use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class ReceiptManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza packet) {
if (!(connection instanceof AccountItem)) {
return;
}
final AccountJid account = ((AccountItem) connection).getAccount();
final Jid from = packet.getFrom();
if (from == null) {
return;
}
if (!(packet instanceof Message)) {
return;
}
final Message message = (Message) packet;
if (message.getType() == Message.Type.error) {
Application.getInstance().runInBackgroundUserRequest(new Runnable() {
@Override
public void run() {
markAsError(account, message);
}
});
} else {
// TODO setDefaultAutoReceiptMode should be used
for (ExtensionElement packetExtension : message.getExtensions()) {
if (packetExtension instanceof DeliveryReceiptRequest) {
String id = AbstractChat.getStanzaId(message);
if (id == null) {
continue;
}
Message receipt = new Message(from);
receipt.addExtension(new DeliveryReceipt(id));
// the key problem is Thread - smack does not keep it in auto reply
receipt.setThread(message.getThread());
receipt.setType(Message.Type.chat);
try {
StanzaSender.sendStanza(account, receipt);
} catch (NetworkException e) {
LogManager.exception(this, e);
}
}
}
}
}
use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class SSNManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
Jid from = stanza.getFrom();
if (from == null) {
return;
}
if (!(connection instanceof AccountItem) || !(stanza instanceof Message)) {
return;
}
AccountJid account = ((AccountItem) connection).getAccount();
Message message = (Message) stanza;
String session = message.getThread();
if (session == null) {
return;
}
for (ExtensionElement packetExtension : stanza.getExtensions()) {
if (packetExtension instanceof Feature) {
Feature feature = (Feature) packetExtension;
if (!feature.isValid()) {
continue;
}
DataForm.Type dataFormType = feature.getDataFormType();
if (dataFormType == DataForm.Type.form) {
onFormReceived(account, from, session, feature);
} else if (dataFormType == DataForm.Type.submit) {
onSubmitReceived(account, from, session, feature);
} else if (dataFormType == DataForm.Type.result) {
onResultReceived(account, session, feature);
}
}
}
}
use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class VCardManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
if (!(connection instanceof AccountItem)) {
return;
}
AccountJid account = connection.getAccount();
if (stanza instanceof Presence && ((Presence) stanza).getType() != Presence.Type.error) {
Jid from = stanza.getFrom();
if (from == null) {
return;
}
Jid addressForVcard = from;
if (MUCManager.getInstance().hasRoom(account, from.asEntityBareJidIfPossible())) {
addressForVcard = from;
}
// Request vCard for new users
if (!names.containsKey(addressForVcard)) {
if (SettingsManager.connectionLoadVCard()) {
request(account, addressForVcard);
}
}
}
if (stanza instanceof VCard) {
Jid from = stanza.getFrom();
if (from == null)
return;
onVCardReceived(account, from, (VCard) stanza);
}
}
use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class VCardManager method saveVCard.
public void saveVCard(final AccountJid account, final VCard vCard) {
AccountItem accountItem = AccountManager.getInstance().getAccount(account);
if (accountItem == null) {
onVCardSaveFailed(account);
return;
}
final AbstractXMPPConnection xmppConnection = accountItem.getConnection();
final CustomVCardManager vCardManager = CustomVCardManager.getInstanceFor(xmppConnection);
Application.getInstance().runInBackgroundUserRequest(new Runnable() {
@Override
public void run() {
boolean isSuccess = true;
xmppConnection.setPacketReplyTimeout(120000);
vCardSaveRequests.add(account);
try {
vCardManager.saveVCard(vCard);
String avatarHash = null;
try {
avatarHash = vCard.getAvatarHash();
// "bad base-64" error happen sometimes
} catch (IllegalArgumentException e) {
LogManager.exception(this, e);
}
if (avatarHash == null) {
avatarHash = AvatarManager.EMPTY_HASH;
}
PresenceManager.getInstance().sendVCardUpdatePresence(account, avatarHash);
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | NetworkException | InterruptedException e) {
LogManager.w(this, "Error saving vCard: " + e.getMessage());
isSuccess = false;
}
vCardSaveRequests.remove(account);
xmppConnection.setPacketReplyTimeout(ConnectionManager.PACKET_REPLY_TIMEOUT);
final boolean finalIsSuccess = isSuccess;
Application.getInstance().runOnUiThread(new Runnable() {
@Override
public void run() {
if (finalIsSuccess) {
onVCardSaveSuccess(account);
} else {
onVCardSaveFailed(account);
}
}
});
}
});
}
use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class XabberAccountManager method createSyncList.
/**
* @param remoteList is list of settings from cloud
* @return list of settings for displaying in sync-dialog
*/
public List<XMPPAccountSettings> createSyncList(List<XMPPAccountSettings> remoteList) {
List<XMPPAccountSettings> resultList = new ArrayList<>();
// add remote accounts to list
for (XMPPAccountSettings remoteItem : remoteList) {
XMPPAccountSettings.SyncStatus status = XMPPAccountSettings.SyncStatus.remote;
// if account already exist
AccountJid accountJid = getExistingAccount(remoteItem.getJid());
if (accountJid != null) {
AccountItem localItem = AccountManager.getInstance().getAccount(accountJid);
if (localItem != null) {
if (remoteItem.getTimestamp() == localItem.getTimestamp())
status = XMPPAccountSettings.SyncStatus.localEqualsRemote;
else if (remoteItem.getTimestamp() > localItem.getTimestamp())
status = XMPPAccountSettings.SyncStatus.remoteNewer;
else {
status = XMPPAccountSettings.SyncStatus.localNewer;
remoteItem.setTimestamp(localItem.getTimestamp());
}
remoteItem.setSyncNotAllowed(localItem.isSyncNotAllowed());
}
remoteItem.setStatus(status);
remoteItem.setSynchronization(isAccountSynchronize(remoteItem.getJid()));
resultList.add(remoteItem);
} else if (!remoteItem.isDeleted()) {
remoteItem.setStatus(status);
remoteItem.setSynchronization(isAccountSynchronize(remoteItem.getJid()));
resultList.add(remoteItem);
}
}
// add local accounts to list
Collection<AccountItem> localAccounts = AccountManager.getInstance().getAllAccountItems();
for (AccountItem localAccount : localAccounts) {
String localJid = localAccount.getAccount().getFullJid().asBareJid().toString();
boolean exist = false;
for (XMPPAccountSettings remoteItem : remoteList) {
if (localJid.equals(remoteItem.getJid())) {
exist = true;
}
}
if (!exist) {
XMPPAccountSettings localItem = new XMPPAccountSettings(localJid, false, localAccount.getTimestamp());
localItem.setOrder(remoteList.size() + localAccount.getOrder());
localItem.setColor(ColorManager.getInstance().convertIndexToColorName(localAccount.getColorIndex()));
localItem.setStatus(XMPPAccountSettings.SyncStatus.local);
localItem.setSynchronization(isAccountSynchronize(localItem.getJid()));
localItem.setSyncNotAllowed(localAccount.isSyncNotAllowed());
resultList.add(localItem);
}
}
return resultList;
}
Aggregations