Search in sources :

Example 1 with Resourcepart

use of org.jxmpp.jid.parts.Resourcepart in project xabber-android by redsolution.

the class ChatMessageAdapter method setUpAvatar.

private void setUpAvatar(MessageItem messageItem, IncomingMessage message) {
    if (SettingsManager.chatsShowAvatars()) {
        final AccountJid account = messageItem.getAccount();
        final UserJid user = messageItem.getUser();
        final Resourcepart resource = messageItem.getResource();
        message.avatar.setVisibility(View.VISIBLE);
        message.avatarBackground.setVisibility(View.VISIBLE);
        if ((isMUC && MUCManager.getInstance().getNickname(account, user.getJid().asEntityBareJidIfPossible()).equals(resource))) {
            message.avatar.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
        } else {
            if (isMUC) {
                if (resource.equals(Resourcepart.EMPTY)) {
                    message.avatar.setImageDrawable(AvatarManager.getInstance().getRoomAvatar(user));
                } else {
                    try {
                        message.avatar.setImageDrawable(AvatarManager.getInstance().getUserAvatar(UserJid.from(JidCreate.domainFullFrom(user.getJid().asDomainBareJid(), resource))));
                    } catch (UserJid.UserJidCreateException e) {
                        LogManager.exception(this, e);
                    }
                }
            } else {
                message.avatar.setImageDrawable(AvatarManager.getInstance().getUserAvatar(user));
            }
        }
    } else {
        message.avatar.setVisibility(View.GONE);
        message.avatarBackground.setVisibility(View.GONE);
    }
}
Also used : AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Example 2 with Resourcepart

use of org.jxmpp.jid.parts.Resourcepart in project xabber-android by redsolution.

the class IncomingMessageVH method setUpAvatar.

private void setUpAvatar(Context context, GroupchatUser groupchatUser, MessageItem messageItem, boolean isMUC, String userName, boolean needTail) {
    boolean needAvatar = isMUC ? SettingsManager.chatsShowAvatarsMUC() : SettingsManager.chatsShowAvatars();
    // for new groupchats (0GGG)
    if (groupchatUser != null && SettingsManager.chatsShowAvatarsMUC())
        needAvatar = true;
    if (!needAvatar) {
        avatar.setVisibility(View.GONE);
        avatarBackground.setVisibility(View.GONE);
        return;
    }
    if (!needTail) {
        avatar.setVisibility(View.INVISIBLE);
        avatarBackground.setVisibility(View.INVISIBLE);
        return;
    }
    avatar.setVisibility(View.VISIBLE);
    avatarBackground.setVisibility(View.VISIBLE);
    // groupchat avatar
    if (groupchatUser != null) {
        Drawable placeholder;
        try {
            UserJid userJid = UserJid.from(messageItem.getUser().getJid().toString() + "/" + groupchatUser.getNickname());
            placeholder = AvatarManager.getInstance().getOccupantAvatar(userJid, groupchatUser.getNickname());
        } catch (UserJid.UserJidCreateException e) {
            placeholder = AvatarManager.getInstance().generateDefaultAvatar(groupchatUser.getNickname(), groupchatUser.getNickname());
        }
        Glide.with(context).load(groupchatUser.getAvatar()).centerCrop().placeholder(placeholder).error(placeholder).into(avatar);
        return;
    }
    final UserJid user = messageItem.getUser();
    final AccountJid account = messageItem.getAccount();
    final Resourcepart resource = messageItem.getResource();
    if (!isMUC)
        avatar.setImageDrawable(AvatarManager.getInstance().getUserAvatarForContactList(user, userName));
    else {
        if ((MUCManager.getInstance().getNickname(account, user.getJid().asEntityBareJidIfPossible()).equals(resource))) {
            avatar.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
        } else {
            if (resource.equals(Resourcepart.EMPTY)) {
                avatar.setImageDrawable(AvatarManager.getInstance().getRoomAvatarForContactList(user));
            } else {
                String nick = resource.toString();
                UserJid userJid = null;
                try {
                    userJid = UserJid.from(user.getJid().toString() + "/" + resource.toString());
                    avatar.setImageDrawable(AvatarManager.getInstance().getOccupantAvatar(userJid, nick));
                } catch (UserJid.UserJidCreateException e) {
                    LogManager.exception(this, e);
                    avatar.setImageDrawable(AvatarManager.getInstance().generateDefaultAvatar(nick, nick));
                }
            }
        }
    }
}
Also used : AccountJid(com.xabber.android.data.entity.AccountJid) Drawable(android.graphics.drawable.Drawable) UserJid(com.xabber.android.data.entity.UserJid) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Example 3 with Resourcepart

