Search in sources :

Example 1 with BaseEntity

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

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

the class MessageManager method onLoad.

@Override
public void onLoad() {
    final Set<BaseEntity> loadChats = new HashSet<BaseEntity>();
    Cursor cursor;
    cursor = MessageTable.getInstance().messagesToSend();
    try {
        if (cursor.moveToFirst()) {
            do {
                loadChats.add(new BaseEntity(MessageTable.getAccount(cursor), MessageTable.getUser(cursor)));
            } while (cursor.moveToNext());
        }
    } finally {
        cursor.close();
    }
    Application.getInstance().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            onLoaded(loadChats);
        }
    });
}
Also used : BaseEntity(com.xabber.android.data.entity.BaseEntity) Cursor(android.database.Cursor) HashSet(java.util.HashSet)

Example 3 with BaseEntity

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

the class AccountRosterListener method update.

private void update(Collection<String> addresses) {
    RosterManager.getInstance().updateContacts();
    Collection<BaseEntity> entities = new ArrayList<>();
    for (String address : addresses) {
        entities.add(new BaseEntity(account, address));
    }
    RosterManager.onContactsChanged(entities);
}
Also used : ArrayList(java.util.ArrayList) BaseEntity(com.xabber.android.data.entity.BaseEntity)

Example 4 with BaseEntity

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

the class ChatViewer method onContactsChanged.

@Override
public void onContactsChanged(Collection<BaseEntity> entities) {
    for (BaseEntity contact : entities) {
        for (ChatViewerFragment chat : registeredChats) {
            if (chat.isEqual(contact)) {
                chat.updateChat();
            }
        }
    }
    updateRegisteredRecentChatsFragments();
    updateStatusBar();
}
Also used : BaseEntity(com.xabber.android.data.entity.BaseEntity) ChatViewerFragment(com.xabber.android.ui.fragment.ChatViewerFragment)

Example 5 with BaseEntity

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

the class ChatViewer method getSelectedPageDataFromIntent.

private void getSelectedPageDataFromIntent() {
    Intent intent = getIntent();
    if (intent.getAction() == null) {
        return;
    }
    switch(intent.getAction()) {
        case ACTION_RECENT_CHATS:
            isRecentChatsSelected = true;
            selectedChat = null;
            break;
        case ACTION_SPECIFIC_CHAT:
        case ACTION_ATTENTION:
        case Intent.ACTION_SEND:
        case ACTION_SHORTCUT:
            isRecentChatsSelected = false;
            selectedChat = new BaseEntity(getAccount(intent), getUser(intent));
            break;
    }
}
Also used : BaseEntity(com.xabber.android.data.entity.BaseEntity) Intent(android.content.Intent)

Aggregations

BaseEntity (com.xabber.android.data.entity.BaseEntity)14 ArrayList (java.util.ArrayList)5 Intent (android.content.Intent)2 Cursor (android.database.Cursor)2 NestedMap (com.xabber.android.data.entity.NestedMap)2 AccountConfiguration (com.xabber.android.ui.adapter.AccountConfiguration)2 HashSet (java.util.HashSet)2 Uri (android.net.Uri)1 AdapterContextMenuInfo (android.widget.AdapterView.AdapterContextMenuInfo)1 ChatsShowStatusChange (com.xabber.android.data.SettingsManager.ChatsShowStatusChange)1 AccountItem (com.xabber.android.data.account.AccountItem)1 RoomChat (com.xabber.android.data.extension.muc.RoomChat)1 AbstractChat (com.xabber.android.data.message.AbstractChat)1 AbstractContact (com.xabber.android.data.roster.AbstractContact)1 RosterContact (com.xabber.android.data.roster.RosterContact)1 GroupConfiguration (com.xabber.android.ui.adapter.GroupConfiguration)1 ChatViewerFragment (com.xabber.android.ui.fragment.ChatViewerFragment)1 IQ (org.jivesoftware.smack.packet.IQ)1 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)1