Search in sources :

Example 1 with Element

use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.

the class MessageArchiveService method processFin.

private void processFin(Query query, Element fin) {
    boolean complete = fin.getAttributeAsBoolean("complete");
    Element set = fin.findChild("set", "http://jabber.org/protocol/rsm");
    Element last = set == null ? null : set.findChild("last");
    String count = set == null ? null : set.findChildContent("count");
    Element first = set == null ? null : set.findChild("first");
    Element relevant = query.getPagingOrder() == PagingOrder.NORMAL ? last : first;
    boolean abort = (!query.isCatchup() && query.getTotalCount() >= Config.PAGE_SIZE) || query.getTotalCount() >= Config.MAM_MAX_MESSAGES;
    if (query.getConversation() != null) {
        query.getConversation().setFirstMamReference(first == null ? null : first.getContent());
    }
    if (complete || relevant == null || abort) {
        boolean done;
        if (query.isCatchup()) {
            done = false;
        } else {
            if (count != null) {
                try {
                    done = Integer.parseInt(count) <= query.getTotalCount();
                } catch (NumberFormatException e) {
                    done = false;
                }
            } else {
                done = query.getTotalCount() == 0;
            }
        }
        done = done || (query.getActualMessageCount() == 0 && !query.isCatchup());
        this.finalizeQuery(query, done);
        Log.d(Config.LOGTAG, query.getAccount().getJid().toBareJid() + ": finished mam after " + query.getTotalCount() + "(" + query.getActualMessageCount() + ") messages. messages left=" + Boolean.toString(!done) + " count=" + count);
        if (query.isCatchup() && query.getActualMessageCount() > 0) {
            mXmppConnectionService.getNotificationService().finishBacklog(true, query.getAccount());
        }
        processPostponed(query);
    } else {
        final Query nextQuery;
        if (query.getPagingOrder() == PagingOrder.NORMAL) {
            nextQuery = query.next(last == null ? null : last.getContent());
        } else {
            nextQuery = query.prev(first == null ? null : first.getContent());
        }
        this.execute(nextQuery);
        this.finalizeQuery(query, false);
        synchronized (this.queries) {
            this.queries.add(nextQuery);
        }
    }
}
Also used : Element(de.pixart.messenger.xml.Element)

Example 2 with Element

use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.

the class MessageArchiveService method execute.

private void execute(final Query query) {
    final Account account = query.getAccount();
    if (account.getStatus() == Account.State.ONLINE) {
        Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": running mam query " + query.toString());
        IqPacket packet = this.mXmppConnectionService.getIqGenerator().queryMessageArchiveManagement(query);
        this.mXmppConnectionService.sendIqPacket(account, packet, (a, p) -> {
            Element fin = p.findChild("fin", Namespace.MAM);
            if (p.getType() == IqPacket.TYPE.TIMEOUT) {
                synchronized (MessageArchiveService.this.queries) {
                    MessageArchiveService.this.queries.remove(query);
                    if (query.hasCallback()) {
                        query.callback(false);
                    }
                }
            } else if (p.getType() == IqPacket.TYPE.RESULT && fin != null) {
                processFin(query, fin);
            } else if (p.getType() == IqPacket.TYPE.RESULT && query.isLegacy()) {
            // do nothing
            } else {
                Log.d(Config.LOGTAG, a.getJid().toBareJid().toString() + ": error executing mam: " + p.toString());
                finalizeQuery(query, true);
            }
        });
    } else {
        synchronized (this.pendingQueries) {
            this.pendingQueries.add(query);
        }
    }
}
Also used : Account(de.pixart.messenger.entities.Account) Element(de.pixart.messenger.xml.Element) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 3 with Element

use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method joinMuc.

private void joinMuc(Conversation conversation, final OnConferenceJoined onConferenceJoined, final boolean followedInvite) {
    Account account = conversation.getAccount();
    account.pendingConferenceJoins.remove(conversation);
    account.pendingConferenceLeaves.remove(conversation);
    if (account.getStatus() == Account.State.ONLINE) {
        // disabled for testing strange MUC leaves
        sendPresencePacket(account, mPresenceGenerator.leave(conversation.getMucOptions()));
        conversation.resetMucOptions();
        if (onConferenceJoined != null) {
            conversation.getMucOptions().flagNoAutoPushConfiguration();
        }
        conversation.setHasMessagesLeftOnServer(false);
        fetchConferenceConfiguration(conversation, new OnConferenceConfigurationFetched() {

            private void join(Conversation conversation) {
                Account account = conversation.getAccount();
                final MucOptions mucOptions = conversation.getMucOptions();
                final Jid joinJid = mucOptions.getSelf().getFullJid();
                Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": joining conversation " + joinJid.toString());
                PresencePacket packet = mPresenceGenerator.selfPresence(account, Presence.Status.ONLINE, mucOptions.nonanonymous() || onConferenceJoined != null);
                packet.setTo(joinJid);
                Element x = packet.addChild("x", "http://jabber.org/protocol/muc");
                if (conversation.getMucOptions().getPassword() != null) {
                    x.addChild("password").setContent(mucOptions.getPassword());
                }
                if (mucOptions.mamSupport()) {
                    // Use MAM instead of the limited muc history to get history
                    x.addChild("history").setAttribute("maxchars", "0");
                } else {
                    // Fallback to muc history
                    x.addChild("history").setAttribute("since", PresenceGenerator.getTimestamp(conversation.getLastMessageTransmitted().getTimestamp()));
                }
                sendPresencePacket(account, packet);
                if (onConferenceJoined != null) {
                    onConferenceJoined.onConferenceJoined(conversation);
                }
                if (!joinJid.equals(conversation.getJid())) {
                    conversation.setContactJid(joinJid);
                    databaseBackend.updateConversation(conversation);
                }
                if (mucOptions.mamSupport()) {
                    getMessageArchiveService().catchupMUC(conversation);
                }
                if (mucOptions.isPrivateAndNonAnonymous()) {
                    fetchConferenceMembers(conversation);
                    if (followedInvite && conversation.getBookmark() == null) {
                        saveConversationAsBookmark(conversation, null);
                    }
                }
                sendUnsentMessages(conversation);
            }

            @Override
            public void onConferenceConfigurationFetched(Conversation conversation) {
                join(conversation);
            }

            @Override
            public void onFetchFailed(final Conversation conversation, Element error) {
                if (error != null && "remote-server-not-found".equals(error.getName())) {
                    conversation.getMucOptions().setError(MucOptions.Error.SERVER_NOT_FOUND);
                    updateConversationUi();
                } else {
                    join(conversation);
                    fetchConferenceConfiguration(conversation);
                }
            }
        });
        updateConversationUi();
    } else {
        account.pendingConferenceJoins.add(conversation);
        conversation.resetMucOptions();
        conversation.setHasMessagesLeftOnServer(false);
        updateConversationUi();
    }
}
Also used : Account(de.pixart.messenger.entities.Account) MucOptions(de.pixart.messenger.entities.MucOptions) Jid(de.pixart.messenger.xmpp.jid.Jid) Element(de.pixart.messenger.xml.Element) Conversation(de.pixart.messenger.entities.Conversation) PresencePacket(de.pixart.messenger.xmpp.stanzas.PresencePacket)