use of org.jxmpp.jid.parts.Resourcepart in project xabber-android by redsolution.

the class OccupantListAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final View view;
    if (convertView == null) {
        view = activity.getLayoutInflater().inflate(R.layout.item_occupant, parent, false);
    } else {
        view = convertView;
    }
    final Occupant occupant = (Occupant) getItem(position);
    final ImageView avatarView = (ImageView) view.findViewById(R.id.ivAvatar);
    avatarView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent;
            try {
                intent = ContactActivity.createIntent(activity, account, UserJid.from(JidCreate.domainFullFrom(room.asDomainBareJid(), occupant.getNickname())));
                activity.startActivity(intent);
            } catch (UserJid.UserJidCreateException e) {
                LogManager.exception(this, e);
            }
        }
    });
    final ImageView affilationView = (ImageView) view.findViewById(R.id.affilation);
    final TextView nameView = (TextView) view.findViewById(R.id.name);
    final TextView statusTextView = (TextView) view.findViewById(R.id.status);
    final ImageView statusModeView = (ImageView) view.findViewById(R.id.ivStatus);
    // avatar
    Resourcepart nickname = occupant.getNickname();
    if (nickname != null && MUCManager.getInstance().getNickname(account, room).equals(nickname)) {
        avatarView.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
    } else {
        String nick = occupant.getJid().getResourceOrEmpty().toString();
        UserJid userJid = null;
        try {
            userJid = UserJid.from(occupant.getJid());
            avatarView.setImageDrawable(AvatarManager.getInstance().getOccupantAvatar(userJid, nick));
        } catch (UserJid.UserJidCreateException e) {
            LogManager.exception(this, e);
            avatarView.setImageDrawable(AvatarManager.getInstance().generateDefaultAvatar(nick, nick));
        }
    }
    affilationView.setImageLevel(occupant.getAffiliation().ordinal());
    nameView.setText(occupant.getNickname());
    String status;
    if (occupant.getRole() == MUCRole.moderator)
        status = activity.getString(R.string.muc_role_moderator);
    else if (occupant.getRole() == MUCRole.participant)
        status = activity.getString(R.string.muc_role_participant);
    else
        status = activity.getString(R.string.muc_role_visitor);
    String statusText = occupant.getStatusText();
    if (statusText != null && !statusText.isEmpty())
        status = status + " • " + statusText;
    statusTextView.setText(status);
    statusModeView.setImageLevel(occupant.getStatusMode().getStatusLevel());
    return view;
}
Also used : Occupant(com.xabber.android.data.extension.muc.Occupant) UserJid(com.xabber.android.data.entity.UserJid) Intent(android.content.Intent) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Example 4 with Resourcepart

use of org.jxmpp.jid.parts.Resourcepart in project xabber-android by redsolution.

the class ChatStateManager method onDisconnect.

@Override
public void onDisconnect(ConnectionItem connection) {
    if (!(connection instanceof AccountItem))
        return;
    AccountJid account = ((AccountItem) connection).getAccount();
    chatStates.clear(account.toString());
    for (Map<Resourcepart, Runnable> map : stateCleaners.getNested(account.toString()).values()) {
        for (Runnable runnable : map.values()) {
            handler.removeCallbacks(runnable);
        }
    }
    stateCleaners.clear(account.toString());
    supports.clear(account.toString());
    sent.clear(account.toString());
    for (PendingIntent pendingIntent : pauseIntents.getNested(account.toString()).values()) {
        alarmManager.cancel(pendingIntent);
    }
    pauseIntents.clear(account.toString());
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid) PendingIntent(android.app.PendingIntent) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Example 5 with Resourcepart

