Search in sources :

Example 31 with Resourcepart

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

the class ContactVcardViewerFragment method fillResourceList.

private void fillResourceList(AccountJid account, Jid bareAddress, List<View> resourcesList) {
    final List<Presence> allPresences = RosterManager.getInstance().getPresences(account, bareAddress);
    boolean isAccount = account.getFullJid().asBareJid().equals(user.getBareJid());
    Resourcepart accountResource = null;
    if (isAccount) {
        // TODO: probably not the best way to get own resource
        AccountItem accountItem = AccountManager.getInstance().getAccount(account);
        if (accountItem != null) {
            accountResource = accountItem.getConnection().getConfiguration().getResource();
        }
    }
    PresenceManager.sortPresencesByPriority(allPresences);
    for (Presence presence : allPresences) {
        Jid fromJid = presence.getFrom();
        ClientInfo clientInfo = CapabilitiesManager.getInstance().getCachedClientInfo(fromJid);
        String client = "";
        if (clientInfo == null) {
            client = getString(R.string.please_wait);
            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;
                }
            }
        }
        int priorityValue = presence.getPriority();
        String priorityString;
        if (priorityValue == Integer.MIN_VALUE) {
            priorityString = getString(R.string.account_priority) + ": " + getString(R.string.unknown);
        } else {
            priorityString = getString(R.string.account_priority) + ": " + priorityValue;
        }
        if (!client.isEmpty()) {
            client = getString(R.string.contact_viewer_client) + ": " + client;
        }
        Resourcepart resourceOrNull = fromJid.getResourceOrNull();
        String resource = getString(R.string.account_resource) + ": " + resourceOrNull;
        final StatusMode statusMode = StatusMode.createStatusMode(presence);
        String status = presence.getStatus();
        if (TextUtils.isEmpty(status)) {
            status = getString(statusMode.getStringID());
        }
        LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        View resourceView = inflater.inflate(R.layout.item_contact_info, xmppItems, false);
        resourceView.findViewById(R.id.contact_info_item_secondary);
        ((TextView) resourceView.findViewById(R.id.contact_info_item_secondary)).setText(client);
        ((TextView) resourceView.findViewById(R.id.contact_info_item_main)).setText(status);
        ((TextView) resourceView.findViewById(R.id.contact_info_item_secondary_second_line)).setText(resource);
        resourceView.findViewById(R.id.contact_info_item_secondary_second_line).setVisibility(View.VISIBLE);
        ((TextView) resourceView.findViewById(R.id.contact_info_item_secondary_third_line)).setText(priorityString);
        resourceView.findViewById(R.id.contact_info_item_secondary_third_line).setVisibility(View.VISIBLE);
        if (isAccount && resourceOrNull != null && resourceOrNull.equals(accountResource)) {
            TextView thisDeviceIndicatorTextView = (TextView) resourceView.findViewById(R.id.contact_info_item_secondary_forth_line);
            thisDeviceIndicatorTextView.setTextColor(ColorManager.getInstance().getAccountPainter().getAccountSendButtonColor(account));
            thisDeviceIndicatorTextView.setText(R.string.contact_viewer_this_device);
            thisDeviceIndicatorTextView.setVisibility(View.VISIBLE);
        }
        ImageView statusIcon = (ImageView) resourceView.findViewById(R.id.contact_info_right_icon);
        statusIcon.setVisibility(View.VISIBLE);
        statusIcon.setImageResource(R.drawable.ic_status);
        statusIcon.setImageLevel(statusMode.getStatusLevel());
        resourcesList.add(resourceView);
    }
}
Also used : StatusMode(com.xabber.android.data.account.StatusMode) AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) Jid(org.jxmpp.jid.Jid) AccountItem(com.xabber.android.data.account.AccountItem) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Resourcepart(org.jxmpp.jid.parts.Resourcepart) LayoutInflater(android.view.LayoutInflater) Presence(org.jivesoftware.smack.packet.Presence) TextView(android.widget.TextView) ClientInfo(com.xabber.android.data.extension.capability.ClientInfo) ImageView(android.widget.ImageView)

Example 32 with Resourcepart

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

the class RegularChat method parseInnerMessage.

