Search in sources :

Example 6 with RegularChat

use of com.xabber.android.data.message.RegularChat in project xabber-android by redsolution.

the class ChatViewerFragment method setUpOptionsMenu.

private void setUpOptionsMenu(Menu menu) {
    AbstractChat abstractChat = MessageManager.getInstance().getChat(account, user);
    if (abstractChat instanceof RoomChat) {
        RoomState chatState = ((RoomChat) abstractChat).getState();
        if (chatState == RoomState.available) {
            menu.findItem(R.id.action_list_of_occupants).setVisible(true);
        }
        if (chatState == RoomState.unavailable) {
            menu.findItem(R.id.action_join_conference).setVisible(true);
        } else {
            menu.findItem(R.id.action_invite_to_chat).setVisible(true);
            if (chatState == RoomState.error) {
                menu.findItem(R.id.action_authorization_settings).setVisible(true);
            } else {
                menu.findItem(R.id.action_leave_conference).setVisible(true);
            }
        }
    }
    if (abstractChat instanceof RegularChat) {
        menu.findItem(R.id.action_view_contact).setVisible(true);
        menu.findItem(R.id.action_close_chat).setVisible(true);
        menu.findItem(R.id.action_block_contact).setVisible(true);
    }
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) RoomChat(com.xabber.android.data.extension.muc.RoomChat) RegularChat(com.xabber.android.data.message.RegularChat) RoomState(com.xabber.android.data.extension.muc.RoomState)

Example 7 with RegularChat

use of com.xabber.android.data.message.RegularChat in project xabber-android by redsolution.

the class ChatActivity method getNotifMode.

private NotificationState.NotificationMode getNotifMode() {
    AbstractChat chat = MessageManager.getInstance().getOrCreateChat(account, user);
    NotificationState.NotificationMode mode = NotificationState.NotificationMode.bydefault;
    if (chat != null) {
        boolean defaultValue = chat instanceof RegularChat ? SettingsManager.eventsOnChat() : SettingsManager.eventsOnMuc();
        if (chat.getNotificationState().getMode() == NotificationState.NotificationMode.enabled && !defaultValue)
            mode = NotificationState.NotificationMode.enabled;
        if (chat.getNotificationState().getMode() == NotificationState.NotificationMode.disabled && defaultValue)
            mode = NotificationState.NotificationMode.disabled;
    }
    return mode;
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) RegularChat(com.xabber.android.data.message.RegularChat) NotificationState(com.xabber.android.data.message.NotificationState)

Example 8 with RegularChat

use of com.xabber.android.data.message.RegularChat in project xabber-android by redsolution.

the class AttentionManager method sendAttention.

public void sendAttention(AccountJid account, UserJid user) throws NetworkException {
    AbstractChat chat = MessageManager.getInstance().getOrCreateChat(account, user);
    if (!(chat instanceof RegularChat)) {
        throw new NetworkException(R.string.ENTRY_IS_NOT_FOUND);
    }
    Jid to = chat.getTo();
    if (to.getResourceOrNull() == null || to.getResourceOrNull().equals(Resourcepart.EMPTY)) {
        final Presence presence = RosterManager.getInstance().getPresence(account, user);
        if (presence == null) {
            to = null;
        } else {
            to = presence.getFrom();
        }
    }
    if (to == null) {
        throw new NetworkException(R.string.ENTRY_IS_NOT_AVAILABLE);
    }
    if (!CapabilitiesManager.getInstance().isFeatureSupported(to, AttentionExtension.NAMESPACE)) {
        throw new NetworkException(R.string.ATTENTION_IS_NOT_SUPPORTED);
    }
    Message message = new Message();
    message.setTo(to);
    message.setType(Message.Type.headline);
    message.addExtension(new AttentionExtension());
    StanzaSender.sendStanza(account, message);
    chat.newAction(null, null, ChatAction.attention_called, false);
}
Also used : UserJid(com.xabber.android.data.entity.UserJid) AccountJid(com.xabber.android.data.entity.AccountJid) Jid(org.jxmpp.jid.Jid) Message(org.jivesoftware.smack.packet.Message) AbstractChat(com.xabber.android.data.message.AbstractChat) Presence(org.jivesoftware.smack.packet.Presence) NetworkException(com.xabber.android.data.NetworkException) AttentionExtension(org.jivesoftware.smackx.attention.packet.AttentionExtension) RegularChat(com.xabber.android.data.message.RegularChat)

Example 9 with RegularChat

use of com.xabber.android.data.message.RegularChat in project xabber-android by redsolution.

the class ChatFragment method showResourceChoiceAlert.

