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