use of net.java.otr4j.OtrException in project xabber-android by redsolution.
the class RegularChat method onPacket.
@Override
protected boolean onPacket(UserJid bareAddress, Stanza packet, boolean isCarbons) {
if (!super.onPacket(bareAddress, packet, isCarbons))
return false;
final Resourcepart resource = packet.getFrom().getResourceOrNull();
if (packet instanceof Presence) {
final Presence presence = (Presence) packet;
if (this.resource != null && presence.getType() == Presence.Type.unavailable && resource != null && this.resource.equals(resource)) {
this.resource = null;
}
// if (presence.getType() == Presence.Type.unavailable) {
// OTRManager.getInstance().onContactUnAvailable(account, user);
// }
} else if (packet instanceof Message) {
final Message message = (Message) packet;
if (message.getType() == Message.Type.error)
return true;
MUCUser mucUser = MUCUser.from(message);
if (mucUser != null && mucUser.getInvite() != null)
return true;
String text = message.getBody();
if (text == null)
return true;
String thread = message.getThread();
updateThreadId(thread);
if (resource != null && !resource.equals(Resourcepart.EMPTY)) {
this.resource = resource;
}
boolean encrypted = OTRManager.getInstance().isEncrypted(text);
if (!isCarbons) {
try {
text = OTRManager.getInstance().transformReceiving(account, user, text);
} catch (OtrException e) {
if (e.getCause() instanceof OTRUnencryptedException) {
text = ((OTRUnencryptedException) e.getCause()).getText();
encrypted = false;
} else {
LogManager.exception(this, e);
// Invalid message received.
return true;
}
}
}
// System message received.
if (text == null || text.trim().equals(""))
return true;
createAndSaveNewMessage(resource, text, null, getDelayStamp(message), true, true, encrypted, isOfflineMessage(account.getFullJid().getDomain(), packet), packet.getStanzaId());
EventBus.getDefault().post(new NewIncomingMessageEvent(account, user));
}
return true;
}
use of net.java.otr4j.OtrException in project xabber-android by redsolution.
the class OTRManager method onContactUnAvailable.
public void onContactUnAvailable(String account, String user) {
Session session = sessions.get(account, user);
if (session == null) {
return;
}
if (session.getSessionStatus() == SessionStatus.ENCRYPTED) {
try {
LogManager.i(this, "onContactUnAvailable. Refresh session for " + user);
session.refreshSession();
} catch (OtrException e) {
LogManager.exception(this, e);
}
}
}
use of net.java.otr4j.OtrException in project xabber-android by redsolution.
the class OTRManager method initSmp.
/**
* Initiate request using SM protocol.
*/
public void initSmp(String account, String user, String question, String secret) throws NetworkException {
LogManager.i(this, "initializing smp... " + user);
removeSMRequest(account, user);
addSMProgress(account, user);
try {
getOrCreateSession(account, user).initSmp(question, secret);
} catch (OtrException e) {
throw new NetworkException(R.string.OTR_ERROR, e);
}
}
use of net.java.otr4j.OtrException in project xabber-android by redsolution.
the class OTRManager method startSession.
public void startSession(String account, String user) throws NetworkException {
LogManager.i(this, "Starting session for " + user);
try {
getOrCreateSession(account, user).startSession();
} catch (OtrException e) {
throw new NetworkException(R.string.OTR_ERROR, e);
}
LogManager.i(this, "Started session for " + user);
}
use of net.java.otr4j.OtrException in project xabber-android by redsolution.
the class OTRManager method respondSmp.
/**
* Respond using SM protocol.
*/
public void respondSmp(String account, String user, String question, String secret) throws NetworkException {
LogManager.i(this, "responding smp... " + user);
removeSMRequest(account, user);
addSMProgress(account, user);
try {
getOrCreateSession(account, user).respondSmp(question, secret);
} catch (OtrException e) {
throw new NetworkException(R.string.OTR_ERROR, e);
}
}
Aggregations