mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-30 20:52:21 -05:00
Fix OTR-Error messages
Send out OTR-Errors on unreadableMessageReceived() as well, not only on messageFromAnotherInstanceReceived
This commit is contained in:
parent
7eabdfd80f
commit
db74cb52c4
@ -202,20 +202,7 @@ public class OtrEngine extends OtrCryptoEngineImpl implements OtrEngineHost {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void messageFromAnotherInstanceReceived(SessionID session) {
|
public void messageFromAnotherInstanceReceived(SessionID session) {
|
||||||
try {
|
sendOtrErrorMessage(session, "Message from another OTR-instance received");
|
||||||
Jid jid = Jid.fromSessionID(session);
|
|
||||||
Conversation conversation = mXmppConnectionService.find(account, jid);
|
|
||||||
String id = conversation == null ? null : conversation.getLastReceivedOtrMessageId();
|
|
||||||
if (id != null) {
|
|
||||||
MessagePacket packet = mXmppConnectionService.getMessageGenerator().generateOtrError(jid,id);
|
|
||||||
packet.setFrom(account.getJid());
|
|
||||||
mXmppConnectionService.sendMessagePacket(account,packet);
|
|
||||||
Log.d(Config.LOGTAG,packet.toString());
|
|
||||||
Log.d(Config.LOGTAG,account.getJid().toBareJid().toString()+": unreadable OTR message in "+conversation.getName());
|
|
||||||
}
|
|
||||||
} catch (InvalidJidException e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -267,9 +254,28 @@ public class OtrEngine extends OtrCryptoEngineImpl implements OtrEngineHost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unreadableMessageReceived(SessionID arg0) throws OtrException {
|
public void unreadableMessageReceived(SessionID session) throws OtrException {
|
||||||
Log.d(Config.LOGTAG,"unreadable message received");
|
Log.d(Config.LOGTAG,"unreadable message received");
|
||||||
throw new OtrException(new Exception("unreadable message received"));
|
sendOtrErrorMessage(session, "You sent me an unreadable OTR-encrypted message");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendOtrErrorMessage(SessionID session, String errorText) {
|
||||||
|
try {
|
||||||
|
Jid jid = Jid.fromSessionID(session);
|
||||||
|
Conversation conversation = mXmppConnectionService.find(account, jid);
|
||||||
|
String id = conversation == null ? null : conversation.getLastReceivedOtrMessageId();
|
||||||
|
if (id != null) {
|
||||||
|
MessagePacket packet = mXmppConnectionService.getMessageGenerator()
|
||||||
|
.generateOtrError(jid, id, errorText);
|
||||||
|
packet.setFrom(account.getJid());
|
||||||
|
mXmppConnectionService.sendMessagePacket(account,packet);
|
||||||
|
Log.d(Config.LOGTAG,packet.toString());
|
||||||
|
Log.d(Config.LOGTAG,account.getJid().toBareJid().toString()
|
||||||
|
+": unreadable OTR message in "+conversation.getName());
|
||||||
|
}
|
||||||
|
} catch (InvalidJidException e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -172,7 +172,7 @@ public class MessageGenerator extends AbstractGenerator {
|
|||||||
return receivedPacket;
|
return receivedPacket;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessagePacket generateOtrError(Jid to, String id) {
|
public MessagePacket generateOtrError(Jid to, String id, String errorText) {
|
||||||
MessagePacket packet = new MessagePacket();
|
MessagePacket packet = new MessagePacket();
|
||||||
packet.setType(MessagePacket.TYPE_ERROR);
|
packet.setType(MessagePacket.TYPE_ERROR);
|
||||||
packet.setAttribute("id",id);
|
packet.setAttribute("id",id);
|
||||||
@ -181,7 +181,7 @@ public class MessageGenerator extends AbstractGenerator {
|
|||||||
error.setAttribute("code","406");
|
error.setAttribute("code","406");
|
||||||
error.setAttribute("type","modify");
|
error.setAttribute("type","modify");
|
||||||
error.addChild("not-acceptable","urn:ietf:params:xml:ns:xmpp-stanzas");
|
error.addChild("not-acceptable","urn:ietf:params:xml:ns:xmpp-stanzas");
|
||||||
error.addChild("text").setContent("unreadable OTR message received");
|
error.addChild("text").setContent("?OTR Error:" + errorText);
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user