fixed pgp on incoming carbon messages
This commit is contained in:
parent
657df84155
commit
2f2aa7aa21
|
@ -21,17 +21,15 @@ public class MessageParser {
|
||||||
this.mXmppConnectionService = service;
|
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("/");
|
String[] fromParts = packet.getFrom().split("/");
|
||||||
Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, fromParts[0],false);
|
Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, fromParts[0],false);
|
||||||
|
String pgpBody = getPgpBody(packet);
|
||||||
|
if (pgpBody!=null) {
|
||||||
return new Message(conversation, packet.getFrom(), pgpBody, Message.ENCRYPTION_PGP, Message.STATUS_RECIEVED);
|
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) {
|
public Message parseOtrChat(MessagePacket packet, Account account) {
|
||||||
|
@ -156,7 +154,12 @@ public class MessageParser {
|
||||||
}
|
}
|
||||||
String[] parts = fullJid.split("/");
|
String[] parts = fullJid.split("/");
|
||||||
Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, parts[0],false);
|
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) {
|
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);
|
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");
|
Element child = packet.findChild("x", "jabber:x:encrypted");
|
||||||
if (child==null) {
|
if (child==null) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -142,12 +142,7 @@ public class XmppConnectionService extends Service {
|
||||||
|
|
||||||
|
|
||||||
if ((packet.getType() == MessagePacket.TYPE_CHAT)) {
|
if ((packet.getType() == MessagePacket.TYPE_CHAT)) {
|
||||||
String pgpBody = mMessageParser.getPgpBody(packet);
|
if ((packet.getBody() != null)
|
||||||
if (pgpBody != null) {
|
|
||||||
message = mMessageParser.parsePgpChat(pgpBody, packet,
|
|
||||||
account);
|
|
||||||
message.markUnread();
|
|
||||||
} else if ((packet.getBody() != null)
|
|
||||||
&& (packet.getBody().startsWith("?OTR"))) {
|
&& (packet.getBody().startsWith("?OTR"))) {
|
||||||
message = mMessageParser.parseOtrChat(packet, account);
|
message = mMessageParser.parseOtrChat(packet, account);
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
|
@ -155,7 +150,7 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
} else if (packet.hasChild("body")) {
|
} else if (packet.hasChild("body")) {
|
||||||
message = mMessageParser
|
message = mMessageParser
|
||||||
.parsePlainTextChat(packet, account);
|
.parseChat(packet, account);
|
||||||
message.markUnread();
|
message.markUnread();
|
||||||
} else if (packet.hasChild("received")
|
} else if (packet.hasChild("received")
|
||||||
|| (packet.hasChild("sent"))) {
|
|| (packet.hasChild("sent"))) {
|
||||||
|
|
Loading…
Reference in a new issue