@Override
protected String parseInnerMessage(boolean ui, Message message, Date timestamp, String parentMessageId) {
    if (message.getType() == Message.Type.error)
        return null;
    MUCUser mucUser = MUCUser.from(message);
    if (mucUser != null && mucUser.getInvite() != null)
        return null;
    final Jid fromJid = message.getFrom();
    Resourcepart resource = null;
    if (fromJid != null)
        resource = fromJid.getResourceOrNull();
    String text = message.getBody();
    if (text == null)
        return null;
    boolean encrypted = OTRManager.getInstance().isEncrypted(text);
    RealmList<Attachment> attachments = HttpFileUploadManager.parseFileMessage(message);
    String uid = UUID.randomUUID().toString();
    RealmList<ForwardId> forwardIds = parseForwardedMessage(ui, message, uid);
    String originalStanza = message.toXML().toString();
    String originalFrom = "";
    if (fromJid != null)
        originalFrom = fromJid.toString();
    boolean fromMuc = message.getType().equals(Type.groupchat);
    // groupchat
    String gropchatUserId = null;
    RefUser groupchatUser = ReferencesManager.getGroupchatUserFromReferences(message);
    if (groupchatUser != null) {
        gropchatUserId = groupchatUser.getId();
        GroupchatUserManager.getInstance().saveGroupchatUser(groupchatUser, timestamp.getTime());
    }
    // forward comment (to support previous forwarded xep)
    String forwardComment = ForwardManager.parseForwardComment(message);
    if (forwardComment != null && !forwardComment.isEmpty())
        text = forwardComment;
    // modify body with references
    Pair<String, String> bodies = ReferencesManager.modifyBodyWithReferences(message, text);
    text = bodies.first;
    String markupText = bodies.second;
    // create message with file-attachments
    if (attachments.size() > 0)
        createAndSaveFileMessage(ui, uid, resource, text, markupText, null, timestamp, getDelayStamp(message), true, false, encrypted, false, getStanzaId(message), attachments, originalStanza, parentMessageId, originalFrom, fromMuc, true, gropchatUserId);
    else
        // create message without attachments
        createAndSaveNewMessage(ui, uid, resource, text, markupText, null, timestamp, getDelayStamp(message), true, false, encrypted, false, getStanzaId(message), originalStanza, parentMessageId, originalFrom, forwardIds, fromMuc, true, gropchatUserId);
    return uid;
}
Also used : RefUser(com.xabber.android.data.extension.references.RefUser) MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) UserJid(com.xabber.android.data.entity.UserJid) AccountJid(com.xabber.android.data.entity.AccountJid) Jid(org.jxmpp.jid.Jid) Attachment(com.xabber.android.data.database.messagerealm.Attachment) ForwardId(com.xabber.android.data.database.messagerealm.ForwardId) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Example 33 with Resourcepart

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

the class RegularChat method onPacket.

@Override
protected boolean onPacket(UserJid bareAddress, Stanza packet, boolean isCarbons) {
    if (!super.onPacket(bareAddress, packet, isCarbons))
        return false;
    final Resourcepart resource = packet.getFrom().getResourceOrNull();
    if (packet instanceof Presence) {
        final Presence presence = (Presence) packet;
        if (this.resource != null && presence.getType() == Presence.Type.unavailable && resource != null && this.resource.equals(resource)) {
            this.resource = null;
        }
        if (packet.hasExtension(RefUser.NAMESPACE)) {
            this.isGroupchat = true;
        }
    // if (presence.getType() == Presence.Type.unavailable) {
    // OTRManager.getInstance().onContactUnAvailable(account, user);
    // }
    } else if (packet instanceof Message) {
        final Message message = (Message) packet;
        if (message.getType() == Message.Type.error)
            return true;
        MUCUser mucUser = MUCUser.from(message);
        if (mucUser != null && mucUser.getInvite() != null)
            return true;
        String text = message.getBody();
        if (text == null)
            return true;
        DelayInformation delayInformation = message.getExtension(DelayInformation.ELEMENT, DelayInformation.NAMESPACE);
        if (delayInformation != null && "Offline Storage".equals(delayInformation.getReason())) {
            return true;
        }
        // Xabber service message received
        if (message.getType() == Type.headline) {
            if (XMPPAuthManager.getInstance().isXabberServiceMessage(message.getStanzaId()))
                return true;
        }
        String thread = message.getThread();
        updateThreadId(thread);
        if (resource != null && !resource.equals(Resourcepart.EMPTY)) {
            this.resource = resource;
        }
        boolean encrypted = OTRManager.getInstance().isEncrypted(text);
        if (!isCarbons) {
            try {
                text = OTRManager.getInstance().transformReceiving(account, user, text);
            } catch (OtrException e) {
                if (e.getCause() instanceof OTRUnencryptedException) {
                    text = ((OTRUnencryptedException) e.getCause()).getText();
                    encrypted = false;
                } else {
                    LogManager.exception(this, e);
                    // Invalid message received.
                    return true;
                }
            }
        }
        // groupchat
        String gropchatUserId = null;
        RefUser groupchatUser = ReferencesManager.getGroupchatUserFromReferences(packet);
        if (groupchatUser != null) {
            gropchatUserId = groupchatUser.getId();
            GroupchatUserManager.getInstance().saveGroupchatUser(groupchatUser);
        }
        RealmList<Attachment> attachments = HttpFileUploadManager.parseFileMessage(packet);
        String uid = UUID.randomUUID().toString();
        RealmList<ForwardId> forwardIds = parseForwardedMessage(true, packet, uid);
        String originalStanza = packet.toXML().toString();
        String originalFrom = packet.getFrom().toString();
        // forward comment (to support previous forwarded xep)
        String forwardComment = ForwardManager.parseForwardComment(packet);
        if (forwardComment != null)
            text = forwardComment;
        // System message received.
        if ((text == null || text.trim().equals("")) && (forwardIds == null || forwardIds.isEmpty()))
            return true;
        // modify body with references
        Pair<String, String> bodies = ReferencesManager.modifyBodyWithReferences(message, text);
        text = bodies.first;
        String markupText = bodies.second;
        // create message with file-attachments
        if (attachments.size() > 0)
            createAndSaveFileMessage(true, uid, resource, text, markupText, null, null, getDelayStamp(message), true, true, encrypted, isOfflineMessage(account.getFullJid().getDomain(), packet), getStanzaId(message), attachments, originalStanza, null, originalFrom, false, false, gropchatUserId);
        else
            // create message without attachments
            createAndSaveNewMessage(true, uid, resource, text, markupText, null, null, getDelayStamp(message), true, true, encrypted, isOfflineMessage(account.getFullJid().getDomain(), packet), getStanzaId(message), originalStanza, null, originalFrom, forwardIds, false, false, gropchatUserId);
        EventBus.getDefault().post(new NewIncomingMessageEvent(account, user));
    }
    return true;
}
Also used : RefUser(com.xabber.android.data.extension.references.RefUser) MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) RealmList(io.realm.RealmList) Message(org.jivesoftware.smack.packet.Message) DelayInformation(org.jivesoftware.smackx.delay.packet.DelayInformation) Presence(org.jivesoftware.smack.packet.Presence) OtrException(net.java.otr4j.OtrException) OTRUnencryptedException(com.xabber.android.data.extension.otr.OTRUnencryptedException) Resourcepart(org.jxmpp.jid.parts.Resourcepart) Pair(android.util.Pair)

