Properly track message sender
Previously, the sender was assumed to be the conversation counterpart. This broke carboned own-device messages. We now track the sender properly, and also set the status (sent by one of the own devices vs received from the counterpart) accordingly.
This commit is contained in:
parent
18c1e15d00
commit
ec6870307e
|
@ -856,14 +856,14 @@ public class AxolotlService {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public XmppAxolotlMessage encrypt(Message message ){
|
public XmppAxolotlMessage encrypt(Message message ){
|
||||||
final XmppAxolotlMessage axolotlMessage = new XmppAxolotlMessage(message.getContact(),
|
final XmppAxolotlMessage axolotlMessage = new XmppAxolotlMessage(message.getContact().getJid().toBareJid(),
|
||||||
ownDeviceId, message.getBody());
|
ownDeviceId, message.getBody());
|
||||||
|
|
||||||
if(findSessionsforContact(axolotlMessage.getContact()).isEmpty()) {
|
if(findSessionsforContact(message.getContact()).isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Log.d(Config.LOGTAG, "Building axolotl foreign headers...");
|
Log.d(Config.LOGTAG, "Building axolotl foreign headers...");
|
||||||
for (XmppAxolotlSession session : findSessionsforContact(axolotlMessage.getContact())) {
|
for (XmppAxolotlSession session : findSessionsforContact(message.getContact())) {
|
||||||
Log.d(Config.LOGTAG, session.remoteAddress.toString());
|
Log.d(Config.LOGTAG, session.remoteAddress.toString());
|
||||||
//if(!session.isTrusted()) {
|
//if(!session.isTrusted()) {
|
||||||
// TODO: handle this properly
|
// TODO: handle this properly
|
||||||
|
@ -910,7 +910,7 @@ public class AxolotlService {
|
||||||
|
|
||||||
public XmppAxolotlMessage.XmppAxolotlPlaintextMessage processReceiving(XmppAxolotlMessage message) {
|
public XmppAxolotlMessage.XmppAxolotlPlaintextMessage processReceiving(XmppAxolotlMessage message) {
|
||||||
XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage = null;
|
XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage = null;
|
||||||
AxolotlAddress senderAddress = new AxolotlAddress(message.getContact().getJid().toBareJid().toString(),
|
AxolotlAddress senderAddress = new AxolotlAddress(message.getFrom().toString(),
|
||||||
message.getSenderDeviceId());
|
message.getSenderDeviceId());
|
||||||
|
|
||||||
XmppAxolotlSession session = sessions.get(senderAddress);
|
XmppAxolotlSession session = sessions.get(senderAddress);
|
||||||
|
|
|
@ -19,13 +19,14 @@ import javax.crypto.spec.SecretKeySpec;
|
||||||
|
|
||||||
import eu.siacs.conversations.entities.Contact;
|
import eu.siacs.conversations.entities.Contact;
|
||||||
import eu.siacs.conversations.xml.Element;
|
import eu.siacs.conversations.xml.Element;
|
||||||
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
||||||
|
|
||||||
public class XmppAxolotlMessage {
|
public class XmppAxolotlMessage {
|
||||||
private byte[] innerKey;
|
private byte[] innerKey;
|
||||||
private byte[] ciphertext;
|
private byte[] ciphertext;
|
||||||
private byte[] iv;
|
private byte[] iv;
|
||||||
private final Set<XmppAxolotlMessageHeader> headers;
|
private final Set<XmppAxolotlMessageHeader> headers;
|
||||||
private final Contact contact;
|
private final Jid from;
|
||||||
private final int sourceDeviceId;
|
private final int sourceDeviceId;
|
||||||
|
|
||||||
public static class XmppAxolotlMessageHeader {
|
public static class XmppAxolotlMessageHeader {
|
||||||
|
@ -82,8 +83,8 @@ public class XmppAxolotlMessage {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public XmppAxolotlMessage(Contact contact, Element axolotlMessage) {
|
public XmppAxolotlMessage(Jid from, Element axolotlMessage) {
|
||||||
this.contact = contact;
|
this.from = from;
|
||||||
this.sourceDeviceId = Integer.parseInt(axolotlMessage.getAttribute("id"));
|
this.sourceDeviceId = Integer.parseInt(axolotlMessage.getAttribute("id"));
|
||||||
this.headers = new HashSet<>();
|
this.headers = new HashSet<>();
|
||||||
for(Element child:axolotlMessage.getChildren()) {
|
for(Element child:axolotlMessage.getChildren()) {
|
||||||
|
@ -101,8 +102,8 @@ public class XmppAxolotlMessage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public XmppAxolotlMessage(Contact contact, int sourceDeviceId, String plaintext) {
|
public XmppAxolotlMessage(Jid from, int sourceDeviceId, String plaintext) {
|
||||||
this.contact = contact;
|
this.from = from;
|
||||||
this.sourceDeviceId = sourceDeviceId;
|
this.sourceDeviceId = sourceDeviceId;
|
||||||
this.headers = new HashSet<>();
|
this.headers = new HashSet<>();
|
||||||
this.encrypt(plaintext);
|
this.encrypt(plaintext);
|
||||||
|
@ -124,8 +125,8 @@ public class XmppAxolotlMessage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Contact getContact() {
|
public Jid getFrom() {
|
||||||
return this.contact;
|
return this.from;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSenderDeviceId() {
|
public int getSenderDeviceId() {
|
||||||
|
|
|
@ -99,13 +99,13 @@ public class MessageParser extends AbstractParser implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Message parseAxolotlChat(Element axolotlMessage, Jid from, String id, Conversation conversation) {
|
private Message parseAxolotlChat(Element axolotlMessage, Jid from, String id, Conversation conversation, int status) {
|
||||||
Message finishedMessage = null;
|
Message finishedMessage = null;
|
||||||
AxolotlService service = conversation.getAccount().getAxolotlService();
|
AxolotlService service = conversation.getAccount().getAxolotlService();
|
||||||
XmppAxolotlMessage xmppAxolotlMessage = new XmppAxolotlMessage(conversation.getContact(), axolotlMessage);
|
XmppAxolotlMessage xmppAxolotlMessage = new XmppAxolotlMessage(from.toBareJid(), axolotlMessage);
|
||||||
XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage = service.processReceiving(xmppAxolotlMessage);
|
XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage = service.processReceiving(xmppAxolotlMessage);
|
||||||
if(plaintextMessage != null) {
|
if(plaintextMessage != null) {
|
||||||
finishedMessage = new Message(conversation, plaintextMessage.getPlaintext(), Message.ENCRYPTION_AXOLOTL, Message.STATUS_RECEIVED);
|
finishedMessage = new Message(conversation, plaintextMessage.getPlaintext(), Message.ENCRYPTION_AXOLOTL, status);
|
||||||
finishedMessage.setAxolotlSession(plaintextMessage.getSession());
|
finishedMessage.setAxolotlSession(plaintextMessage.getSession());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,7 +322,7 @@ public class MessageParser extends AbstractParser implements
|
||||||
} else if (pgpEncrypted != null) {
|
} else if (pgpEncrypted != null) {
|
||||||
message = new Message(conversation, pgpEncrypted, Message.ENCRYPTION_PGP, status);
|
message = new Message(conversation, pgpEncrypted, Message.ENCRYPTION_PGP, status);
|
||||||
} else if (axolotlEncrypted != null) {
|
} else if (axolotlEncrypted != null) {
|
||||||
message = parseAxolotlChat(axolotlEncrypted, from, remoteMsgId, conversation);
|
message = parseAxolotlChat(axolotlEncrypted, from, remoteMsgId, conversation, status);
|
||||||
if (message == null) {
|
if (message == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue