Search in sources :

Example 11 with Conversation

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

the class ShareViaAccountActivity method onBackendConnected.

@Override
void onBackendConnected() {
    final int numAccounts = xmppConnectionService.getAccounts().size();
    if (numAccounts == 1) {
        final String body = getIntent().getStringExtra(EXTRA_BODY);
        final Account account = xmppConnectionService.getAccounts().get(0);
        try {
            final Jid contact = Jid.of(getIntent().getStringExtra(EXTRA_CONTACT));
            final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, contact, false, false);
            switchToConversation(conversation, body);
        } catch (IllegalArgumentException e) {
        // ignore error
        }
        finish();
    } else {
        refreshUiReal();
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.Jid) Conversation(eu.siacs.conversations.entities.Conversation)

Example 12 with Conversation

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

the class XmppConnectionService method removeBlockedConversations.

public boolean removeBlockedConversations(final Account account, final Jid blockedJid) {
    boolean removed = false;
    synchronized (this.conversations) {
        boolean domainJid = blockedJid.getLocal() == null;
        for (Conversation conversation : this.conversations) {
            boolean jidMatches = (domainJid && blockedJid.getDomain().equals(conversation.getJid().getDomain())) || blockedJid.equals(conversation.getJid().asBareJid());
            if (conversation.getAccount() == account && conversation.getMode() == Conversation.MODE_SINGLE && jidMatches) {
                this.conversations.remove(conversation);
                markRead(conversation);
                conversation.setStatus(Conversation.STATUS_ARCHIVED);
                Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": archiving conversation " + conversation.getJid().asBareJid() + " because jid was blocked");
                updateConversation(conversation);
                removed = true;
            }
        }
    }
    return removed;
}
Also used : Conversation(eu.siacs.conversations.entities.Conversation)

Example 13 with Conversation

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

the class MessageSearchTask method findOrGenerateStub.

private Conversational findOrGenerateStub(String conversationUuid, String accountUuid, String contactJid, int mode) throws Exception {
    Conversation conversation = xmppConnectionService.findConversationByUuid(conversationUuid);
    if (conversation != null) {
        return conversation;
    }
    Account account = xmppConnectionService.findAccountByUuid(accountUuid);
    Jid jid = Jid.of(contactJid);
    if (account != null && jid != null) {
        return new StubConversation(account, conversationUuid, jid.asBareJid(), mode);
    }
    throw new Exception("Unable to generate stub for " + contactJid);
}
Also used : Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.Jid) StubConversation(eu.siacs.conversations.entities.StubConversation) StubConversation(eu.siacs.conversations.entities.StubConversation) Conversation(eu.siacs.conversations.entities.Conversation)

Example 14 with Conversation

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

the class NotificationService method buildMultipleConversation.

private Builder buildMultipleConversation(final boolean notify, final boolean quietHours) {
    final Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService, quietHours ? "quiet_hours" : (notify ? "messages" : "silent_messages"));
    final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
    style.setBigContentTitle(mXmppConnectionService.getResources().getQuantityString(R.plurals.x_unread_conversations, notifications.size(), notifications.size()));
    final StringBuilder names = new StringBuilder();
    Conversation conversation = null;
    for (final ArrayList<Message> messages : notifications.values()) {
        if (messages.size() > 0) {
            conversation = (Conversation) messages.get(0).getConversation();
            final String name = conversation.getName().toString();
            SpannableString styledString;
            if (Config.HIDE_MESSAGE_TEXT_IN_NOTIFICATION) {
                int count = messages.size();
                styledString = new SpannableString(name + ": " + mXmppConnectionService.getResources().getQuantityString(R.plurals.x_messages, count, count));
                styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0);
                style.addLine(styledString);
            } else {
                styledString = new SpannableString(name + ": " + UIHelper.getMessagePreview(mXmppConnectionService, messages.get(0)).first);
                styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0);
                style.addLine(styledString);
            }
            names.append(name);
            names.append(", ");
        }
    }
    if (names.length() >= 2) {
        names.delete(names.length() - 2, names.length());
    }
    final String contentTitle = mXmppConnectionService.getResources().getQuantityString(R.plurals.x_unread_conversations, notifications.size(), notifications.size());
    mBuilder.setContentTitle(contentTitle);
    mBuilder.setTicker(contentTitle);
    mBuilder.setContentText(names.toString());
    mBuilder.setStyle(style);
    if (conversation != null) {
        mBuilder.setContentIntent(createContentIntent(conversation));
    }
    mBuilder.setGroupSummary(true);
    mBuilder.setGroup(CONVERSATIONS_GROUP);
    mBuilder.setDeleteIntent(createDeleteIntent(null));
    mBuilder.setSmallIcon(R.drawable.ic_notification);
    return mBuilder;
}
Also used : SpannableString(android.text.SpannableString) Message(eu.siacs.conversations.entities.Message) Builder(androidx.core.app.NotificationCompat.Builder) StyleSpan(android.text.style.StyleSpan) NotificationCompat(androidx.core.app.NotificationCompat) Conversation(eu.siacs.conversations.entities.Conversation) SpannableString(android.text.SpannableString)

Example 15 with Conversation

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

the class NotificationService method wasHighlightedOrPrivate.

private boolean wasHighlightedOrPrivate(final Message message) {
    if (message.getConversation() instanceof Conversation) {
        Conversation conversation = (Conversation) message.getConversation();
        final String nick = conversation.getMucOptions().getActualNick();
        final Pattern highlight = generateNickHighlightPattern(nick);
        if (message.getBody() == null || nick == null) {
            return false;
        }
        final Matcher m = highlight.matcher(message.getBody());
        return (m.find() || message.isPrivateMessage());
    } else {
        return false;
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Conversation(eu.siacs.conversations.entities.Conversation) SpannableString(android.text.SpannableString)

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