Search in sources :

Example 51 with Conversation

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

the class BlockContactDialog method show.

public static void show(final XmppActivity xmppActivity, final Blockable blockable) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(xmppActivity);
    final boolean isBlocked = blockable.isBlocked();
    builder.setNegativeButton(R.string.cancel, null);
    DialogBlockContactBinding binding = DataBindingUtil.inflate(xmppActivity.getLayoutInflater(), R.layout.dialog_block_contact, null, false);
    final boolean reporting = blockable.getAccount().getXmppConnection().getFeatures().spamReporting();
    binding.reportSpam.setVisibility(!isBlocked && reporting ? View.VISIBLE : View.GONE);
    builder.setView(binding.getRoot());
    final String value;
    @StringRes int res;
    if (blockable.getJid().isFullJid()) {
        builder.setTitle(isBlocked ? R.string.action_unblock_participant : R.string.action_block_participant);
        value = blockable.getJid().toEscapedString();
        res = isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text;
    } else if (blockable.getJid().getLocal() == null || blockable.getAccount().isBlocked(blockable.getJid().getDomain())) {
        builder.setTitle(isBlocked ? R.string.action_unblock_domain : R.string.action_block_domain);
        value = blockable.getJid().getDomain().toEscapedString();
        res = isBlocked ? R.string.unblock_domain_text : R.string.block_domain_text;
    } else {
        int resBlockAction = blockable instanceof Conversation && ((Conversation) blockable).isWithStranger() ? R.string.block_stranger : R.string.action_block_contact;
        builder.setTitle(isBlocked ? R.string.action_unblock_contact : resBlockAction);
        value = blockable.getJid().asBareJid().toEscapedString();
        res = isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text;
    }
    binding.text.setText(JidDialog.style(xmppActivity, res, value));
    builder.setPositiveButton(isBlocked ? R.string.unblock : R.string.block, (dialog, which) -> {
        if (isBlocked) {
            xmppActivity.xmppConnectionService.sendUnblockRequest(blockable);
        } else {
            boolean toastShown = false;
            if (xmppActivity.xmppConnectionService.sendBlockRequest(blockable, binding.reportSpam.isChecked())) {
                Toast.makeText(xmppActivity, R.string.corresponding_conversations_closed, Toast.LENGTH_SHORT).show();
                toastShown = true;
            }
            if (xmppActivity instanceof ContactDetailsActivity) {
                if (!toastShown) {
                    Toast.makeText(xmppActivity, R.string.contact_blocked_past_tense, Toast.LENGTH_SHORT).show();
                }
                xmppActivity.finish();
            }
        }
    });
    builder.create().show();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) StringRes(androidx.annotation.StringRes) Conversation(eu.siacs.conversations.entities.Conversation) DialogBlockContactBinding(eu.siacs.conversations.databinding.DialogBlockContactBinding)

Example 52 with Conversation

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

the class ChannelDiscoveryActivity method joinChannelSearchResult.

public void joinChannelSearchResult(String selectedAccount, Room result) {
    final Jid jid = Config.DOMAIN_LOCK == null ? Jid.ofEscaped(selectedAccount) : Jid.ofLocalAndDomainEscaped(selectedAccount, Config.DOMAIN_LOCK);
    final boolean syncAutoJoin = getBooleanPreference("autojoin", R.bool.autojoin);
    final Account account = xmppConnectionService.findAccountByJid(jid);
    final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, result.getRoom(), true, true, true);
    Bookmark bookmark = conversation.getBookmark();
    if (bookmark != null) {
        if (!bookmark.autojoin() && syncAutoJoin) {
            bookmark.setAutojoin(true);
            xmppConnectionService.createBookmark(account, bookmark);
        }
    } else {
        bookmark = new Bookmark(account, conversation.getJid().asBareJid());
        bookmark.setAutojoin(syncAutoJoin);
        xmppConnectionService.createBookmark(account, bookmark);
    }
    switchToConversation(conversation);
}
Also used : Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.Jid) Bookmark(eu.siacs.conversations.entities.Bookmark) Conversation(eu.siacs.conversations.entities.Conversation)

Example 53 with Conversation

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

the class XmppConnectionService method populateWithOrderedConversations.

public void populateWithOrderedConversations(final List<Conversation> list, final boolean includeNoFileUpload, final boolean sort) {
    final List<String> orderedUuids;
    if (sort) {
        orderedUuids = null;
    } else {
        orderedUuids = new ArrayList<>();
        for (Conversation conversation : list) {
            orderedUuids.add(conversation.getUuid());
        }
    }
    list.clear();
    if (includeNoFileUpload) {
        list.addAll(getConversations());
    } else {
        for (Conversation conversation : getConversations()) {
            if (conversation.getMode() == Conversation.MODE_SINGLE || (conversation.getAccount().httpUploadAvailable() && conversation.getMucOptions().participating())) {
                list.add(conversation);
            }
        }
    }
    try {
        if (orderedUuids != null) {
            Collections.sort(list, (a, b) -> {
                final int indexA = orderedUuids.indexOf(a.getUuid());
                final int indexB = orderedUuids.indexOf(b.getUuid());
                if (indexA == -1 || indexB == -1 || indexA == indexB) {
                    return a.compareTo(b);
                }
                return indexA - indexB;
            });
        } else {
            Collections.sort(list);
        }
    } catch (IllegalArgumentException e) {
    // ignore
    }
}
Also used : Conversation(eu.siacs.conversations.entities.Conversation) SuppressLint(android.annotation.SuppressLint)

Example 54 with Conversation

use of eu.siacs.conversations.entities.Conversation 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_CHAT_STATE);
        }
    }
    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 55 with Conversation

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

the class XmppConnectionService method processDeletedBookmark.

public void processDeletedBookmark(Account account, Jid jid) {
    final Conversation conversation = find(account, jid);
    if (conversation != null && conversation.getMucOptions().getError() == MucOptions.Error.DESTROYED) {
        Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": archiving destroyed conference (" + conversation.getJid() + ") after receiving pep");
        archiveConversation(conversation, false);
    }
}
Also used : Conversation(eu.siacs.conversations.entities.Conversation)

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