Search in sources :

Example 1 with Occupant

use of org.jivesoftware.smackx.muc.Occupant in project Zom-Android by zom.

the class XmppConnection method handleMessage.

private void handleMessage(org.jivesoftware.smack.packet.Message smackMessage, boolean isOmemo, boolean notifyUser) {
    String body = smackMessage.getBody();
    boolean isGroupMessage = smackMessage.getType() == org.jivesoftware.smack.packet.Message.Type.groupchat;
    if (smackMessage.getError() != null) {
        // smackMessage.getError().getCode();
        String error = "Error " + smackMessage.getError() + " (" + smackMessage.getError().getCondition() + "): " + smackMessage.getError().getConditionText();
        debug(TAG, error);
        return;
    }
    if (body == null) {
        Collection<org.jivesoftware.smack.packet.Message.Body> mColl = smackMessage.getBodies();
        for (org.jivesoftware.smack.packet.Message.Body bodyPart : mColl) {
            String msg = bodyPart.getMessage();
            if (msg != null) {
                body = msg;
                break;
            }
        }
    }
    ChatSession session = findOrCreateSession(smackMessage.getFrom().toString(), isGroupMessage);
    if (// not subscribed so don't do anything
    session != null) {
        if (body != null && session != null) {
            Message rec = new Message(body);
            rec.setTo(new XmppAddress(smackMessage.getTo().toString()));
            rec.setFrom(new XmppAddress(smackMessage.getFrom().toString()));
            rec.setDateTime(new Date());
            rec.setID(smackMessage.getStanzaId());
            if (isOmemo)
                rec.setType(Imps.MessageType.INCOMING_ENCRYPTED_VERIFIED);
            else
                rec.setType(Imps.MessageType.INCOMING);
            // Detect if this was said by us, and mark message as outgoing
            if (isGroupMessage) {
                if (TextUtils.isEmpty(rec.getFrom().getResource())) {
                    // do nothing if there is no resource since that is a system message
                    return;
                } else if (rec.getFrom().getResource().equals(rec.getTo().getUser())) {
                    try {
                        // rec.setType(Imps.MessageType.OUTGOING);
                        Occupant oc = mChatGroupManager.getMultiUserChat(rec.getFrom().getBareAddress()).getOccupant(JidCreate.entityFullFrom(rec.getFrom().getAddress()));
                        if (oc != null && oc.getJid().equals(mUser.getAddress().getAddress()))
                            // do nothing if it is from us
                            return;
                    } catch (Exception e) {
                        debug(TAG, "error parsing address", e);
                    }
                }
            }
            boolean good = session.onReceiveMessage(rec, notifyUser);
            if (smackMessage.getExtension("request", DeliveryReceipt.NAMESPACE) != null) {
                if (good) {
                    debug(TAG, "sending delivery receipt");
                    // got XEP-0184 request, send receipt
                    sendReceipt(smackMessage);
                    session.onReceiptsExpected(true);
                } else {
                    debug(TAG, "not sending delivery receipt due to processing error");
                }
            } else {
                // no request for delivery receipt
                session.onReceiptsExpected(false);
            }
        }
    }
}
Also used : Message(org.awesomeapp.messenger.model.Message) Occupant(org.jivesoftware.smackx.muc.Occupant) ChatSession(org.awesomeapp.messenger.model.ChatSession) IChatSession(org.awesomeapp.messenger.service.IChatSession) Date(java.util.Date) KeyStoreException(java.security.KeyStoreException) UndecidedOmemoIdentityException(org.jivesoftware.smackx.omemo.exceptions.UndecidedOmemoIdentityException) XMPPException(org.jivesoftware.smack.XMPPException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ImException(org.awesomeapp.messenger.model.ImException) KeyManagementException(java.security.KeyManagementException) InvocationTargetException(java.lang.reflect.InvocationTargetException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SmackException(org.jivesoftware.smack.SmackException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) MultiUserChatException(org.jivesoftware.smackx.muc.MultiUserChatException) CryptoFailedException(org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException) CertificateException(java.security.cert.CertificateException)

Example 2 with Occupant

use of org.jivesoftware.smackx.muc.Occupant in project Spark by igniterealtime.

the class UserManager method getOccupant.

/**
 * Returns the occupant of the room identified by their nickname.
 *
 * @param groupChatRoom the GroupChatRoom.
 * @param nickname      the users nickname.
 * @return the Occupant found.
 */
public Occupant getOccupant(GroupChatRoom groupChatRoom, String nickname) {
    String userJID = groupChatRoom.getRoomname() + "/" + nickname;
    Occupant occ = null;
    try {
        occ = groupChatRoom.getMultiUserChat().getOccupant(userJID);
    } catch (Exception e) {
        Log.error(e);
    }
    return occ;
}
Also used : Occupant(org.jivesoftware.smackx.muc.Occupant)

Aggregations

Occupant (org.jivesoftware.smackx.muc.Occupant)2 RemoteException (android.os.RemoteException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateException (java.security.cert.CertificateException)1 Date (java.util.Date)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 ChatSession (org.awesomeapp.messenger.model.ChatSession)1 ImException (org.awesomeapp.messenger.model.ImException)1 Message (org.awesomeapp.messenger.model.Message)1 IChatSession (org.awesomeapp.messenger.service.IChatSession)1 SmackException (org.jivesoftware.smack.SmackException)1 XMPPException (org.jivesoftware.smack.XMPPException)1 MultiUserChatException (org.jivesoftware.smackx.muc.MultiUserChatException)1 CryptoFailedException (org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException)1 UndecidedOmemoIdentityException (org.jivesoftware.smackx.omemo.exceptions.UndecidedOmemoIdentityException)1 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)1