Search in sources :

Example 26 with Account

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

use of de.pixart.messenger.entities.Account 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)

Example 28 with Account

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

the class XmppConnectionService method checkForAvatar.

public void checkForAvatar(Account account, final UiCallback<Avatar> callback) {
    IqPacket packet = this.mIqGenerator.retrieveAvatarMetaData(null);
    this.sendIqPacket(account, packet, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                Element pubsub = packet.findChild("pubsub", "http://jabber.org/protocol/pubsub");
                if (pubsub != null) {
                    Element items = pubsub.findChild("items");
                    if (items != null) {
                        Avatar avatar = Avatar.parseMetadata(items);
                        if (avatar != null) {
                            avatar.owner = account.getJid().toBareJid();
                            if (fileBackend.isAvatarCached(avatar)) {
                                if (account.setAvatar(avatar.getFilename())) {
                                    databaseBackend.updateAccount(account);
                                }
                                getAvatarService().clear(account);
                                callback.success(avatar);
                            } else {
                                fetchAvatarPep(account, avatar, callback);
                            }
                            return;
                        }
                    }
                }
            }
            callback.error(0, null);
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Element(de.pixart.messenger.xml.Element) Avatar(de.pixart.messenger.xmpp.pep.Avatar) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 29 with Account

use of de.pixart.messenger.entities.Account 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)

Example 30 with Account

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

the class XmppConnectionService method restoreFromDatabase.

private void restoreFromDatabase() {
    synchronized (this.conversations) {
        final Map<String, Account> accountLookupTable = new Hashtable<>();
        for (Account account : this.accounts) {
            accountLookupTable.put(account.getUuid(), account);
        }
        Log.d(Config.LOGTAG, "restoring conversations...");
        final long startTimeConversationsRestore = SystemClock.elapsedRealtime();
        this.conversations.addAll(databaseBackend.getConversations(Conversation.STATUS_AVAILABLE));
        for (Iterator<Conversation> iterator = conversations.listIterator(); iterator.hasNext(); ) {
            Conversation conversation = iterator.next();
            Account account = accountLookupTable.get(conversation.getAccountUuid());
            if (account != null) {
                conversation.setAccount(account);
            } else {
                Log.e(Config.LOGTAG, "unable to restore Conversations with " + conversation.getJid());
                iterator.remove();
            }
        }
        long diffConversationsRestore = SystemClock.elapsedRealtime() - startTimeConversationsRestore;
        Log.d(Config.LOGTAG, "finished restoring conversations in " + diffConversationsRestore + "ms");
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                long deletionDate = getAutomaticMessageDeletionDate();
                mLastExpiryRun.set(SystemClock.elapsedRealtime());
                if (deletionDate > 0) {
                    Log.d(Config.LOGTAG, "deleting messages that are older than " + AbstractGenerator.getTimestamp(deletionDate));
                    databaseBackend.expireOldMessages(deletionDate);
                }
                Log.d(Config.LOGTAG, "restoring roster...");
                for (Account account : accounts) {
                    databaseBackend.readRoster(account.getRoster());
                    // roster needs to be loaded at this stage
                    account.initAccountServices(XmppConnectionService.this);
                }
                getBitmapCache().evictAll();
                loadPhoneContacts();
                Log.d(Config.LOGTAG, "restoring messages...");
                final long startMessageRestore = SystemClock.elapsedRealtime();
                for (Conversation conversation : conversations) {
                    conversation.addAll(0, databaseBackend.getMessages(conversation, Config.PAGE_SIZE));
                    checkDeletedFiles(conversation);
                    conversation.findUnsentTextMessages(new Conversation.OnMessageFound() {

                        @Override
                        public void onMessageFound(Message message) {
                            markMessage(message, Message.STATUS_WAITING);
                        }
                    });
                    conversation.findUnreadMessages(new Conversation.OnMessageFound() {

                        @Override
                        public void onMessageFound(Message message) {
                            mNotificationService.pushFromBacklog(message);
                        }
                    });
                }
                mNotificationService.finishBacklog(false);
                restoredFromDatabaseLatch.countDown();
                final long diffMessageRestore = SystemClock.elapsedRealtime() - startMessageRestore;
                Log.d(Config.LOGTAG, "finished restoring messages in " + diffMessageRestore + "ms");
                updateConversationUi();
            }
        };
        // will contain one write command (expiry) but that's fine
        mDatabaseReaderExecutor.execute(runnable);
    }
}
Also used : Account(de.pixart.messenger.entities.Account) XmppAxolotlMessage(de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage) Message(de.pixart.messenger.entities.Message) Hashtable(java.util.Hashtable) Conversation(de.pixart.messenger.entities.Conversation)

Aggregations

Account (de.pixart.messenger.entities.Account)104 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)39 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)31 Jid (de.pixart.messenger.xmpp.jid.Jid)26 Element (de.pixart.messenger.xml.Element)23 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)19 Conversation (de.pixart.messenger.entities.Conversation)18 ArrayList (java.util.ArrayList)14 Intent (android.content.Intent)12 Contact (de.pixart.messenger.entities.Contact)12 Bookmark (de.pixart.messenger.entities.Bookmark)10 PendingIntent (android.app.PendingIntent)9 Message (de.pixart.messenger.entities.Message)8 Bundle (android.os.Bundle)7 AlertDialog (android.support.v7.app.AlertDialog)7 MucOptions (de.pixart.messenger.entities.MucOptions)7 List (java.util.List)7 SuppressLint (android.annotation.SuppressLint)6 Bitmap (android.graphics.Bitmap)6 View (android.view.View)6