use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class TimeManager method onPacket.
@Override
public void onPacket(ConnectionItem connection, final String bareAddress, Stanza packet) {
if (!(connection instanceof AccountItem))
return;
String account = ((AccountItem) connection).getAccount();
if (!(packet instanceof Time))
return;
Time time = (Time) packet;
if (time.getType() == Type.get) {
Time result = new Time();
result.setType(Type.result);
result.setPacketID(time.getPacketID());
result.setFrom(time.getTo());
result.setTo(time.getFrom());
Calendar calendar = Calendar.getInstance();
result.setTzo((calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / 60000);
result.setUtc(calendar.getTime());
try {
ConnectionManager.getInstance().sendStanza(account, result);
} catch (NetworkException e) {
}
}
}
use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class VCardManager method requestVCard.
private void requestVCard(final String account, final String srcUser) {
final String userBareJid = srcUser;
AccountItem accountItem = AccountManager.getInstance().getAccount(account);
ConnectionThread connectionThread = accountItem.getConnectionThread();
if (!accountItem.getFactualStatusMode().isOnline() || connectionThread == null) {
onVCardFailed(account, userBareJid);
return;
}
final org.jivesoftware.smackx.vcardtemp.VCardManager vCardManager = org.jivesoftware.smackx.vcardtemp.VCardManager.getInstanceFor(connectionThread.getXMPPConnection());
final Thread thread = new Thread("Get vCard user " + userBareJid + " for account " + account) {
@Override
public void run() {
VCard vCard = null;
vCardRequests.add(userBareJid);
try {
vCard = vCardManager.loadVCard(userBareJid);
} catch (SmackException.NoResponseException | SmackException.NotConnectedException e) {
LogManager.w(this, "Error getting vCard: " + e.getMessage());
} catch (XMPPException.XMPPErrorException e) {
LogManager.w(this, "XMPP error getting vCard: " + e.getMessage() + e.getXMPPError());
if (e.getXMPPError().getCondition() == XMPPError.Condition.item_not_found) {
vCard = new VCard();
}
} catch (ClassCastException e) {
// http://stackoverflow.com/questions/31498721/error-loading-vcard-information-using-smack-emptyresultiq-cannot-be-cast-to-or
LogManager.w(this, "ClassCastException: " + e.getMessage());
vCard = new VCard();
}
vCardRequests.remove(userBareJid);
final VCard finalVCard = vCard;
Application.getInstance().runOnUiThread(new Runnable() {
@Override
public void run() {
if (finalVCard == null) {
onVCardFailed(account, userBareJid);
} else {
onVCardReceived(account, userBareJid, finalVCard);
}
}
});
}
};
thread.start();
}
use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class MUCManager 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 || !(packet instanceof Message)) {
return;
}
Message message = (Message) packet;
if (message.getType() != Message.Type.normal && message.getType() != Message.Type.chat) {
return;
}
MUCUser mucUser = MUC.getMUCUserExtension(packet);
if (mucUser == null || mucUser.getInvite() == null) {
return;
}
RoomChat roomChat = getRoomChat(account, bareAddress);
if (roomChat == null || !roomChat.getState().inUse()) {
String inviter = mucUser.getInvite().getFrom();
if (inviter == null) {
inviter = bareAddress;
}
inviteProvider.add(new RoomInvite(account, bareAddress, inviter, mucUser.getInvite().getReason(), mucUser.getPassword()), true);
}
}
use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class ReceiptManager method onPacket.
@Override
public void onPacket(ConnectionItem connection, String bareAddress, Stanza packet) {
if (!(connection instanceof AccountItem))
return;
String account = ((AccountItem) connection).getAccount();
final String user = packet.getFrom();
if (user == null)
return;
if (!(packet instanceof Message))
return;
final Message message = (Message) packet;
if (message.getType() == Message.Type.error) {
final MessageItem messageItem = sent.remove(account, message.getPacketID());
if (messageItem != null && !messageItem.isError()) {
messageItem.markAsError();
Application.getInstance().runInBackground(new Runnable() {
@Override
public void run() {
if (messageItem.getId() != null)
MessageTable.getInstance().markAsError(messageItem.getId());
}
});
MessageManager.getInstance().onChatChanged(messageItem.getChat().getAccount(), messageItem.getChat().getUser(), false);
}
} else {
// TODO setDefaultAutoReceiptMode should be used
for (ExtensionElement packetExtension : message.getExtensions()) if (packetExtension instanceof DeliveryReceiptRequest) {
String id = message.getPacketID();
if (id == null)
continue;
Message receipt = new Message(user);
receipt.addExtension(new DeliveryReceipt(id));
// the key problem is Thread - smack does not keep it in auto reply
receipt.setThread(message.getThread());
try {
ConnectionManager.getInstance().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 RosterManager method getRoster.
@Nullable
private Roster getRoster(String account) {
final AccountItem accountItem = AccountManager.getInstance().getAccount(account);
if (accountItem == null) {
return null;
}
final ConnectionThread connectionThread = accountItem.getConnectionThread();
if (connectionThread == null) {
return null;
}
final AbstractXMPPConnection xmppConnection = connectionThread.getXMPPConnection();
if (xmppConnection == null) {
return null;
}
return Roster.getInstanceFor(xmppConnection);
}
Aggregations