public void showResourceChoiceAlert(final AccountJid account, final UserJid user, final boolean restartSession) {
    final List<Presence> allPresences = RosterManager.getInstance().getPresences(account, user.getJid());
    final List<Map<String, String>> items = new ArrayList<>();
    for (Presence presence : allPresences) {
        Jid fromJid = presence.getFrom();
        ClientInfo clientInfo = CapabilitiesManager.getInstance().getCachedClientInfo(fromJid);
        String client = "";
        if (clientInfo == null) {
            CapabilitiesManager.getInstance().requestClientInfoByUser(account, fromJid);
        } else if (clientInfo == ClientInfo.INVALID_CLIENT_INFO) {
            client = getString(R.string.unknown);
        } else {
            String name = clientInfo.getName();
            if (name != null) {
                client = name;
            }
            String type = clientInfo.getType();
            if (type != null) {
                if (client.isEmpty()) {
                    client = type;
                } else {
                    client = client + "/" + type;
                }
            }
        }
        Map<String, String> map = new HashMap<>();
        if (!client.isEmpty()) {
            map.put(ResourceAdapter.KEY_CLIENT, client);
        }
        Resourcepart resourceOrNull = fromJid.getResourceOrNull();
        if (resourceOrNull != null) {
            map.put(ResourceAdapter.KEY_RESOURCE, resourceOrNull.toString());
            items.add(map);
        }
    }
    final ResourceAdapter adapter = new ResourceAdapter(getActivity(), items);
    adapter.setCheckedItem(checkedResource);
    if (items.size() > 0) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle(R.string.otr_select_resource);
        builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                checkedResource = adapter.getCheckedItem();
            }
        });
        builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                checkedResource = adapter.getCheckedItem();
                try {
                    AbstractChat chat = getChat();
                    if (chat instanceof RegularChat) {
                        ((RegularChat) chat).setOTRresource(Resourcepart.from(items.get(checkedResource).get(ResourceAdapter.KEY_RESOURCE)));
                        if (restartSession)
                            restartEncryption(account, user);
                        else
                            startEncryption(account, user);
                    } else {
                        Toast.makeText(getActivity(), R.string.otr_select_toast_error, Toast.LENGTH_SHORT).show();
                    }
                } catch (XmppStringprepException e) {
                    e.printStackTrace();
                    Toast.makeText(getActivity(), R.string.otr_select_toast_error, Toast.LENGTH_SHORT).show();
                }
            }
        });
        builder.setSingleChoiceItems(adapter, checkedResource, null).show();
    } else {
        Toast.makeText(getActivity(), R.string.otr_select_toast_resources_not_found, Toast.LENGTH_SHORT).show();
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Jid(org.jxmpp.jid.Jid) AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) AbstractChat(com.xabber.android.data.message.AbstractChat) ArrayList(java.util.ArrayList) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) RegularChat(com.xabber.android.data.message.RegularChat) Resourcepart(org.jxmpp.jid.parts.Resourcepart) Presence(org.jivesoftware.smack.packet.Presence) ResourceAdapter(com.xabber.android.ui.adapter.ResourceAdapter) ClientInfo(com.xabber.android.data.extension.capability.ClientInfo) Map(java.util.Map) HashMap(java.util.HashMap)

Example 10 with RegularChat

use of com.xabber.android.data.message.RegularChat in project xabber-android by redsolution.

the class OTRManager method setNotifyIntentToChat.

private void setNotifyIntentToChat(Intent intent, AccountJid accountJid, UserJid userJid) {
    RegularChat chat = (RegularChat) MessageManager.getInstance().getOrCreateChat(accountJid, userJid);
    chat.setIntent(intent);
}
Also used : RegularChat(com.xabber.android.data.message.RegularChat)

Aggregations

RegularChat (com.xabber.android.data.message.RegularChat)10 AbstractChat (com.xabber.android.data.message.AbstractChat)9 AccountJid (com.xabber.android.data.entity.AccountJid)3 UserJid (com.xabber.android.data.entity.UserJid)3 Presence (org.jivesoftware.smack.packet.Presence)3 NetworkException (com.xabber.android.data.NetworkException)2 ClientInfo (com.xabber.android.data.extension.capability.ClientInfo)2 RoomChat (com.xabber.android.data.extension.muc.RoomChat)2 Message (org.jivesoftware.smack.packet.Message)2 Jid (org.jxmpp.jid.Jid)2 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)2 DialogInterface (android.content.DialogInterface)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 KeyEvent (android.view.KeyEvent)1 MenuInflater (android.view.MenuInflater)1 View (android.view.View)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1