Search in sources :

Example 36 with UserJid

use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.

the class ChatMarkerManager method processCarbonsMessage.

public void processCarbonsMessage(AccountJid account, final Message message, CarbonExtension.Direction direction) {
    if (direction == CarbonExtension.Direction.sent) {
        ChatMarkersElements.DisplayedExtension extension = ChatMarkersElements.DisplayedExtension.from(message);
        if (extension != null) {
            UserJid companion;
            try {
                companion = UserJid.from(message.getTo()).getBareUserJid();
            } catch (UserJid.UserJidCreateException e) {
                return;
            }
            AbstractChat chat = MessageManager.getInstance().getOrCreateChat(account, companion);
            if (chat != null) {
                chat.markAsRead(extension.getId(), false);
                MessageNotificationManager.getInstance().removeChatWithTimer(account, companion);
                // start grace period
                AccountManager.getInstance().startGracePeriod(account);
            }
        }
    }
}
Also used : ChatMarkersElements(org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements) AbstractChat(com.xabber.android.data.message.AbstractChat) UserJid(com.xabber.android.data.entity.UserJid)

Example 37 with UserJid

use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.

the class AttentionManager method onStanza.

@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
    if (!(stanza instanceof Message)) {
        return;
    }
    if (!SettingsManager.chatsAttention()) {
        return;
    }
    final AccountJid account = connection.getAccount();
    UserJid from;
    try {
        from = UserJid.from(stanza.getFrom());
    } catch (UserJid.UserJidCreateException e) {
        e.printStackTrace();
        return;
    }
    for (ExtensionElement packetExtension : stanza.getExtensions()) {
        if (packetExtension instanceof AttentionExtension) {
            boolean fromMUC = ((Message) stanza).getType().equals(Message.Type.groupchat);
            MessageManager.getInstance().openChat(account, from);
            MessageManager.getInstance().getOrCreateChat(account, from).newAction(null, null, ChatAction.attention_requested, fromMUC);
            attentionRequestProvider.add(new AttentionRequest(account, from.getBareUserJid()), true);
        }
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) AccountJid(com.xabber.android.data.entity.AccountJid) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) UserJid(com.xabber.android.data.entity.UserJid) AttentionExtension(org.jivesoftware.smackx.attention.packet.AttentionExtension)

Example 38 with UserJid

use of com.xabber.android.data.entity.UserJid 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 39 with UserJid

use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.

the class MUCManager method onStanza.

@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
    if (!(connection instanceof AccountItem)) {
        return;
    }
    AccountJid account = ((AccountItem) connection).getAccount();
    Jid from = stanza.getFrom();
    if (from == null || !(stanza instanceof Message)) {
        return;
    }
    Message message = (Message) stanza;
    if (message.getType() != Message.Type.normal && message.getType() != Message.Type.chat) {
        return;
    }
    MUCUser mucUser = MUCUser.from(stanza);
    if (mucUser == null || mucUser.getInvite() == null) {
        return;
    }
    RoomChat roomChat = getRoomChat(account, from.asEntityBareJidIfPossible());
    if (roomChat == null || !roomChat.getState().inUse()) {
        UserJid inviter = null;
        try {
            inviter = UserJid.from(mucUser.getInvite().getFrom());
        } catch (UserJid.UserJidCreateException e) {
            LogManager.exception(this, e);
        }
        if (inviter == null) {
            try {
                inviter = UserJid.from(from);
            } catch (UserJid.UserJidCreateException e) {
                LogManager.exception(this, e);
            }
        }
        try {
            inviteProvider.add(new RoomInvite(account, UserJid.from(from), inviter, mucUser.getInvite().getReason(), mucUser.getPassword()), true);
        } catch (UserJid.UserJidCreateException e) {
            LogManager.exception(this, e);
        }
    }
}
Also used : MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) UserJid(com.xabber.android.data.entity.UserJid) AccountJid(com.xabber.android.data.entity.AccountJid) DomainBareJid(org.jxmpp.jid.DomainBareJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) Jid(org.jxmpp.jid.Jid) Message(org.jivesoftware.smack.packet.Message) AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid)

Example 40 with UserJid

use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.

the class OTRManager method askForSecret.

@Override
public void askForSecret(SessionID sessionID, InstanceTag receiverTag, String question) {
    try {
        AccountJid accountJid = AccountJid.from(sessionID.getAccountID());
        UserJid userJid = UserJid.from(sessionID.getUserID());
        // set notify intent to chat
        setNotifyIntentToChat(QuestionActivity.createIntent(Application.getInstance(), accountJid, userJid, question != null, true, question), accountJid, userJid);
        // show android notification
        SMRequest request = new SMRequest(AccountJid.from(sessionID.getAccountID()), UserJid.from(sessionID.getUserID()), question);
        smRequestProvider.add(request, true);
        // send event of adding auth request to fragment
        EventBus.getDefault().post(new AuthAskEvent(accountJid, userJid));
    } catch (UserJid.UserJidCreateException | XmppStringprepException e) {
        LogManager.exception(this, e);
    }
}
Also used : AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException)

Aggregations

UserJid (com.xabber.android.data.entity.UserJid)67 AccountJid (com.xabber.android.data.entity.AccountJid)43 AbstractChat (com.xabber.android.data.message.AbstractChat)15 ArrayList (java.util.ArrayList)15 Intent (android.content.Intent)9 Jid (org.jxmpp.jid.Jid)9 Presence (org.jivesoftware.smack.packet.Presence)8 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)8 AccountItem (com.xabber.android.data.account.AccountItem)7 AbstractContact (com.xabber.android.data.roster.AbstractContact)6 Message (org.jivesoftware.smack.packet.Message)6 Resourcepart (org.jxmpp.jid.parts.Resourcepart)6 NetworkException (com.xabber.android.data.NetworkException)5 IFlexible (eu.davidea.flexibleadapter.items.IFlexible)5 SmackException (org.jivesoftware.smack.SmackException)5 Uri (android.net.Uri)4 ContactVO (com.xabber.android.presentation.ui.contactlist.viewobjects.ContactVO)4 DomainBareJid (org.jxmpp.jid.DomainBareJid)4 TextView (android.widget.TextView)3 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)3