use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class SSNManager method onFormReceived.
private void onFormReceived(AccountJid account, Jid from, String session, Feature feature) {
OtrMode otrMode = getOtrMode(account, session);
boolean cancel = false;
Collection<DisclosureValue> disclosureValues = feature.getDisclosureOptions();
DisclosureValue disclosureValue = DisclosureValue.never;
if (disclosureValues == null)
disclosureValue = null;
else if (!disclosureValues.contains(disclosureValue))
cancel = true;
Collection<SecurityValue> securityValues = feature.getSecurityOptions();
SecurityValue securityValue;
AccountItem accountItem = AccountManager.getInstance().getAccount(account);
if (accountItem != null && accountItem.getConnectionSettings().getTlsMode() == TLSMode.required) {
securityValue = SecurityValue.c2s;
} else {
securityValue = SecurityValue.none;
}
if (securityValues == null)
securityValue = null;
else if (!securityValues.contains(securityValue))
cancel = true;
Collection<LoggingValue> loggingValues = feature.getLoggingOptions();
LoggingValue loggingValue;
if (loggingValues == null)
loggingValue = null;
else {
loggingValue = otrMode.selectLoggingValue(loggingValues);
if (loggingValue == null)
cancel = true;
}
if (cancel) {
DataForm dataForm = Feature.createDataForm(DataForm.Type.submit);
if (feature.getAcceptValue() != null) {
Feature.addAcceptField(dataForm, false);
sessionStates.remove(account.toString(), session);
} else {
Feature.addRenegotiateField(dataForm, false);
}
sendFeature(account, from, session, new Feature(dataForm));
return;
}
DataForm dataForm = Feature.createDataForm(DataForm.Type.submit);
if (feature.getAcceptValue() != null)
Feature.addAcceptField(dataForm, true);
else
Feature.addRenegotiateField(dataForm, true);
if (disclosureValue != null)
Feature.addDisclosureField(dataForm, null, disclosureValue);
if (securityValue != null)
Feature.addSecurityField(dataForm, null, securityValue);
if (loggingValue != null) {
Feature.addLoggingField(dataForm, null, loggingValue);
}
sessionStates.put(account.toString(), session, SessionState.active);
sendFeature(account, from, session, new Feature(dataForm));
}
use of com.xabber.android.data.account.AccountItem 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 AccountJid account, final EntityBareJid room, boolean requested) {
final RoomChat roomChat;
final Resourcepart nickname;
final String password;
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);
AccountItem accountItem = AccountManager.getInstance().getAccount(account);
if (accountItem == null) {
return;
}
final MultiUserChat multiUserChat;
try {
multiUserChat = MultiUserChatManager.getInstanceFor(accountItem.getConnection()).getMultiUserChat(room);
} catch (IllegalStateException e) {
Application.getInstance().onError(R.string.NOT_CONNECTED);
return;
}
roomChat.setState(RoomState.joining);
roomChat.setMultiUserChat(multiUserChat);
roomChat.setRequested(requested);
Application.getInstance().runInBackgroundUserRequest(new Runnable() {
@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);
try {
RosterManager.onContactChanged(account, UserJid.from(room));
VCardManager.getInstance().request(account, room);
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
}
});
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);
}
try {
RosterManager.onContactChanged(account, UserJid.from(room));
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
}
});
return;
} 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);
try {
RosterManager.onContactChanged(account, UserJid.from(room));
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
}
});
}
});
}
use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class MUCManager method requestHostedRooms.
public static void requestHostedRooms(final AccountJid account, final DomainBareJid serviceName, final HostedRoomsListener listener) {
AccountItem accountItem = AccountManager.getInstance().getAccount(account);
if (accountItem == null) {
listener.onHostedRoomsReceived(null);
return;
}
final XMPPConnection xmppConnection = accountItem.getConnection();
if (!xmppConnection.isAuthenticated()) {
listener.onHostedRoomsReceived(null);
return;
}
Application.getInstance().runInBackgroundUserRequest(new Runnable() {
@Override
public void run() {
Collection<HostedRoom> hostedRooms = null;
try {
hostedRooms = MultiUserChatManager.getInstanceFor(xmppConnection).getHostedRooms(serviceName);
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException | MultiUserChatException.NotAMucServiceException e) {
LogManager.exception(this, e);
}
final Collection<HostedRoom> finalHostedRooms = hostedRooms;
Application.getInstance().runOnUiThread(new Runnable() {
@Override
public void run() {
listener.onHostedRoomsReceived(finalHostedRooms);
}
});
}
});
}
use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class MUCManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
if (!(connection instanceof AccountItem)) {
return;
}
AccountJid account = ((AccountItem) connection).getAccount();
Jid from = stanza.getFrom();
if (from == null || !(stanza instanceof Message)) {
return;
}
Message message = (Message) stanza;
if (message.getType() != Message.Type.normal && message.getType() != Message.Type.chat) {
return;
}
MUCUser mucUser = MUCUser.from(stanza);
if (mucUser == null || mucUser.getInvite() == null) {
return;
}
RoomChat roomChat = getRoomChat(account, from.asEntityBareJidIfPossible());
if (roomChat == null || !roomChat.getState().inUse()) {
UserJid inviter = null;
try {
inviter = UserJid.from(mucUser.getInvite().getFrom());
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
if (inviter == null) {
try {
inviter = UserJid.from(from);
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
}
try {
inviteProvider.add(new RoomInvite(account, UserJid.from(from), inviter, mucUser.getInvite().getReason(), mucUser.getPassword()), true);
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
}
}
use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class StanzaSender method getXmppTcpConnection.
@NonNull
private static XMPPTCPConnection getXmppTcpConnection(AccountJid account) throws NetworkException {
AccountItem accountItem = AccountManager.getInstance().getAccount(account);
if (accountItem == null) {
throw new NetworkException(R.string.NOT_CONNECTED);
}
XMPPTCPConnection returnConnection = accountItem.getConnection();
if (!returnConnection.isAuthenticated()) {
throw new NetworkException(R.string.NOT_CONNECTED);
}
return returnConnection;
}
Aggregations