use of org.jxmpp.jid.parts.Resourcepart in project xabber-android by redsolution.

the class ChatStateManager method onStanza.

@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
    if (stanza.getFrom() == null) {
        return;
    }
    final Resourcepart resource = stanza.getFrom().getResourceOrNull();
    if (resource == null) {
        return;
    }
    final AccountJid account = ((AccountItem) connection).getAccount();
    final UserJid bareUserJid;
    try {
        bareUserJid = UserJid.from(stanza.getFrom()).getBareUserJid();
    } catch (UserJid.UserJidCreateException e) {
        return;
    }
    if (stanza instanceof Presence) {
        Presence presence = (Presence) stanza;
        if (presence.getType() != Type.unavailable) {
            return;
        }
        chatStates.remove(account.toString(), bareUserJid.toString(), resource);
        removeCallback(account, bareUserJid.getBareJid(), resource);
        supports.remove(account.toString(), bareUserJid.toString(), resource);
    } else if (stanza instanceof Message) {
        boolean support = false;
        for (ExtensionElement extension : stanza.getExtensions()) if (extension instanceof ChatStateExtension) {
            removeCallback(account, bareUserJid.getBareJid(), resource);
            ChatState chatState = ((ChatStateExtension) extension).getChatState();
            chatStates.put(account.toString(), bareUserJid.toString(), resource, chatState);
            if (chatState != ChatState.active) {
                Runnable runnable = new Runnable() {

                    @Override
                    public void run() {
                        if (this != stateCleaners.get(account.toString(), bareUserJid.toString(), resource)) {
                            return;
                        }
                        chatStates.remove(account.toString(), bareUserJid.toString(), resource);
                        removeCallback(account, bareUserJid.getBareJid(), resource);
                        RosterManager.onChatStateChanged(account, bareUserJid);
                    }
                };
                handler.postDelayed(runnable, REMOVE_STATE_DELAY);
                stateCleaners.put(account.toString(), bareUserJid.toString(), resource, runnable);
            }
            RosterManager.onChatStateChanged(account, bareUserJid);
            support = true;
            break;
        }
        Message message = (Message) stanza;
        if (message.getType() != Message.Type.chat && message.getType() != Message.Type.groupchat) {
            return;
        }
        if (support) {
            supports.put(account.toString(), bareUserJid.toString(), resource, true);
        } else if (supports.get(account.toString(), bareUserJid.toString(), resource) == null) {
            // Disable only if there no information about support.
            supports.put(account.toString(), bareUserJid.toString(), resource, false);
        }
    }
}
Also used : ChatState(org.jivesoftware.smackx.chatstates.ChatState) Message(org.jivesoftware.smack.packet.Message) ChatStateExtension(org.jivesoftware.smackx.chatstates.packet.ChatStateExtension) AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) UserJid(com.xabber.android.data.entity.UserJid) Presence(org.jivesoftware.smack.packet.Presence) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Aggregations

Resourcepart (org.jxmpp.jid.parts.Resourcepart)54 EntityBareJid (org.jxmpp.jid.EntityBareJid)24 SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)20 XMPPException (org.jivesoftware.smack.XMPPException)19 TestNotPossibleException (org.igniterealtime.smack.inttest.TestNotPossibleException)17 SmackException (org.jivesoftware.smack.SmackException)16 Presence (org.jivesoftware.smack.packet.Presence)16 ResultSyncPoint (org.igniterealtime.smack.inttest.util.ResultSyncPoint)15 EntityFullJid (org.jxmpp.jid.EntityFullJid)13 UserJid (com.xabber.android.data.entity.UserJid)11 Jid (org.jxmpp.jid.Jid)9 AccountJid (com.xabber.android.data.entity.AccountJid)8 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)8 DomainBareJid (org.jxmpp.jid.DomainBareJid)7 MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)6 AccountItem (com.xabber.android.data.account.AccountItem)4 Localpart (org.jxmpp.jid.parts.Localpart)4 Attachment (com.xabber.android.data.database.messagerealm.Attachment)3 ForwardId (com.xabber.android.data.database.messagerealm.ForwardId)3 ArrayList (java.util.ArrayList)3