Search in sources :

Example 1 with Bookmark

use of de.pixart.messenger.entities.Bookmark 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 2 with Bookmark

use of de.pixart.messenger.entities.Bookmark in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method getKnownConferenceHosts.

public List<String> getKnownConferenceHosts() {
    final ArrayList<String> mucServers = new ArrayList<>();
    for (final Account account : accounts) {
        if (account.getXmppConnection() != null) {
            final String server = account.getXmppConnection().getMucServer();
            if (server != null && !mucServers.contains(server)) {
                mucServers.add(server);
            }
            for (Bookmark bookmark : account.getBookmarks()) {
                final Jid jid = bookmark.getJid();
                final String s = jid == null ? null : jid.getDomainpart();
                if (s != null && !mucServers.contains(s)) {
                    mucServers.add(s);
                }
            }
        }
    }
    return mucServers;
}
Also used : Account(de.pixart.messenger.entities.Account) Bookmark(de.pixart.messenger.entities.Bookmark) Jid(de.pixart.messenger.xmpp.jid.Jid) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList)

Example 3 with Bookmark

use of de.pixart.messenger.entities.Bookmark in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method saveConversationAsBookmark.

public void saveConversationAsBookmark(Conversation conversation, String name) {
    Account account = conversation.getAccount();
    Bookmark bookmark = new Bookmark(account, conversation.getJid().toBareJid());
    if (!conversation.getJid().isBareJid()) {
        bookmark.setNick(conversation.getJid().getResourcepart());
    }
    if (name != null && !name.trim().isEmpty()) {
        bookmark.setBookmarkName(name.trim());
    }
    bookmark.setAutojoin(getPreferences().getBoolean("autojoin", getResources().getBoolean(R.bool.autojoin)));
    account.getBookmarks().add(bookmark);
    pushBookmarks(account);
    bookmark.setConversation(conversation);
}
Also used : Account(de.pixart.messenger.entities.Account) Bookmark(de.pixart.messenger.entities.Bookmark)

Example 4 with Bookmark

use of de.pixart.messenger.entities.Bookmark in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method pushBookmarks.

public void pushBookmarks(Account account) {
    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": pushing bookmarks");
    IqPacket iqPacket = new IqPacket(IqPacket.TYPE.SET);
    Element query = iqPacket.query("jabber:iq:private");
    Element storage = query.addChild("storage", "storage:bookmarks");
    for (Bookmark bookmark : account.getBookmarks()) {
        storage.addChild(bookmark);
    }
    sendIqPacket(account, iqPacket, mDefaultIqHandler);
}
Also used : Bookmark(de.pixart.messenger.entities.Bookmark) Element(de.pixart.messenger.xml.Element) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 5 with Bookmark

use of de.pixart.messenger.entities.Bookmark in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method leaveMuc.

private void leaveMuc(Conversation conversation, boolean now) {
    Account account = conversation.getAccount();
    account.pendingConferenceJoins.remove(conversation);
    account.pendingConferenceLeaves.remove(conversation);
    if (account.getStatus() == Account.State.ONLINE || now) {
        sendPresencePacket(conversation.getAccount(), mPresenceGenerator.leave(conversation.getMucOptions()));
        conversation.getMucOptions().setOffline();
        Bookmark bookmark = conversation.getBookmark();
        if (bookmark != null) {
            bookmark.setConversation(null);
        }
        Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": leaving muc " + conversation.getJid());
    } else {
        account.pendingConferenceLeaves.add(conversation);
    }
}
Also used : Account(de.pixart.messenger.entities.Account) Bookmark(de.pixart.messenger.entities.Bookmark)

Aggregations

Bookmark (de.pixart.messenger.entities.Bookmark)15 Account (de.pixart.messenger.entities.Account)9 Jid (de.pixart.messenger.xmpp.jid.Jid)6 Conversation (de.pixart.messenger.entities.Conversation)4 Element (de.pixart.messenger.xml.Element)3 SuppressLint (android.annotation.SuppressLint)2 AlertDialog (android.support.v7.app.AlertDialog)2 MucOptions (de.pixart.messenger.entities.MucOptions)2 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)2 PendingIntent (android.app.PendingIntent)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 DialogInterface (android.content.DialogInterface)1 OnClickListener (android.content.DialogInterface.OnClickListener)1 Intent (android.content.Intent)1 SpannableString (android.text.SpannableString)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 CheckBox (android.widget.CheckBox)1 Checkable (android.widget.Checkable)1