use of net.java.otr4j.session.SessionID in project xabber-android by redsolution.
the class OTRManager method getOrCreateSession.
private Session getOrCreateSession(String account, String user) {
Session session = sessions.get(account, user);
if (session != null) {
LogManager.i(this, "Found session with id " + session.getSessionID() + " with status " + session.getSessionStatus() + " for user " + user);
return session;
}
LogManager.i(this, "Creating new session for " + user);
AccountItem accountItem = AccountManager.getInstance().getAccount(account);
session = new Session(new SessionID(account, user, accountItem == null ? "" : accountItem.getConnectionSettings().getProtocol().toString()), this);
session.addOtrEngineListener(this);
sessions.put(account, user, session);
return session;
}
use of net.java.otr4j.session.SessionID in project Conversations by siacs.
the class XmppConnectionService method onOtrSessionEstablished.
public void onOtrSessionEstablished(Conversation conversation) {
final Account account = conversation.getAccount();
final Session otrSession = conversation.getOtrSession();
Log.d(Config.LOGTAG, account.getJid().toBareJid() + " otr session established with " + conversation.getJid() + "/" + otrSession.getSessionID().getUserID());
conversation.findUnsentMessagesWithEncryption(Message.ENCRYPTION_OTR, new Conversation.OnMessageFound() {
@Override
public void onMessageFound(Message message) {
SessionID id = otrSession.getSessionID();
try {
message.setCounterpart(Jid.fromString(id.getAccountID() + "/" + id.getUserID()));
} catch (InvalidJidException e) {
return;
}
if (message.needsUploading()) {
mJingleConnectionManager.createNewConnection(message);
} else {
MessagePacket outPacket = mMessageGenerator.generateOtrChat(message);
if (outPacket != null) {
mMessageGenerator.addDelay(outPacket, message.getTimeSent());
message.setStatus(Message.STATUS_SEND);
databaseBackend.updateMessage(message);
sendMessagePacket(account, outPacket);
}
}
updateConversationUi();
}
});
}
use of net.java.otr4j.session.SessionID in project Conversations by siacs.
the class Conversation method startOtrSession.
public SessionImpl startOtrSession(String presence, boolean sendStart) {
if (this.otrSession != null) {
return this.otrSession;
} else {
final SessionID sessionId = new SessionID(this.getJid().toBareJid().toString(), presence, "xmpp");
this.otrSession = new SessionImpl(sessionId, getAccount().getOtrService());
try {
if (sendStart) {
this.otrSession.startSession();
return this.otrSession;
}
return this.otrSession;
} catch (OtrException e) {
return null;
}
}
}
use of net.java.otr4j.session.SessionID in project Conversations by siacs.
the class XmppActivity method selectPresence.
public void selectPresence(final Conversation conversation, final OnPresenceSelected listener) {
final Contact contact = conversation.getContact();
if (conversation.hasValidOtrSession()) {
SessionID id = conversation.getOtrSession().getSessionID();
Jid jid;
try {
jid = Jid.fromString(id.getAccountID() + "/" + id.getUserID());
} catch (InvalidJidException e) {
jid = null;
}
conversation.setNextCounterpart(jid);
listener.onPresenceSelected();
} else if (!contact.showInRoster()) {
showAddToRosterDialog(conversation);
} else {
final Presences presences = contact.getPresences();
if (presences.size() == 0) {
if (!contact.getOption(Contact.Options.TO) && !contact.getOption(Contact.Options.ASKING) && contact.getAccount().getStatus() == Account.State.ONLINE) {
showAskForPresenceDialog(contact);
} else if (!contact.getOption(Contact.Options.TO) || !contact.getOption(Contact.Options.FROM)) {
warnMutalPresenceSubscription(conversation, listener);
} else {
conversation.setNextCounterpart(null);
listener.onPresenceSelected();
}
} else if (presences.size() == 1) {
String presence = presences.toResourceArray()[0];
try {
conversation.setNextCounterpart(Jid.fromParts(contact.getJid().getLocalpart(), contact.getJid().getDomainpart(), presence));
} catch (InvalidJidException e) {
conversation.setNextCounterpart(null);
}
listener.onPresenceSelected();
} else {
showPresenceSelectionDialog(presences, conversation, listener);
}
}
}
Aggregations