Search in sources :

Example 6 with AccountItem

use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.

the class CapabilitiesManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, String bareAddress, Stanza packet) {
    if (!(connection instanceof AccountItem))
        return;
    final String account = ((AccountItem) connection).getAccount();
    final String user = Jid.getStringPrep(packet.getFrom());
    if (packet instanceof IQ) {
        IQ iq = (IQ) packet;
        if (iq.getType() != Type.error && !(packet instanceof DiscoverInfo && iq.getType() == Type.result))
            return;
        String packetId = iq.getStanzaId();
        DiscoverInfoRequest request = null;
        Iterator<DiscoverInfoRequest> iterator = requests.iterator();
        while (iterator.hasNext()) {
            DiscoverInfoRequest check = iterator.next();
            if (check.getPacketId().equals(packetId)) {
                request = check;
                iterator.remove();
                break;
            }
        }
        if (request == null || !request.getUser().equals(user))
            return;
        final Capability capability = request.getCapability();
        final ClientInfo clientInfo;
        if (iq.getType() == Type.error) {
            if (!Capability.DIRECT_REQUEST_METHOD.equals(capability.getHash()))
                // Don't save invalid replay if it wasn't direct request.
                return;
            if (clientInformations.containsKey(capability))
                return;
            clientInfo = INVALID_CLIENT_INFO;
        } else if (iq.getType() == Type.result) {
            DiscoverInfo discoverInfo = (DiscoverInfo) packet;
            if (capability.isSupportedHash() || capability.isLegacy()) {
                if (capability.isLegacy() || (isValid(discoverInfo) && capability.getHashedValue(calculateString(discoverInfo)).equals(capability.getVersion()))) {
                    clientInfo = getClientInfo(discoverInfo);
                    Application.getInstance().runInBackground(new Runnable() {

                        @Override
                        public void run() {
                            CapabilitiesTable.getInstance().write(capability.getHash(), capability.getNode(), capability.getVersion(), clientInfo.getType(), clientInfo.getName(), clientInfo.getFeatures());
                        }
                    });
                } else {
                    // Just wait for next presence from another entity.
                    return;
                }
            } else {
                clientInfo = getClientInfo(discoverInfo);
            }
        } else
            throw new IllegalStateException();
        clientInformations.put(capability, clientInfo);
        ArrayList<BaseEntity> entities = new ArrayList<>();
        for (NestedMap.Entry<Capability> entry : userCapabilities) if (capability.equals(entry.getValue()))
            entities.add(new BaseEntity(account, Jid.getBareAddress(entry.getSecond())));
        RosterManager.getInstance().onContactsChanged(entities);
    }
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) AccountItem(com.xabber.android.data.account.AccountItem) IQ(org.jivesoftware.smack.packet.IQ) ArrayList(java.util.ArrayList) BaseEntity(com.xabber.android.data.entity.BaseEntity) NestedMap(com.xabber.android.data.entity.NestedMap)

Example 7 with AccountItem

use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.

the class ServerInfoManager method onAuthorized.

@Override
public void onAuthorized(ConnectionItem connection) {
    if (connection instanceof AccountItem) {
        String account = ((AccountItem) connection).getAccount();
        if (protocols.get(account) == null) {
            DiscoverInfo packet = new DiscoverInfo();
            packet.setTo(Jid.getServer(account));
            packet.setType(Type.get);
            try {
                ConnectionManager.getInstance().sendRequest(account, packet, this);
            } catch (NetworkException e) {
            }
            return;
        }
    }
    onAvailable(connection);
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) AccountItem(com.xabber.android.data.account.AccountItem) NetworkException(com.xabber.android.data.NetworkException)

Example 8 with AccountItem

use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.

the class MessageManager 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) {
        return;
    }
    if (packet instanceof Message && MessageArchiveManager.getInstance().isModificationsSucceed(account) && Delay.isOfflineMessage(Jid.getServer(account), packet)) {
        // archive have been received.
        return;
    }
    String contact = bareAddress;
    if (packet instanceof Message) {
        Message message = (Message) packet;
        if (MUCManager.getInstance().hasRoom(account, bareAddress) && message.getType() != Message.Type.groupchat) {
            contact = packet.getFrom();
        }
    }
    final String user = packet.getFrom();
    boolean processed = false;
    for (AbstractChat chat : chats.getNested(account).values()) {
        if (chat.onPacket(contact, packet)) {
            processed = true;
            break;
        }
    }
    final AbstractChat chat = getChat(account, user);
    if (chat != null && packet instanceof Message) {
        if (chat.isPrivateMucChat() && !chat.isPrivateMucChatAccepted()) {
            if (mucPrivateChatRequestProvider.get(chat.getAccount(), chat.getUser()) == null) {
                if (!PrivateMucChatBlockingManager.getInstance().getBlockedContacts(account).contains(chat.getUser())) {
                    mucPrivateChatRequestProvider.add(new MucPrivateChatNotification(account, user), true);
                }
            }
        }
        return;
    }
    if (!processed && packet instanceof Message) {
        final Message message = (Message) packet;
        final String body = message.getBody();
        if (body == null) {
            return;
        }
        if (message.getType() == Message.Type.chat && MUCManager.getInstance().hasRoom(account, Jid.getBareAddress(user))) {
            createPrivateMucChat(account, user).onPacket(contact, packet);
            if (!PrivateMucChatBlockingManager.getInstance().getBlockedContacts(account).contains(user)) {
                mucPrivateChatRequestProvider.add(new MucPrivateChatNotification(account, user), true);
            }
            return;
        }
        for (ExtensionElement packetExtension : message.getExtensions()) {
            if (packetExtension instanceof MUCUser) {
                return;
            }
        }
        createChat(account, user).onPacket(contact, packet);
    }
}
Also used : MucPrivateChatNotification(com.xabber.android.data.message.chat.MucPrivateChatNotification) MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) Message(org.jivesoftware.smack.packet.Message) AccountItem(com.xabber.android.data.account.AccountItem) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement)

