Search in sources :

Example 6 with Account

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

the class XmppConnectionService method resetAllAttemptCounts.

private void resetAllAttemptCounts(boolean reallyAll, boolean retryImmediately) {
    Log.d(Config.LOGTAG, "resetting all attempt counts");
    for (Account account : accounts) {
        if (account.hasErrorStatus() || reallyAll) {
            final XmppConnection connection = account.getXmppConnection();
            if (connection != null) {
                connection.resetAttemptCount(retryImmediately);
            }
        }
        if (account.setShowErrorNotification(true)) {
            databaseBackend.updateAccount(account);
        }
    }
    mNotificationService.updateErrorNotification();
}
Also used : XmppConnection(de.pixart.messenger.xmpp.XmppConnection) Account(de.pixart.messenger.entities.Account)

Example 7 with Account

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

the class XmppConnectionService method switchToBackground.

private void switchToBackground() {
    final boolean broadcastLastActivity = broadcastLastActivity();
    for (Account account : getAccounts()) {
        if (account.getStatus() == Account.State.ONLINE) {
            XmppConnection connection = account.getXmppConnection();
            if (connection != null) {
                if (broadcastLastActivity) {
                    sendPresence(account, broadcastLastActivity);
                }
                if (connection.getFeatures().csi()) {
                    connection.sendInactive();
                }
            }
        }
    }
    this.mNotificationService.setIsInForeground(false);
    Log.d(Config.LOGTAG, "app switched into background");
}
Also used : XmppConnection(de.pixart.messenger.xmpp.XmppConnection) Account(de.pixart.messenger.entities.Account)

Example 8 with Account

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

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

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

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