Search in sources :

Example 96 with Conversation

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

the class XmppConnectionService method disconnect.

private void disconnect(Account account, boolean force) {
    if ((account.getStatus() == Account.State.ONLINE) || (account.getStatus() == Account.State.DISABLED)) {
        final XmppConnection connection = account.getXmppConnection();
        if (!force) {
            List<Conversation> conversations = getConversations();
            for (Conversation conversation : conversations) {
                if (conversation.getAccount() == account) {
                    if (conversation.getMode() == Conversation.MODE_MULTI) {
                        leaveMuc(conversation, true);
                    }
                }
            }
            sendOfflinePresence(account);
        }
        connection.disconnect(force);
    }
}
Also used : XmppConnection(eu.siacs.conversations.xmpp.XmppConnection) Conversation(eu.siacs.conversations.entities.Conversation)

Example 97 with Conversation

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

the class UIHelper method getMessageDisplayName.

public static String getMessageDisplayName(final Message message) {
    final Conversational conversation = message.getConversation();
    if (message.getStatus() == Message.STATUS_RECEIVED) {
        final Contact contact = message.getContact();
        if (conversation.getMode() == Conversation.MODE_MULTI) {
            if (contact != null) {
                return contact.getDisplayName();
            } else {
                return getDisplayedMucCounterpart(message.getCounterpart());
            }
        } else {
            return contact != null ? contact.getDisplayName() : "";
        }
    } else {
        if (conversation instanceof Conversation && conversation.getMode() == Conversation.MODE_MULTI) {
            return ((Conversation) conversation).getMucOptions().getSelf().getName();
        } else {
            final Account account = conversation.getAccount();
            final Jid jid = account.getJid();
            final String displayName = account.getDisplayName();
            if (Strings.isNullOrEmpty(displayName)) {
                return jid.getLocal() != null ? jid.getLocal() : jid.getDomain().toString();
            } else {
                return displayName;
            }
        }
    }
}
Also used : Conversational(eu.siacs.conversations.entities.Conversational) Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.Jid) Conversation(eu.siacs.conversations.entities.Conversation) Contact(eu.siacs.conversations.entities.Contact)

Example 98 with Conversation

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

the class XmppConnectionService method createAdhocConference.

public boolean createAdhocConference(final Account account, final String name, final Iterable<Jid> jids, final UiCallback<Conversation> callback) {
    Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": creating adhoc conference with " + jids.toString());
    if (account.getStatus() == Account.State.ONLINE) {
        try {
            String server = findConferenceServer(account);
            if (server == null) {
                if (callback != null) {
                    callback.error(R.string.no_conference_server_found, null);
                }
                return false;
            }
            final Jid jid = Jid.of(CryptoHelper.pronounceable(getRNG()), server, null);
            final Conversation conversation = findOrCreateConversation(account, jid, true, false, true);
            joinMuc(conversation, new OnConferenceJoined() {

                @Override
                public void onConferenceJoined(final Conversation conversation) {
                    final Bundle configuration = IqGenerator.defaultGroupChatConfiguration();
                    if (!TextUtils.isEmpty(name)) {
                        configuration.putString("muc#roomconfig_roomname", name);
                    }
                    pushConferenceConfiguration(conversation, configuration, new OnConfigurationPushed() {

                        @Override
                        public void onPushSucceeded() {
                            for (Jid invite : jids) {
                                invite(conversation, invite);
                            }
                            for (String resource : account.getSelfContact().getPresences().toResourceArray()) {
                                Jid other = account.getJid().withResource(resource);
                                Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": sending direct invite to " + other);
                                directInvite(conversation, other);
                            }
                            saveConversationAsBookmark(conversation, name);
                            if (callback != null) {
                                callback.success(conversation);
                            }
                        }

                        @Override
                        public void onPushFailed() {
                            archiveConversation(conversation);
                            if (callback != null) {
                                callback.error(R.string.conference_creation_failed, conversation);
                            }
                        }
                    });
                }
            });
            return true;
        } catch (IllegalArgumentException e) {
            if (callback != null) {
                callback.error(R.string.conference_creation_failed, null);
            }
            return false;
        }
    } else {
        if (callback != null) {
            callback.error(R.string.not_connected_try_again, null);
        }
        return false;
    }
}
Also used : Jid(eu.siacs.conversations.xmpp.Jid) Bundle(android.os.Bundle) Conversation(eu.siacs.conversations.entities.Conversation)

