Search in sources :

Example 36 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class XmppConnectionService method pushContactToServer.

public void pushContactToServer(final Contact contact) {
    contact.resetOption(Contact.Options.DIRTY_DELETE);
    contact.setOption(Contact.Options.DIRTY_PUSH);
    final Account account = contact.getAccount();
    if (account.getStatus() == Account.State.ONLINE) {
        final boolean ask = contact.getOption(Contact.Options.ASKING);
        final boolean sendUpdates = contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST) && contact.getOption(Contact.Options.PREEMPTIVE_GRANT);
        final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
        iq.query(Namespace.ROSTER).addChild(contact.asElement());
        account.getXmppConnection().sendIqPacket(iq, mDefaultIqHandler);
        if (sendUpdates) {
            sendPresencePacket(account, mPresenceGenerator.sendPresenceUpdatesTo(contact));
        }
        if (ask) {
            sendPresencePacket(account, mPresenceGenerator.requestPresenceUpdatesFrom(contact));
        }
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 37 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class XmppConnectionService method switchToForeground.

private void switchToForeground() {
    final boolean broadcastLastActivity = broadcastLastActivity();
    for (Conversation conversation : getConversations()) {
        if (conversation.getMode() == Conversation.MODE_MULTI) {
            conversation.getMucOptions().resetChatState();
        } else {
            conversation.setIncomingChatState(Config.DEFAULT_CHATSTATE);
        }
    }
    for (Account account : getAccounts()) {
        if (account.getStatus() == Account.State.ONLINE) {
            account.deactivateGracePeriod();
            final XmppConnection connection = account.getXmppConnection();
            if (connection != null) {
                if (connection.getFeatures().csi()) {
                    connection.sendActive();
                }
                if (broadcastLastActivity) {
                    //send new presence but don't include idle because we are not
                    sendPresence(account, false);
                }
            }
        }
    }
    Log.d(Config.LOGTAG, "app switched into foreground");
}
Also used : XmppConnection(eu.siacs.conversations.xmpp.XmppConnection) Account(eu.siacs.conversations.entities.Account) Conversation(eu.siacs.conversations.entities.Conversation)

Example 38 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class XmppConnectionService method publishAvatar.

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

        @Override
        public void onIqPacketReceived(Account account, IqPacket result) {
            if (result.getType() == IqPacket.TYPE.RESULT) {
                final IqPacket packet = XmppConnectionService.this.mIqGenerator.publishAvatarMetadata(avatar);
                sendIqPacket(account, packet, new OnIqPacketReceived() {

                    @Override
                    public void onIqPacketReceived(Account account, IqPacket result) {
                        if (result.getType() == IqPacket.TYPE.RESULT) {
                            if (account.setAvatar(avatar.getFilename())) {
                                getAvatarService().clear(account);
                                databaseBackend.updateAccount(account);
                            }
                            Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": published avatar " + (avatar.size / 1024) + "KiB");
                            if (callback != null) {
                                callback.success(avatar);
                            }
                        } else {
                            if (callback != null) {
                                callback.error(R.string.error_publish_avatar_server_reject, avatar);
                            }
                        }
                    }
                });
            } else {
                Element error = result.findChild("error");
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server rejected avatar " + (avatar.size / 1024) + "KiB " + (error != null ? error.toString() : ""));
                if (callback != null) {
                    callback.error(R.string.error_publish_avatar_server_reject, avatar);
                }
            }
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 39 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

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(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket) Contact(eu.siacs.conversations.entities.Contact)

Example 40 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

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) {
        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());
                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()));
                }
                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.membersOnly() && mucOptions.nonanonymous()) {
                    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);
                } else {
                    join(conversation);
                    fetchConferenceConfiguration(conversation);
                }
            }
        });
        updateConversationUi();
    } else {
        account.pendingConferenceJoins.add(conversation);
        conversation.resetMucOptions();
        conversation.setHasMessagesLeftOnServer(false);
        updateConversationUi();
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) MucOptions(eu.siacs.conversations.entities.MucOptions) Jid(eu.siacs.conversations.xmpp.jid.Jid) Element(eu.siacs.conversations.xml.Element) Conversation(eu.siacs.conversations.entities.Conversation) PresencePacket(eu.siacs.conversations.xmpp.stanzas.PresencePacket)

Aggregations

Account (eu.siacs.conversations.entities.Account)100 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)41 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)33 Jid (eu.siacs.conversations.xmpp.jid.Jid)22 Element (eu.siacs.conversations.xml.Element)21 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)17 Conversation (eu.siacs.conversations.entities.Conversation)16 Contact (eu.siacs.conversations.entities.Contact)9 Message (eu.siacs.conversations.entities.Message)9 ArrayList (java.util.ArrayList)8 PendingIntent (android.app.PendingIntent)7 Intent (android.content.Intent)7 Bookmark (eu.siacs.conversations.entities.Bookmark)7 SuppressLint (android.annotation.SuppressLint)6 AlertDialog (android.app.AlertDialog)6 TextView (android.widget.TextView)6 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)6 FileNotFoundException (java.io.FileNotFoundException)6 DialogInterface (android.content.DialogInterface)5 View (android.view.View)5