Example 4 with Element

use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method deleteContactOnServer.

public void deleteContactOnServer(Contact contact) {
    contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
    contact.resetOption(Contact.Options.DIRTY_PUSH);
    contact.setOption(Contact.Options.DIRTY_DELETE);
    Account account = contact.getAccount();
    if (account.getStatus() == Account.State.ONLINE) {
        IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
        Element item = iq.query(Namespace.ROSTER).addChild("item");
        item.setAttribute("jid", contact.getJid().toString());
        item.setAttribute("subscription", "remove");
        account.getXmppConnection().sendIqPacket(iq, mDefaultIqHandler);
    }
}
Also used : Account(de.pixart.messenger.entities.Account) Element(de.pixart.messenger.xml.Element) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 5 with Element

use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method fetchAvatarPep.

private void fetchAvatarPep(Account account, final Avatar avatar, final UiCallback<Avatar> callback) {
    IqPacket packet = this.mIqGenerator.retrievePepAvatar(avatar);
    sendIqPacket(account, packet, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket result) {
            synchronized (mInProgressAvatarFetches) {
                mInProgressAvatarFetches.remove(generateFetchKey(account, avatar));
            }
            final String ERROR = account.getJid().toBareJid() + ": fetching avatar for " + avatar.owner + " failed ";
            if (result.getType() == IqPacket.TYPE.RESULT) {
                avatar.image = mIqParser.avatarData(result);
                if (avatar.image != null) {
                    if (getFileBackend().save(avatar)) {
                        if (account.getJid().toBareJid().equals(avatar.owner)) {
                            if (account.setAvatar(avatar.getFilename())) {
                                databaseBackend.updateAccount(account);
                            }
                            getAvatarService().clear(account);
                            updateConversationUi();
                            updateAccountUi();
                        } else {
                            Contact contact = account.getRoster().getContact(avatar.owner);
                            contact.setAvatar(avatar);
                            getAvatarService().clear(contact);
                            updateConversationUi();
                            updateRosterUi();
                        }
                        if (callback != null) {
                            callback.success(avatar);
                        }
                        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": successfully fetched pep avatar for " + avatar.owner);
                        return;
                    }
                } else {
                    Log.d(Config.LOGTAG, ERROR + "(parsing error)");
                }
            } else {
                Element error = result.findChild("error");
                if (error == null) {
                    Log.d(Config.LOGTAG, ERROR + "(server error)");
                } else {
                    Log.d(Config.LOGTAG, ERROR + error.toString());
                }
            }
            if (callback != null) {
                callback.error(0, null);
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Element(de.pixart.messenger.xml.Element) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket) Contact(de.pixart.messenger.entities.Contact)

Aggregations

Element (de.pixart.messenger.xml.Element)100 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)48 Account (de.pixart.messenger.entities.Account)23 Jid (de.pixart.messenger.xmpp.jid.Jid)19 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)17 Contact (de.pixart.messenger.entities.Contact)9 MessagePacket (de.pixart.messenger.xmpp.stanzas.MessagePacket)8 ArrayList (java.util.ArrayList)7 Conversation (de.pixart.messenger.entities.Conversation)6 IOException (java.io.IOException)6 Data (de.pixart.messenger.xmpp.forms.Data)5 Avatar (de.pixart.messenger.xmpp.pep.Avatar)5 HashSet (java.util.HashSet)5 AxolotlService (de.pixart.messenger.crypto.axolotl.AxolotlService)4 MucOptions (de.pixart.messenger.entities.MucOptions)4 ECPublicKey (org.whispersystems.libsignal.ecc.ECPublicKey)4 PreKeyBundle (org.whispersystems.libsignal.state.PreKeyBundle)4 Pair (android.util.Pair)3 Bookmark (de.pixart.messenger.entities.Bookmark)3 Message (de.pixart.messenger.entities.Message)3