Search in sources :

Example 1 with Jid

use of de.pixart.messenger.xmpp.jid.Jid 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 2 with Jid

use of de.pixart.messenger.xmpp.jid.Jid in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method sendUnblockRequest.

public void sendUnblockRequest(final Blockable blockable) {
    if (blockable != null && blockable.getJid() != null) {
        final Jid jid = blockable.getBlockedJid();
        this.sendIqPacket(blockable.getAccount(), getIqGenerator().generateSetUnblockRequest(jid), new OnIqPacketReceived() {

            @Override
            public void onIqPacketReceived(final Account account, final IqPacket packet) {
                if (packet.getType() == IqPacket.TYPE.RESULT) {
                    account.getBlocklist().remove(jid);
                    updateBlocklistUi(OnUpdateBlocklist.Status.UNBLOCKED);
                }
            }
        });
    }
}
Also used : Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 3 with Jid

use of de.pixart.messenger.xmpp.jid.Jid in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method loadPhoneContacts.

public void loadPhoneContacts() {
    mContactMergerExecutor.execute(new Runnable() {

        @Override
        public void run() {
            PhoneHelper.loadPhoneContacts(XmppConnectionService.this, new OnPhoneContactsLoadedListener() {

                @Override
                public void onPhoneContactsLoaded(List<Bundle> phoneContacts) {
                    Log.d(Config.LOGTAG, "start merging phone contacts with roster");
                    for (Account account : accounts) {
                        List<Contact> withSystemAccounts = account.getRoster().getWithSystemAccounts();
                        for (Bundle phoneContact : phoneContacts) {
                            Jid jid;
                            try {
                                jid = Jid.fromString(phoneContact.getString("jid"));
                            } catch (final InvalidJidException e) {
                                continue;
                            }
                            final Contact contact = account.getRoster().getContact(jid);
                            String systemAccount = phoneContact.getInt("phoneid") + "#" + phoneContact.getString("lookup");
                            contact.setSystemAccount(systemAccount);
                            boolean needsCacheClean = contact.setPhotoUri(phoneContact.getString("photouri"));
                            needsCacheClean |= contact.setSystemName(phoneContact.getString("displayname"));
                            if (needsCacheClean) {
                                getAvatarService().clear(contact);
                            }
                            withSystemAccounts.remove(contact);
                        }
                        for (Contact contact : withSystemAccounts) {
                            contact.setSystemAccount(null);
                            boolean needsCacheClean = contact.setPhotoUri(null);
                            needsCacheClean |= contact.setSystemName(null);
                            if (needsCacheClean) {
                                getAvatarService().clear(contact);
                            }
                        }
                    }
                    Log.d(Config.LOGTAG, "finished merging phone contacts");
                    mShortcutService.refresh(mInitialAddressbookSyncCompleted.compareAndSet(false, true));
                    updateAccountUi();
                }
            });
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) Bundle(android.os.Bundle) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) List(java.util.List) OnPhoneContactsLoadedListener(de.pixart.messenger.utils.OnPhoneContactsLoadedListener) Contact(de.pixart.messenger.entities.Contact)

Example 4 with Jid

use of de.pixart.messenger.xmpp.jid.Jid in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method changeAffiliationInConference.

public void changeAffiliationInConference(final Conversation conference, Jid user, final MucOptions.Affiliation affiliation, final OnAffiliationChanged callback) {
    final Jid jid = user.toBareJid();
    IqPacket request = this.mIqGenerator.changeAffiliation(conference, jid, affiliation.toString());
    sendIqPacket(conference.getAccount(), request, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                conference.getMucOptions().changeAffiliation(jid, affiliation);
                getAvatarService().clear(conference);
                callback.onAffiliationChangedSuccessful(jid);
            } else {
                callback.onAffiliationChangeFailed(jid, R.string.could_not_change_affiliation);
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 5 with Jid

use of de.pixart.messenger.xmpp.jid.Jid 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)

Aggregations

Jid (de.pixart.messenger.xmpp.jid.Jid)75 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)26 Account (de.pixart.messenger.entities.Account)24 Element (de.pixart.messenger.xml.Element)19 Conversation (de.pixart.messenger.entities.Conversation)18 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)15 Contact (de.pixart.messenger.entities.Contact)14 MucOptions (de.pixart.messenger.entities.MucOptions)11 ArrayList (java.util.ArrayList)11 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)8 Message (de.pixart.messenger.entities.Message)7 Intent (android.content.Intent)6 AxolotlService (de.pixart.messenger.crypto.axolotl.AxolotlService)6 Bookmark (de.pixart.messenger.entities.Bookmark)6 MessagePacket (de.pixart.messenger.xmpp.stanzas.MessagePacket)4 Map (java.util.Map)4 SuppressLint (android.annotation.SuppressLint)3 AlertDialog (android.support.v7.app.AlertDialog)3 XmppAxolotlMessage (de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage)3 HashMap (java.util.HashMap)3