use of com.xabber.android.data.connection.ConnectionThread in project xabber-android by redsolution.
the class AttentionManager method onSettingsChanged.
public void onSettingsChanged() {
synchronized (enabledLock) {
for (String account : AccountManager.getInstance().getAccounts()) {
ConnectionThread connectionThread = AccountManager.getInstance().getAccount(account).getConnectionThread();
if (connectionThread == null)
continue;
XMPPConnection xmppConnection = connectionThread.getXMPPConnection();
if (xmppConnection == null)
continue;
ServiceDiscoveryManager manager = ServiceDiscoveryManager.getInstanceFor(xmppConnection);
if (manager == null)
continue;
boolean contains = false;
for (String feature : manager.getFeatures()) {
if (Attention.NAMESPACE.equals(feature)) {
contains = true;
}
}
if (SettingsManager.chatsAttention() == contains)
continue;
if (SettingsManager.chatsAttention())
manager.addFeature(Attention.NAMESPACE);
else
manager.removeFeature(Attention.NAMESPACE);
}
AccountManager.getInstance().resendPresence();
}
}
use of com.xabber.android.data.connection.ConnectionThread in project xabber-android by redsolution.
the class ClientStateManager method sendClientState.
protected static void sendClientState(PlainStreamElement element) {
AccountManager accountManager = AccountManager.getInstance();
for (String accountName : accountManager.getAccounts()) {
AccountItem account = accountManager.getAccount(accountName);
if (account == null) {
continue;
}
ConnectionThread connectionThread = account.getConnectionThread();
if (connectionThread == null) {
continue;
}
AbstractXMPPConnection xmppConnection = connectionThread.getXMPPConnection();
if (xmppConnection == null) {
continue;
}
if (xmppConnection.hasFeature("csi", ClientStateIndication.NAMESPACE))
try {
xmppConnection.send(element);
} catch (SmackException.NotConnectedException e) {
// not connected
}
}
}
use of com.xabber.android.data.connection.ConnectionThread in project xabber-android by redsolution.
the class VCardManager method saveVCard.
public void saveVCard(final String account, final VCard vCard) {
ConnectionThread connectionThread = AccountManager.getInstance().getAccount(account).getConnectionThread();
if (connectionThread == null) {
onVCardSaveFailed(account);
return;
}
final AbstractXMPPConnection xmppConnection = connectionThread.getXMPPConnection();
final org.jivesoftware.smackx.vcardtemp.VCardManager vCardManager = org.jivesoftware.smackx.vcardtemp.VCardManager.getInstanceFor(xmppConnection);
final Thread thread = new Thread("Save vCard for account " + account) {
@Override
public void run() {
boolean isSuccess = true;
xmppConnection.setPacketReplyTimeout(120000);
vCardSaveRequests.add(account);
try {
vCardManager.saveVCard(vCard);
String avatarHash = vCard.getAvatarHash();
if (avatarHash == null) {
avatarHash = AvatarManager.EMPTY_HASH;
}
PresenceManager.getInstance().sendVCardUpdatePresence(account, avatarHash);
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | NetworkException 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);
}
}
});
}
};
thread.start();
}
use of com.xabber.android.data.connection.ConnectionThread 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.connection.ConnectionThread in project xabber-android by redsolution.
the class MUCManager method joinRoom.
/**
* Requests to join to the room.
*
* @param requested Whether user request to join the room.
*/
public void joinRoom(final String account, final String room, boolean requested) {
final XMPPConnection xmppConnection;
final RoomChat roomChat;
final String nickname;
final String password;
final Thread thread;
roomChat = getRoomChat(account, room);
if (roomChat == null) {
Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
return;
}
RoomState state = roomChat.getState();
if (state == RoomState.available || state == RoomState.occupation) {
Application.getInstance().onError(R.string.ALREADY_JOINED);
return;
}
if (state == RoomState.creating || state == RoomState.joining) {
Application.getInstance().onError(R.string.ALREADY_IN_PROGRESS);
return;
}
nickname = roomChat.getNickname();
password = roomChat.getPassword();
requestToWriteRoom(account, room, nickname, password, true);
ConnectionThread connectionThread = AccountManager.getInstance().getAccount(account).getConnectionThread();
if (connectionThread == null) {
Application.getInstance().onError(R.string.NOT_CONNECTED);
return;
}
xmppConnection = connectionThread.getXMPPConnection();
if (xmppConnection == null) {
Application.getInstance().onError(R.string.NOT_CONNECTED);
return;
}
final MultiUserChat multiUserChat;
try {
multiUserChat = MultiUserChatManager.getInstanceFor(xmppConnection).getMultiUserChat(room);
} catch (IllegalStateException e) {
Application.getInstance().onError(R.string.NOT_CONNECTED);
return;
}
roomChat.setState(RoomState.joining);
roomChat.setMultiUserChat(multiUserChat);
roomChat.setRequested(requested);
thread = new Thread("Join to room " + room + " from " + account) {
@Override
public void run() {
try {
if (roomChat.getMultiUserChat() != multiUserChat) {
return;
}
multiUserChat.join(nickname, password);
Application.getInstance().runOnUiThread(new Runnable() {
@Override
public void run() {
if (roomChat.getMultiUserChat() != multiUserChat) {
return;
}
if (roomChat.getState() == RoomState.joining) {
roomChat.setState(RoomState.occupation);
}
removeAuthorizationError(account, room);
RosterManager.getInstance().onContactChanged(account, room);
}
});
return;
} catch (final XMPPException.XMPPErrorException e) {
Application.getInstance().runOnUiThread(new Runnable() {
@Override
public void run() {
if (roomChat.getMultiUserChat() != multiUserChat) {
return;
}
roomChat.setState(RoomState.error);
addAuthorizationError(account, room);
XMPPError xmppError = e.getXMPPError();
if (xmppError != null && xmppError.getCondition() == XMPPError.Condition.conflict) {
Application.getInstance().onError(R.string.NICK_ALREADY_USED);
} else if (xmppError != null && xmppError.getCondition() == XMPPError.Condition.not_authorized) {
Application.getInstance().onError(R.string.AUTHENTICATION_FAILED);
} else {
Application.getInstance().onError(R.string.NOT_CONNECTED);
}
RosterManager.getInstance().onContactChanged(account, room);
}
});
return;
} catch (IllegalStateException e) {
} catch (Exception e) {
LogManager.exception(this, e);
}
Application.getInstance().runOnUiThread(new Runnable() {
@Override
public void run() {
if (roomChat.getMultiUserChat() != multiUserChat) {
return;
}
roomChat.setState(RoomState.waiting);
Application.getInstance().onError(R.string.NOT_CONNECTED);
RosterManager.getInstance().onContactChanged(account, room);
}
});
}
};
thread.setDaemon(true);
thread.start();
}
Aggregations