Example 34 with Resourcepart

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

the class PresenceManager method getOccupant.

/**
 * if contact is private MUC chat
 */
@Nullable
private Occupant getOccupant(AccountJid account, UserJid user) {
    EntityBareJid userEntityBareJid = user.getJid().asEntityBareJidIfPossible();
    if (userEntityBareJid == null) {
        return null;
    }
    Resourcepart resourcepart = user.getJid().getResourceOrNull();
    if (resourcepart == null) {
        return null;
    }
    if (MUCManager.getInstance().hasRoom(account, userEntityBareJid)) {
        final Collection<Occupant> occupants = MUCManager.getInstance().getOccupants(account, userEntityBareJid);
        for (Occupant occupant : occupants) {
            if (occupant.getNickname().equals(resourcepart)) {
                return occupant;
            }
        }
    }
    return null;
}
Also used : Occupant(com.xabber.android.data.extension.muc.Occupant) EntityBareJid(org.jxmpp.jid.EntityBareJid) Resourcepart(org.jxmpp.jid.parts.Resourcepart) Nullable(androidx.annotation.Nullable)

Example 35 with Resourcepart

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

the class RoomChat method parseInnerMessage.

@Override
protected String parseInnerMessage(boolean ui, Message message, Date timestamp, String parentMessageId) {
    if (message.getType() == Message.Type.error)
        return null;
    final org.jxmpp.jid.Jid from = message.getFrom();
    final Resourcepart resource = from.getResourceOrNull();
    String text = message.getBody();
    final String subject = message.getSubject();
    if (text == null)
        return null;
    if (subject != null)
        return null;
    RealmList<Attachment> attachments = HttpFileUploadManager.parseFileMessage(message);
    String uid = UUID.randomUUID().toString();
    RealmList<ForwardId> forwardIds = parseForwardedMessage(ui, message, uid);
    String originalStanza = message.toXML().toString();
    String originalFrom = message.getFrom().toString();
    boolean fromMUC = message.getType().equals(Type.groupchat);
    // forward comment (to support previous forwarded xep)
    String forwardComment = ForwardManager.parseForwardComment(message);
    if (forwardComment != null)
        text = forwardComment;
    // modify body with references
    Pair<String, String> bodies = ReferencesManager.modifyBodyWithReferences(message, text);
    text = bodies.first;
    String markupText = bodies.second;
    // create message with file-attachments
    if (attachments.size() > 0)
        createAndSaveFileMessage(ui, uid, resource, text, markupText, null, timestamp, getDelayStamp(message), true, false, false, false, getStanzaId(message), attachments, originalStanza, parentMessageId, originalFrom, fromMUC, true, null);
    else
        // create message without attachments
        createAndSaveNewMessage(ui, uid, resource, text, markupText, null, timestamp, getDelayStamp(message), true, false, false, false, getStanzaId(message), originalStanza, parentMessageId, originalFrom, forwardIds, fromMUC, true, null);
    return uid;
}
Also used : Attachment(com.xabber.android.data.database.messagerealm.Attachment) ForwardId(com.xabber.android.data.database.messagerealm.ForwardId) 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