Example 9 with AccountItem

use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.

the class MessageArchiveManager method onTimeReceived.

@Override
public void onTimeReceived(final ConnectionItem connection) {
    if (!(connection instanceof AccountItem)) {
        onModifiedAvailable(connection);
        return;
    }
    String account = ((AccountItem) connection).getAccount();
    ModificationStorage modificationStorage = modificationStorages.get(account);
    if (modificationStorage == null) {
        modificationStorage = new ModificationStorage();
        modificationStorages.put(account, modificationStorage);
    }
    modificationStorage.onConnected();
    removeNotReceived(account);
    ArchiveMode archiveMode = AccountManager.getInstance().getArchiveMode(account);
    if (ServerInfoManager.getInstance().isProtocolSupported(account, FEATURE_ARCH) || ServerInfoManager.getInstance().isProtocolSupported(account, FEATURE_PREF) || ServerInfoManager.getInstance().isProtocolSupported(account, FEATURE_MANAGE)) {
        if (archiveMode == ArchiveMode.available) {
            availableArchiveRequestProvider.add(new AvailableArchiveRequest(account), null);
        }
    }
    if (archiveMode != ArchiveMode.server) {
        onModifiedAvailable(account);
        return;
    }
    if (ServerInfoManager.getInstance().isProtocolSupported(account, FEATURE_PREF)) {
        requestPreferences(account);
        return;
    }
    onPreferenceAvailable(account);
}
Also used : ArchiveMode(com.xabber.android.data.account.ArchiveMode) AccountItem(com.xabber.android.data.account.AccountItem)

Example 10 with AccountItem

use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.

the class MessageArchiveManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, final String bareAddress, Stanza packet) {
    if (!(connection instanceof AccountItem))
        return;
    String account = ((AccountItem) connection).getAccount();
    if (AccountManager.getInstance().getArchiveMode(account) != ArchiveMode.server)
        return;
    if (bareAddress != null && !Jid.getServer(account).equals(bareAddress))
        return;
    if (!(packet instanceof IQ))
        return;
    IQ iq = (IQ) packet;
    if (iq.getType() == Type.set && packet instanceof Pref && ((Pref) packet).isValid())
        onPreferenceReceived(account, (Pref) packet);
    else if (iq.getType() == Type.set && packet instanceof ItemRemove && ((ItemRemove) packet).isValid())
        onItemRemoveReceived(account, (ItemRemove) packet);
    else if (iq.getType() == Type.set && packet instanceof SessionRemove && ((SessionRemove) packet).isValid())
        onSessionRemoveReceived(account, (SessionRemove) packet);
    else if (iq.getType() == Type.result && packet instanceof List && ((List) packet).isValid())
        onListReceived(account, (List) packet);
    else if (iq.getType() == Type.result && packet instanceof Chat && ((Chat) packet).isValid())
        onChatReceived(account, (Chat) packet);
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) Pref(com.xabber.xmpp.archive.Pref) ItemRemove(com.xabber.xmpp.archive.ItemRemove) SessionRemove(com.xabber.xmpp.archive.SessionRemove) IQ(org.jivesoftware.smack.packet.IQ) AbstractChat(com.xabber.android.data.message.AbstractChat) Chat(com.xabber.xmpp.archive.Chat) List(com.xabber.xmpp.archive.List)

Aggregations

AccountItem (com.xabber.android.data.account.AccountItem)96 AccountJid (com.xabber.android.data.entity.AccountJid)24 UserJid (com.xabber.android.data.entity.UserJid)14 View (android.view.View)12 NetworkException (com.xabber.android.data.NetworkException)11 ArrayList (java.util.ArrayList)11 SmackException (org.jivesoftware.smack.SmackException)11 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)11 Message (org.jivesoftware.smack.packet.Message)11 Presence (org.jivesoftware.smack.packet.Presence)10 TextView (android.widget.TextView)9 XMPPException (org.jivesoftware.smack.XMPPException)9 Jid (org.jxmpp.jid.Jid)9 ImageView (android.widget.ImageView)8 StatusMode (com.xabber.android.data.account.StatusMode)6 ConnectionState (com.xabber.android.data.connection.ConnectionState)5 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)5 Realm (io.realm.Realm)5 ColorDrawable (android.graphics.drawable.ColorDrawable)4 AccountManager (com.xabber.android.data.account.AccountManager)4