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);
}
}
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);
}
});
}
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);
}
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();
}
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;
}
}
Aggregations