use of de.pixart.messenger.entities.Conversation in project Pix-Art-Messenger by kriztan.
the class ConversationFragment method updateSendButton.
public void updateSendButton() {
boolean useSendButtonToIndicateStatus = PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean("send_button_status", getResources().getBoolean(R.bool.send_button_status));
final Conversation c = this.conversation;
final Presence.Status status;
final String text = this.binding.textinput == null ? "" : this.binding.textinput.getText().toString();
final SendButtonAction action = SendButtonTool.getAction(getActivity(), c, text);
if (useSendButtonToIndicateStatus && c.getAccount().getStatus() == Account.State.ONLINE) {
if (activity.xmppConnectionService != null && activity.xmppConnectionService.getMessageArchiveService().isCatchingUp(c)) {
status = Presence.Status.OFFLINE;
} else if (c.getMode() == Conversation.MODE_SINGLE) {
status = c.getContact().getShownStatus();
} else {
status = c.getMucOptions().online() ? Presence.Status.ONLINE : Presence.Status.OFFLINE;
}
} else {
status = Presence.Status.OFFLINE;
}
this.binding.textSendButton.setTag(action);
this.binding.textSendButton.setImageResource(SendButtonTool.getSendButtonImageResource(getActivity(), action, status));
}
use of de.pixart.messenger.entities.Conversation in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method removeBlockedConversations.
public boolean removeBlockedConversations(final Account account, final Jid blockedJid) {
boolean removed = false;
synchronized (this.conversations) {
boolean domainJid = blockedJid.isDomainJid();
for (Conversation conversation : this.conversations) {
boolean jidMatches = (domainJid && blockedJid.getDomainpart().equals(conversation.getJid().getDomainpart())) || blockedJid.equals(conversation.getJid().toBareJid());
if (conversation.getAccount() == account && conversation.getMode() == Conversation.MODE_SINGLE && jidMatches) {
this.conversations.remove(conversation);
markRead(conversation);
conversation.setStatus(Conversation.STATUS_ARCHIVED);
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": archiving conversation " + conversation.getJid().toBareJid() + " because jid was blocked");
updateConversation(conversation);
removed = true;
}
}
}
return removed;
}
use of de.pixart.messenger.entities.Conversation in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method fetchBookmarks.
public void fetchBookmarks(final Account account) {
final IqPacket iqPacket = new IqPacket(IqPacket.TYPE.GET);
final Element query = iqPacket.query("jabber:iq:private");
query.addChild("storage", "storage:bookmarks");
final OnIqPacketReceived callback = new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(final Account account, final IqPacket packet) {
if (packet.getType() == IqPacket.TYPE.RESULT) {
final Element query = packet.query();
final HashMap<Jid, Bookmark> bookmarks = new HashMap<>();
final Element storage = query.findChild("storage", "storage:bookmarks");
final boolean autojoin = respectAutojoin();
if (storage != null) {
for (final Element item : storage.getChildren()) {
if (item.getName().equals("conference")) {
final Bookmark bookmark = Bookmark.parse(item, account);
Bookmark old = bookmarks.put(bookmark.getJid(), bookmark);
if (old != null && old.getBookmarkName() != null && bookmark.getBookmarkName() == null) {
bookmark.setBookmarkName(old.getBookmarkName());
}
Conversation conversation = find(bookmark);
if (conversation != null) {
bookmark.setConversation(conversation);
} else if (bookmark.autojoin() && bookmark.getJid() != null && autojoin) {
conversation = findOrCreateConversation(account, bookmark.getJid(), true, true, false);
bookmark.setConversation(conversation);
}
}
}
}
account.setBookmarks(new CopyOnWriteArrayList<>(bookmarks.values()));
} else {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not fetch bookmarks");
}
}
};
sendIqPacket(account, iqPacket, callback);
}
use of de.pixart.messenger.entities.Conversation in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method findOrCreateConversation.
public Conversation findOrCreateConversation(final Account account, final Jid jid, final boolean muc, final boolean joinAfterCreate, final MessageArchiveService.Query query, final boolean async) {
synchronized (this.conversations) {
Conversation conversation = find(account, jid);
if (conversation != null) {
return conversation;
}
conversation = databaseBackend.findConversation(account, jid);
final boolean loadMessagesFromDb;
if (conversation != null) {
conversation.setStatus(Conversation.STATUS_AVAILABLE);
conversation.setAccount(account);
if (muc) {
conversation.setMode(Conversation.MODE_MULTI);
conversation.setContactJid(jid);
} else {
conversation.setMode(Conversation.MODE_SINGLE);
conversation.setContactJid(jid.toBareJid());
}
databaseBackend.updateConversation(conversation);
loadMessagesFromDb = conversation.messagesLoaded.compareAndSet(true, false);
} else {
String conversationName;
Contact contact = account.getRoster().getContact(jid);
if (contact != null) {
conversationName = contact.getDisplayName();
} else {
conversationName = jid.getLocalpart();
}
if (muc) {
conversation = new Conversation(conversationName, account, jid, Conversation.MODE_MULTI);
} else {
conversation = new Conversation(conversationName, account, jid.toBareJid(), Conversation.MODE_SINGLE);
}
this.databaseBackend.createConversation(conversation);
loadMessagesFromDb = false;
}
final Conversation c = conversation;
final Runnable runnable = () -> {
if (loadMessagesFromDb) {
c.addAll(0, databaseBackend.getMessages(c, Config.PAGE_SIZE));
updateConversationUi();
c.messagesLoaded.set(true);
}
if (account.getXmppConnection() != null && !c.getContact().isBlocked() && account.getXmppConnection().getFeatures().mam() && !muc) {
if (query == null) {
mMessageArchiveService.query(c);
} else {
if (query.getConversation() == null) {
mMessageArchiveService.query(c, query.getStart(), query.isCatchup());
}
}
}
checkDeletedFiles(c);
if (joinAfterCreate) {
joinMuc(c);
}
};
if (async) {
mDatabaseReaderExecutor.execute(runnable);
} else {
runnable.run();
}
this.conversations.add(conversation);
updateConversationUi();
return conversation;
}
}
use of de.pixart.messenger.entities.Conversation in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method onOtrSessionEstablished.
public void onOtrSessionEstablished(Conversation conversation) {
final Account account = conversation.getAccount();
final Session otrSession = conversation.getOtrSession();
Log.d(Config.LOGTAG, account.getJid().toBareJid() + " otr session established with " + conversation.getJid() + "/" + otrSession.getSessionID().getUserID());
conversation.findUnsentMessagesWithEncryption(Message.ENCRYPTION_OTR, new Conversation.OnMessageFound() {
@Override
public void onMessageFound(Message message) {
SessionID id = otrSession.getSessionID();
try {
message.setCounterpart(Jid.fromString(id.getAccountID() + "/" + id.getUserID()));
} catch (InvalidJidException e) {
return;
}
if (message.needsUploading()) {
mJingleConnectionManager.createNewConnection(message);
} else {
MessagePacket outPacket = mMessageGenerator.generateOtrChat(message);
if (outPacket != null) {
mMessageGenerator.addDelay(outPacket, message.getTimeSent());
message.setStatus(Message.STATUS_SEND);
databaseBackend.updateMessage(message);
sendMessagePacket(account, outPacket);
}
}
updateConversationUi();
}
});
}
Aggregations