Example 99 with Conversation

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

the class XmppConnectionService method resendFailedMessages.

public void resendFailedMessages(final Message message) {
    final Collection<Message> messages = new ArrayList<>();
    Message current = message;
    while (current.getStatus() == Message.STATUS_SEND_FAILED) {
        messages.add(current);
        if (current.mergeable(current.next())) {
            current = current.next();
        } else {
            break;
        }
    }
    for (final Message msg : messages) {
        msg.setTime(System.currentTimeMillis());
        markMessage(msg, Message.STATUS_WAITING);
        this.resendMessage(msg, false);
    }
    if (message.getConversation() instanceof Conversation) {
        ((Conversation) message.getConversation()).sort();
    }
    updateConversationUi();
}
Also used : XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) Message(eu.siacs.conversations.entities.Message) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Conversation(eu.siacs.conversations.entities.Conversation)

Example 100 with Conversation

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

the class XmppConnectionService method directReply.

private void directReply(final Conversation conversation, final String body, final String lastMessageUuid, final boolean dismissAfterReply) {
    final Message inReplyTo = lastMessageUuid == null ? null : conversation.findMessageWithUuid(lastMessageUuid);
    final Message message = new Message(conversation, body, conversation.getNextEncryption());
    if (inReplyTo != null && inReplyTo.isPrivateMessage()) {
        Message.configurePrivateMessage(message, inReplyTo.getCounterpart());
    }
    message.markUnread();
    if (message.getEncryption() == Message.ENCRYPTION_PGP) {
        getPgpEngine().encrypt(message, new UiCallback<Message>() {

            @Override
            public void success(Message message) {
                if (dismissAfterReply) {
                    markRead((Conversation) message.getConversation(), true);
                } else {
                    mNotificationService.pushFromDirectReply(message);
                }
            }

            @Override
            public void error(int errorCode, Message object) {
            }

            @Override
            public void userInputRequired(PendingIntent pi, Message object) {
            }
        });
    } else {
        sendMessage(message);
        if (dismissAfterReply) {
            markRead(conversation, true);
        } else {
            mNotificationService.pushFromDirectReply(message);
        }
    }
}
Also used : XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) Message(eu.siacs.conversations.entities.Message) Conversation(eu.siacs.conversations.entities.Conversation) PendingIntent(android.app.PendingIntent) SuppressLint(android.annotation.SuppressLint)

Aggregations

Conversation (eu.siacs.conversations.entities.Conversation)110 Account (eu.siacs.conversations.entities.Account)27 Message (eu.siacs.conversations.entities.Message)24 Jid (eu.siacs.conversations.xmpp.Jid)22 Contact (eu.siacs.conversations.entities.Contact)17 MucOptions (eu.siacs.conversations.entities.MucOptions)10 Intent (android.content.Intent)9 Element (eu.siacs.conversations.xml.Element)9 PendingIntent (android.app.PendingIntent)8 XmppAxolotlMessage (eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)8 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)8 Uri (android.net.Uri)7 Conversational (eu.siacs.conversations.entities.Conversational)7 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)7 SuppressLint (android.annotation.SuppressLint)6 SpannableString (android.text.SpannableString)6 XmppConnection (eu.siacs.conversations.xmpp.XmppConnection)6 Jid (eu.siacs.conversations.xmpp.jid.Jid)6 ArrayList (java.util.ArrayList)6 Fragment (android.app.Fragment)4