Search in sources :

Example 16 with MUCUser

use of org.jivesoftware.smackx.muc.packet.MUCUser in project xabber-android by redsolution.

the class MUCManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, String bareAddress, Stanza packet) {
    if (!(connection instanceof AccountItem)) {
        return;
    }
    String account = ((AccountItem) connection).getAccount();
    if (bareAddress == null || !(packet instanceof Message)) {
        return;
    }
    Message message = (Message) packet;
    if (message.getType() != Message.Type.normal && message.getType() != Message.Type.chat) {
        return;
    }
    MUCUser mucUser = MUC.getMUCUserExtension(packet);
    if (mucUser == null || mucUser.getInvite() == null) {
        return;
    }
    RoomChat roomChat = getRoomChat(account, bareAddress);
    if (roomChat == null || !roomChat.getState().inUse()) {
        String inviter = mucUser.getInvite().getFrom();
        if (inviter == null) {
            inviter = bareAddress;
        }
        inviteProvider.add(new RoomInvite(account, bareAddress, inviter, mucUser.getInvite().getReason(), mucUser.getPassword()), true);
    }
}
Also used : MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) Message(org.jivesoftware.smack.packet.Message) AccountItem(com.xabber.android.data.account.AccountItem)

Example 17 with MUCUser

use of org.jivesoftware.smackx.muc.packet.MUCUser in project xabber-android by redsolution.

the class RoomChat method createOccupant.

/**
     * Warning: this method should be placed with packet provider.
     *
     * @return New occupant based on presence information.
     */
private Occupant createOccupant(String resource, Presence presence) {
    Occupant occupant = new Occupant(resource);
    String jid = null;
    Affiliation affiliation = Affiliation.none;
    Role role = Role.none;
    StatusMode statusMode = StatusMode.unavailable;
    String statusText = null;
    MUCUser mucUser = MUC.getMUCUserExtension(presence);
    if (mucUser != null) {
        MUCItem item = mucUser.getItem();
        if (item != null) {
            jid = item.getJid();
            try {
                affiliation = Affiliation.fromString(item.getAffiliation().toString());
            } catch (NoSuchElementException e) {
            }
            try {
                role = Role.fromString(item.getRole().toString());
            } catch (NoSuchElementException e) {
            }
            statusMode = StatusMode.createStatusMode(presence);
            statusText = presence.getStatus();
        }
    }
    if (statusText == null) {
        statusText = "";
    }
    occupant.setJid(jid);
    occupant.setAffiliation(affiliation);
    occupant.setRole(role);
    occupant.setStatusMode(statusMode);
    occupant.setStatusText(statusText);
    return occupant;
}
Also used : Role(com.xabber.xmpp.muc.Role) MUCItem(org.jivesoftware.smackx.muc.packet.MUCItem) StatusMode(com.xabber.android.data.account.StatusMode) MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) NoSuchElementException(java.util.NoSuchElementException) Affiliation(com.xabber.xmpp.muc.Affiliation)

Aggregations

MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)17 Message (org.jivesoftware.smack.packet.Message)13 Presence (org.jivesoftware.smack.packet.Presence)6 AccountItem (com.xabber.android.data.account.AccountItem)3 UserJid (com.xabber.android.data.entity.UserJid)3 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)3 Resourcepart (org.jxmpp.jid.parts.Resourcepart)3 StatusMode (com.xabber.android.data.account.StatusMode)2 AccountJid (com.xabber.android.data.entity.AccountJid)2 OTRUnencryptedException (com.xabber.android.data.extension.otr.OTRUnencryptedException)2 MucPrivateChatNotification (com.xabber.android.data.message.chat.MucPrivateChatNotification)2 Date (java.util.Date)2 Map (java.util.Map)2 NoSuchElementException (java.util.NoSuchElementException)2 OtrException (net.java.otr4j.OtrException)2 MUCItem (org.jivesoftware.smackx.muc.packet.MUCItem)2 MetaData (org.jivesoftware.smackx.workgroup.MetaData)2 SessionID (org.jivesoftware.smackx.workgroup.packet.SessionID)2 NetworkException (com.xabber.android.data.NetworkException)1 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)1