Search in sources :

Example 11 with Conversation

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));
}
Also used : SendButtonAction(de.pixart.messenger.ui.util.SendButtonAction) Presence(de.pixart.messenger.entities.Presence) Conversation(de.pixart.messenger.entities.Conversation)

Example 12 with Conversation

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;
}
Also used : Conversation(de.pixart.messenger.entities.Conversation)

Example 13 with Conversation

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);
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Jid(de.pixart.messenger.xmpp.jid.Jid) Bookmark(de.pixart.messenger.entities.Bookmark) HashMap(java.util.HashMap) Element(de.pixart.messenger.xml.Element) Conversation(de.pixart.messenger.entities.Conversation) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 14 with Conversation

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;
    }
}
Also used : Conversation(de.pixart.messenger.entities.Conversation) Contact(de.pixart.messenger.entities.Contact)

Example 15 with 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();
        }
    });
}
Also used : MessagePacket(de.pixart.messenger.xmpp.stanzas.MessagePacket) Account(de.pixart.messenger.entities.Account) XmppAxolotlMessage(de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage) Message(de.pixart.messenger.entities.Message) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Conversation(de.pixart.messenger.entities.Conversation) SessionID(net.java.otr4j.session.SessionID) Session(net.java.otr4j.session.Session)

Aggregations

Conversation (de.pixart.messenger.entities.Conversation)69 Jid (de.pixart.messenger.xmpp.jid.Jid)20 Account (de.pixart.messenger.entities.Account)18 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)16 Message (de.pixart.messenger.entities.Message)15 Contact (de.pixart.messenger.entities.Contact)11 MucOptions (de.pixart.messenger.entities.MucOptions)9 Intent (android.content.Intent)7 SuppressLint (android.annotation.SuppressLint)6 Uri (android.net.Uri)6 SpannableString (android.text.SpannableString)6 View (android.view.View)6 XmppAxolotlMessage (de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage)6 DownloadableFile (de.pixart.messenger.entities.DownloadableFile)6 Element (de.pixart.messenger.xml.Element)6 MessagePacket (de.pixart.messenger.xmpp.stanzas.MessagePacket)6 IOException (java.io.IOException)6 Fragment (android.app.Fragment)5 SharedPreferences (android.content.SharedPreferences)5 Bitmap (android.graphics.Bitmap)5