From 2f2aa7aa21ef1dc9e465776991bac1c0c1899c3a Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Wed, 4 Jun 2014 11:55:38 +0200 Subject: fixed pgp on incoming carbon messages --- .../siacs/conversations/parser/MessageParser.java | 27 ++++++++++++---------- .../services/XmppConnectionService.java | 9 ++------ 2 files changed, 17 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/eu/siacs/conversations/parser/MessageParser.java b/src/eu/siacs/conversations/parser/MessageParser.java index 2ccbe05c..3b1bfb06 100644 --- a/src/eu/siacs/conversations/parser/MessageParser.java +++ b/src/eu/siacs/conversations/parser/MessageParser.java @@ -21,19 +21,17 @@ public class MessageParser { this.mXmppConnectionService = service; } - public Message parsePlainTextChat(MessagePacket packet, Account account) { + public Message parseChat(MessagePacket packet, Account account) { String[] fromParts = packet.getFrom().split("/"); Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, fromParts[0],false); - String body = packet.getBody(); - return new Message(conversation, packet.getFrom(), body, Message.ENCRYPTION_NONE, Message.STATUS_RECIEVED); - } - - public Message parsePgpChat(String pgpBody, MessagePacket packet, Account account) { - String[] fromParts = packet.getFrom().split("/"); - Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, fromParts[0],false); - return new Message(conversation, packet.getFrom(), pgpBody, Message.ENCRYPTION_PGP, Message.STATUS_RECIEVED); + String pgpBody = getPgpBody(packet); + if (pgpBody!=null) { + return new Message(conversation, packet.getFrom(), pgpBody, Message.ENCRYPTION_PGP, Message.STATUS_RECIEVED); + } else { + return new Message(conversation, packet.getFrom(), packet.getBody(), Message.ENCRYPTION_NONE, Message.STATUS_RECIEVED); + } } - + public Message parseOtrChat(MessagePacket packet, Account account) { boolean properlyAddressed = (packet.getTo().split("/").length == 2) || (account.countPresences() == 1); String[] fromParts = packet.getFrom().split("/"); @@ -156,7 +154,12 @@ public class MessageParser { } String[] parts = fullJid.split("/"); Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, parts[0],false); - return new Message(conversation,fullJid, message.findChild("body").getContent(), Message.ENCRYPTION_NONE,status); + String pgpBody = getPgpBody(packet); + if (pgpBody!=null) { + return new Message(conversation,fullJid, pgpBody,Message.ENCRYPTION_PGP,status); + } else { + return new Message(conversation,fullJid,packet.getBody(),Message.ENCRYPTION_NONE,status); + } } public void parseError(MessagePacket packet, Account account) { @@ -164,7 +167,7 @@ public class MessageParser { mXmppConnectionService.markMessage(account, fromParts[0], packet.getId(), Message.STATUS_SEND_FAILED); } - public String getPgpBody(MessagePacket packet) { + private String getPgpBody(MessagePacket packet) { Element child = packet.findChild("x", "jabber:x:encrypted"); if (child==null) { return null; diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 6cb5e6b0..7eb69138 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -142,12 +142,7 @@ public class XmppConnectionService extends Service { if ((packet.getType() == MessagePacket.TYPE_CHAT)) { - String pgpBody = mMessageParser.getPgpBody(packet); - if (pgpBody != null) { - message = mMessageParser.parsePgpChat(pgpBody, packet, - account); - message.markUnread(); - } else if ((packet.getBody() != null) + if ((packet.getBody() != null) && (packet.getBody().startsWith("?OTR"))) { message = mMessageParser.parseOtrChat(packet, account); if (message != null) { @@ -155,7 +150,7 @@ public class XmppConnectionService extends Service { } } else if (packet.hasChild("body")) { message = mMessageParser - .parsePlainTextChat(packet, account); + .parseChat(packet, account); message.markUnread(); } else if (packet.hasChild("received") || (packet.hasChild("sent"))) { -- cgit v1.2.3