From c2bf9d0413ab5c7008d2d8ea2eda18772aba08f5 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 1 Mar 2023 14:52:11 +0100 Subject: [PATCH] store senderIdentity in message --- .../1.json | 22 ++--- .../xmpp/MessageTransformationTest.java | 96 +++++++++++++------ .../android/database/dao/MessageDao.java | 6 +- .../entity/AxolotlIdentityEntity.java | 5 +- .../database/entity/MessageEntity.java | 4 + .../transformer/MessageTransformation.java | 11 +++ .../transformer/TransformationFactory.java | 10 +- .../android/transformer/Transformer.java | 3 +- .../conversations/android/xmpp/Managers.java | 2 + .../{tls => xmpp/manager}/TrustManager.java | 16 ++-- 10 files changed, 120 insertions(+), 55 deletions(-) rename app/src/main/java/im/conversations/android/{tls => xmpp/manager}/TrustManager.java (56%) diff --git a/app/schemas/im.conversations.android.database.ConversationsDatabase/1.json b/app/schemas/im.conversations.android.database.ConversationsDatabase/1.json index dc9e8b7a0..b298e7b0d 100644 --- a/app/schemas/im.conversations.android.database.ConversationsDatabase/1.json +++ b/app/schemas/im.conversations.android.database.ConversationsDatabase/1.json @@ -2,7 +2,7 @@ "formatVersion": 1, "database": { "version": 1, - "identityHash": "9d2672ebdefc9df52add6eebf635031f", + "identityHash": "5152f8eab684376f6f4076cf392e22d7", "entities": [ { "tableName": "account", @@ -482,16 +482,6 @@ ], "orders": [], "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_axolotl_identity_accountId_address_identityKey` ON `${TABLE_NAME}` (`accountId`, `address`, `identityKey`)" - }, - { - "name": "index_axolotl_identity_accountId_identityKey", - "unique": false, - "columnNames": [ - "accountId", - "identityKey" - ], - "orders": [], - "createSql": "CREATE INDEX IF NOT EXISTS `index_axolotl_identity_accountId_identityKey` ON `${TABLE_NAME}` (`accountId`, `identityKey`)" } ], "foreignKeys": [ @@ -1516,7 +1506,7 @@ }, { "tableName": "message", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `chatId` INTEGER NOT NULL, `receivedAt` INTEGER, `sentAt` INTEGER, `outgoing` INTEGER NOT NULL, `toBare` TEXT, `toResource` TEXT, `fromBare` TEXT, `fromResource` TEXT, `occupantId` TEXT, `messageId` TEXT, `stanzaId` TEXT, `stanzaIdVerified` INTEGER NOT NULL, `latestVersion` INTEGER, `acknowledged` INTEGER NOT NULL, `inReplyToMessageId` TEXT, `inReplyToStanzaId` TEXT, `inReplyToMessageEntityId` INTEGER, FOREIGN KEY(`chatId`) REFERENCES `chat`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`latestVersion`) REFERENCES `message_version`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`inReplyToMessageEntityId`) REFERENCES `message`(`id`) ON UPDATE NO ACTION ON DELETE SET NULL )", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `chatId` INTEGER NOT NULL, `receivedAt` INTEGER, `sentAt` INTEGER, `outgoing` INTEGER NOT NULL, `toBare` TEXT, `toResource` TEXT, `fromBare` TEXT, `fromResource` TEXT, `occupantId` TEXT, `senderIdentity` TEXT, `messageId` TEXT, `stanzaId` TEXT, `stanzaIdVerified` INTEGER NOT NULL, `latestVersion` INTEGER, `acknowledged` INTEGER NOT NULL, `inReplyToMessageId` TEXT, `inReplyToStanzaId` TEXT, `inReplyToMessageEntityId` INTEGER, FOREIGN KEY(`chatId`) REFERENCES `chat`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`latestVersion`) REFERENCES `message_version`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`inReplyToMessageEntityId`) REFERENCES `message`(`id`) ON UPDATE NO ACTION ON DELETE SET NULL )", "fields": [ { "fieldPath": "id", @@ -1578,6 +1568,12 @@ "affinity": "TEXT", "notNull": false }, + { + "fieldPath": "senderIdentity", + "columnName": "senderIdentity", + "affinity": "TEXT", + "notNull": false + }, { "fieldPath": "messageId", "columnName": "messageId", @@ -2380,7 +2376,7 @@ "views": [], "setupQueries": [ "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", - "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '9d2672ebdefc9df52add6eebf635031f')" + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '5152f8eab684376f6f4076cf392e22d7')" ] } } \ No newline at end of file diff --git a/app/src/androidTest/java/im/conversations/android/xmpp/MessageTransformationTest.java b/app/src/androidTest/java/im/conversations/android/xmpp/MessageTransformationTest.java index fb1da0a6b..11a435e41 100644 --- a/app/src/androidTest/java/im/conversations/android/xmpp/MessageTransformationTest.java +++ b/app/src/androidTest/java/im/conversations/android/xmpp/MessageTransformationTest.java @@ -70,7 +70,8 @@ public class MessageTransformationTest { final var reaction = reactions.addExtension(new Reaction()); reaction.setContent("Y"); this.transformer.transform( - MessageTransformation.of(reactionMessage, Instant.now(), REMOTE, "stanza-b", null)); + MessageTransformation.of( + reactionMessage, Instant.now(), REMOTE, "stanza-b", null, null)); final var originalMessage = new Message(); originalMessage.setId("1"); originalMessage.setTo(REMOTE); @@ -78,7 +79,8 @@ public class MessageTransformationTest { final var body = originalMessage.addExtension(new Body()); body.setContent(GREETING); this.transformer.transform( - MessageTransformation.of(originalMessage, Instant.now(), REMOTE, "stanza-a", null)); + MessageTransformation.of( + originalMessage, Instant.now(), REMOTE, "stanza-a", null, null)); final var messages = database.messageDao().getMessages(1L); Assert.assertEquals(1, messages.size()); @@ -98,21 +100,22 @@ public class MessageTransformationTest { message.addExtension(new Body("Please give me a thumbs up")); message.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-a"))); this.transformer.transform( - MessageTransformation.of(message, Instant.now(), REMOTE, "stanza-a", "id-user-a")); + MessageTransformation.of( + message, Instant.now(), REMOTE, "stanza-a", null, "id-user-a")); final var reactionA = new Message(Message.Type.GROUPCHAT); reactionA.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-b"))); reactionA.addExtension(Reactions.to("stanza-a")).addExtension(new Reaction("Y")); this.transformer.transform( MessageTransformation.of( - reactionA, Instant.now(), REMOTE, "stanza-b", "id-user-b")); + reactionA, Instant.now(), REMOTE, "stanza-b", null, "id-user-b")); final var reactionB = new Message(Message.Type.GROUPCHAT); reactionB.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-c"))); reactionB.addExtension(Reactions.to("stanza-a")).addExtension(new Reaction("Y")); this.transformer.transform( MessageTransformation.of( - reactionB, Instant.now(), REMOTE, "stanza-c", "id-user-c")); + reactionB, Instant.now(), REMOTE, "stanza-c", null, "id-user-c")); final var reactionC = new Message(Message.Type.GROUPCHAT); reactionC.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-d"))); @@ -121,7 +124,7 @@ public class MessageTransformationTest { reactions.addExtension(new Reaction("Z")); this.transformer.transform( MessageTransformation.of( - reactionC, Instant.now(), REMOTE, "stanza-d", "id-user-d")); + reactionC, Instant.now(), REMOTE, "stanza-d", null, "id-user-d")); final var messages = database.messageDao().getMessages(1L); Assert.assertEquals(1, messages.size()); @@ -148,7 +151,7 @@ public class MessageTransformationTest { this.transformer.transform( MessageTransformation.of( - messageCorrection, Instant.now(), REMOTE, "stanza-a", null)); + messageCorrection, Instant.now(), REMOTE, "stanza-a", null, null)); // the correction should not show up as a message Assert.assertEquals(0, database.messageDao().getMessages(1L).size()); @@ -160,7 +163,8 @@ public class MessageTransformationTest { messageWithTypo.addExtension(new Body()).setContent("Hii example!"); this.transformer.transform( - MessageTransformation.of(messageWithTypo, Instant.now(), REMOTE, "stanza-b", null)); + MessageTransformation.of( + messageWithTypo, Instant.now(), REMOTE, "stanza-b", null, null)); final var messages = database.messageDao().getMessages(1L); @@ -182,7 +186,8 @@ public class MessageTransformationTest { messageWithTypo.addExtension(new Body()).setContent("Hii example!"); this.transformer.transform( - MessageTransformation.of(messageWithTypo, Instant.now(), REMOTE, "stanza-a", null)); + MessageTransformation.of( + messageWithTypo, Instant.now(), REMOTE, "stanza-a", null, null)); Assert.assertEquals(1, database.messageDao().getMessages(1L).size()); @@ -195,7 +200,7 @@ public class MessageTransformationTest { this.transformer.transform( MessageTransformation.of( - messageCorrection, Instant.now(), REMOTE, "stanza-b", null)); + messageCorrection, Instant.now(), REMOTE, "stanza-b", null, null)); final var messages = database.messageDao().getMessages(1L); @@ -214,21 +219,22 @@ public class MessageTransformationTest { message.addExtension(new Body("Please give me a thumbs up")); message.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-a"))); this.transformer.transform( - MessageTransformation.of(message, Instant.now(), REMOTE, "stanza-a", "id-user-a")); + MessageTransformation.of( + message, Instant.now(), REMOTE, "stanza-a", null, "id-user-a")); final var reactionA = new Message(Message.Type.GROUPCHAT); reactionA.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-b"))); reactionA.addExtension(Reactions.to("stanza-a")).addExtension(new Reaction("N")); this.transformer.transform( MessageTransformation.of( - reactionA, Instant.now(), REMOTE, "stanza-b", "id-user-b")); + reactionA, Instant.now(), REMOTE, "stanza-b", null, "id-user-b")); final var reactionB = new Message(Message.Type.GROUPCHAT); reactionB.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-b"))); reactionB.addExtension(Reactions.to("stanza-a")).addExtension(new Reaction("Y")); this.transformer.transform( MessageTransformation.of( - reactionB, Instant.now(), REMOTE, "stanza-c", "id-user-b")); + reactionB, Instant.now(), REMOTE, "stanza-c", null, "id-user-b")); final var messages = database.messageDao().getMessages(1L); Assert.assertEquals(1, messages.size()); @@ -255,6 +261,7 @@ public class MessageTransformationTest { Instant.ofEpochMilli(2000), REMOTE, "irrelevant-stanza-id1", + null, "id-user-a")); // second correction @@ -269,6 +276,7 @@ public class MessageTransformationTest { Instant.ofEpochMilli(3000), REMOTE, "irrelevant-stanza-id2", + null, "id-user-a")); // a reaction @@ -277,7 +285,12 @@ public class MessageTransformationTest { reactionB.addExtension(Reactions.to(ogStanzaId)).addExtension(new Reaction("Y")); this.transformer.transform( MessageTransformation.of( - reactionB, Instant.now(), REMOTE, "irrelevant-stanza-id3", "id-user-b")); + reactionB, + Instant.now(), + REMOTE, + "irrelevant-stanza-id3", + null, + "id-user-b")); // the original message final var m4 = new Message(Message.Type.GROUPCHAT); @@ -286,7 +299,7 @@ public class MessageTransformationTest { m4.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-a"))); this.transformer.transform( MessageTransformation.of( - m4, Instant.ofEpochMilli(1000), REMOTE, ogStanzaId, "id-user-a")); + m4, Instant.ofEpochMilli(1000), REMOTE, ogStanzaId, null, "id-user-a")); final var messages = database.messageDao().getMessages(1L); Assert.assertEquals(1, messages.size()); @@ -310,7 +323,12 @@ public class MessageTransformationTest { reactionA.addExtension(Reactions.to(ogStanzaId)).addExtension(new Reaction("Y")); this.transformer.transform( MessageTransformation.of( - reactionA, Instant.now(), REMOTE, "irrelevant-stanza-id1", "id-user-b")); + reactionA, + Instant.now(), + REMOTE, + "irrelevant-stanza-id1", + null, + "id-user-b")); // second reaction final var reactionB = new Message(Message.Type.GROUPCHAT); @@ -318,7 +336,12 @@ public class MessageTransformationTest { reactionB.addExtension(Reactions.to(ogStanzaId)).addExtension(new Reaction("Y")); this.transformer.transform( MessageTransformation.of( - reactionB, Instant.now(), REMOTE, "irrelevant-stanza-id2", "id-user-c")); + reactionB, + Instant.now(), + REMOTE, + "irrelevant-stanza-id2", + null, + "id-user-c")); // a correction final var m1 = new Message(Message.Type.GROUPCHAT); @@ -331,6 +354,7 @@ public class MessageTransformationTest { Instant.ofEpochMilli(2000), REMOTE, "irrelevant-stanza-id3", + null, "id-user-a")); // the original message @@ -340,7 +364,7 @@ public class MessageTransformationTest { m4.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-a"))); this.transformer.transform( MessageTransformation.of( - m4, Instant.ofEpochMilli(1000), REMOTE, ogStanzaId, "id-user-a")); + m4, Instant.ofEpochMilli(1000), REMOTE, ogStanzaId, null, "id-user-a")); final var messages = database.messageDao().getMessages(1L); Assert.assertEquals(1, messages.size()); @@ -366,7 +390,7 @@ public class MessageTransformationTest { m4.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-a"))); this.transformer.transform( MessageTransformation.of( - m4, Instant.ofEpochMilli(1000), REMOTE, ogStanzaId, "id-user-a")); + m4, Instant.ofEpochMilli(1000), REMOTE, ogStanzaId, null, "id-user-a")); // first reaction final var reactionA = new Message(Message.Type.GROUPCHAT); @@ -374,7 +398,12 @@ public class MessageTransformationTest { reactionA.addExtension(Reactions.to(ogStanzaId)).addExtension(new Reaction("Y")); this.transformer.transform( MessageTransformation.of( - reactionA, Instant.now(), REMOTE, "irrelevant-stanza-id1", "id-user-b")); + reactionA, + Instant.now(), + REMOTE, + "irrelevant-stanza-id1", + null, + "id-user-b")); // second reaction final var reactionB = new Message(Message.Type.GROUPCHAT); @@ -382,7 +411,12 @@ public class MessageTransformationTest { reactionB.addExtension(Reactions.to(ogStanzaId)).addExtension(new Reaction("Y")); this.transformer.transform( MessageTransformation.of( - reactionB, Instant.now(), REMOTE, "irrelevant-stanza-id2", "id-user-c")); + reactionB, + Instant.now(), + REMOTE, + "irrelevant-stanza-id2", + null, + "id-user-c")); final var messages = database.messageDao().getMessages(1L); Assert.assertEquals(1, messages.size()); @@ -404,7 +438,8 @@ public class MessageTransformationTest { m1.addExtension(new Body("Hi. How are you?")); this.transformer.transform( - MessageTransformation.of(m1, Instant.now(), REMOTE, "stanza-a", null)); + MessageTransformation.of( + m1, Instant.now(), REMOTE, "stanza-a", m1.getFrom().asBareJid(), null)); final var m2 = new Message(); m2.setId("2"); @@ -416,7 +451,8 @@ public class MessageTransformationTest { reply.setTo(REMOTE); this.transformer.transform( - MessageTransformation.of(m2, Instant.now(), REMOTE, "stanza-b", null)); + MessageTransformation.of( + m2, Instant.now(), REMOTE, "stanza-b", m2.getFrom().asBareJid(), null)); final var messages = database.messageDao().getMessages(1L); Assert.assertEquals(2, messages.size()); @@ -440,14 +476,18 @@ public class MessageTransformationTest { m1.setFrom(JidCreate.fullFrom(ACCOUNT, Resourcepart.from("junit"))); m1.addExtension(new Body("Hi. How are you?")); - this.transformer.transform(MessageTransformation.of(m1, Instant.now(), REMOTE, null, null)); + this.transformer.transform( + MessageTransformation.of( + m1, Instant.now(), REMOTE, null, m1.getFrom().asBareJid(), null)); final var m2 = new Message(); m2.setTo(JidCreate.fullFrom(ACCOUNT, Resourcepart.from("junit"))); m2.setFrom(JidCreate.fullFrom(REMOTE, Resourcepart.from("junit"))); m2.addExtension(new Received()).setId("1"); - this.transformer.transform(MessageTransformation.of(m2, Instant.now(), REMOTE, null, null)); + this.transformer.transform( + MessageTransformation.of( + m2, Instant.now(), REMOTE, null, m2.getFrom().asBareJid(), null)); final var messages = database.messageDao().getMessages(1L); final var message = Iterables.getOnlyElement(messages); @@ -463,14 +503,16 @@ public class MessageTransformationTest { m1.setId("m1"); m1.addExtension(new Body("It is raining outside")); - this.transformer.transform(MessageTransformation.of(m1, Instant.now(), REMOTE, null, null)); + this.transformer.transform( + MessageTransformation.of(m1, Instant.now(), REMOTE, null, null, null)); final var m2 = new Message(); m2.setTo(ACCOUNT); m2.setFrom(JidCreate.fullFrom(REMOTE, Resourcepart.from("junit"))); m2.addExtension(new Retract()).setId("m1"); - this.transformer.transform(MessageTransformation.of(m2, Instant.now(), REMOTE, null, null)); + this.transformer.transform( + MessageTransformation.of(m2, Instant.now(), REMOTE, null, null, null)); final var messages = database.messageDao().getMessages(1L); final var message = Iterables.getOnlyElement(messages); diff --git a/app/src/main/java/im/conversations/android/database/dao/MessageDao.java b/app/src/main/java/im/conversations/android/database/dao/MessageDao.java index 2934ee7c4..969aef525 100644 --- a/app/src/main/java/im/conversations/android/database/dao/MessageDao.java +++ b/app/src/main/java/im/conversations/android/database/dao/MessageDao.java @@ -190,6 +190,7 @@ public abstract class MessageDao { // when found by stanzaId the stanzaId must either by verified or belonging to a stub // when found by messageId the from must either match (for corrections) or not be set (null) and // we only look up stubs + // TODO `senderIdentity` should probably match too @Query( "SELECT id,stanzaId,messageId,fromBare,latestVersion as version FROM message WHERE" + " chatId=:chatId AND (fromBare=:fromBare OR fromBare IS NULL) AND" @@ -207,8 +208,8 @@ public abstract class MessageDao { Preconditions.checkArgument( messageId != null, "A modification must reference a message id"); final MessageIdentifier messageIdentifier; - // TODO use type for condition and then null check occupantID if (transformation.type == Message.Type.GROUPCHAT) { + // TODO if modification == moderation do not take occupant Id into account Preconditions.checkNotNull( transformation.occupantId, "To create a version of a group chat message occupant id must be set"); @@ -227,6 +228,8 @@ public abstract class MessageDao { modification, messageId, transformation.fromBare()); + // TODO when creating a stub for 'moderation' we should not include occupant id and + // senderId in there since we don’t know who those are final var messageEntity = MessageEntity.stub(chat.id, messageId, transformation); final long messageEntityId = insert(messageEntity); final long messageVersionId = @@ -426,6 +429,7 @@ public abstract class MessageDao { + " FROM chat JOIN message on message.chatId=chat.id JOIN message_version ON" + " message.latestVersion=message_version.id LEFT JOIN axolotl_identity ON" + " chat.accountId=axolotl_identity.accountId AND" + + " message.senderIdentity=axolotl_identity.address AND" + " message_version.identityKey=axolotl_identity.identityKey WHERE chat.id=:chatId" + " AND latestVersion IS NOT NULL ORDER BY message.receivedAt") public abstract List getMessages(long chatId); diff --git a/app/src/main/java/im/conversations/android/database/entity/AxolotlIdentityEntity.java b/app/src/main/java/im/conversations/android/database/entity/AxolotlIdentityEntity.java index 8595e30c1..0a6661381 100644 --- a/app/src/main/java/im/conversations/android/database/entity/AxolotlIdentityEntity.java +++ b/app/src/main/java/im/conversations/android/database/entity/AxolotlIdentityEntity.java @@ -21,10 +21,7 @@ import org.whispersystems.libsignal.IdentityKey; indices = { @Index( value = {"accountId", "address", "identityKey"}, - unique = true), - @Index( - value = {"accountId", "identityKey"}, - unique = false) + unique = true) }) public class AxolotlIdentityEntity { diff --git a/app/src/main/java/im/conversations/android/database/entity/MessageEntity.java b/app/src/main/java/im/conversations/android/database/entity/MessageEntity.java index 74e087d1f..5ceff7fb2 100644 --- a/app/src/main/java/im/conversations/android/database/entity/MessageEntity.java +++ b/app/src/main/java/im/conversations/android/database/entity/MessageEntity.java @@ -55,6 +55,8 @@ public class MessageEntity { public String occupantId; + public BareJid senderIdentity; + public String messageId; public String stanzaId; // the stanza id might not be verified if this MessageEntity was created as a stub parent to @@ -80,6 +82,7 @@ public class MessageEntity { entity.fromBare = transformation.fromBare(); entity.fromResource = transformation.fromResource(); entity.occupantId = transformation.occupantId; + entity.senderIdentity = transformation.senderIdentity(); entity.messageId = transformation.messageId; entity.stanzaId = transformation.stanzaId; entity.stanzaIdVerified = Objects.nonNull(transformation.stanzaId); @@ -94,6 +97,7 @@ public class MessageEntity { entity.messageId = messageId; entity.stanzaIdVerified = false; entity.occupantId = transformation.occupantId; + entity.senderIdentity = transformation.senderIdentity(); return entity; } diff --git a/app/src/main/java/im/conversations/android/transformer/MessageTransformation.java b/app/src/main/java/im/conversations/android/transformer/MessageTransformation.java index 453db7ab0..35b4bf542 100644 --- a/app/src/main/java/im/conversations/android/transformer/MessageTransformation.java +++ b/app/src/main/java/im/conversations/android/transformer/MessageTransformation.java @@ -24,6 +24,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; +import org.jxmpp.jid.BareJid; import org.jxmpp.jid.Jid; public class MessageTransformation extends Transformation { @@ -42,6 +43,8 @@ public class MessageTransformation extends Transformation { Reply.class, Retract.class); + private final BareJid senderIdentity; + private final List extensions; public final Collection deliveryReceiptRequests; @@ -54,10 +57,12 @@ public class MessageTransformation extends Transformation { final Message.Type type, final String messageId, final String stanzaId, + final BareJid senderIdentity, final String occupantId, final List extensions, final Collection deliveryReceiptRequests) { super(receivedAt, to, from, remote, type, messageId, stanzaId, occupantId); + this.senderIdentity = senderIdentity; this.extensions = extensions; this.deliveryReceiptRequests = deliveryReceiptRequests; } @@ -72,6 +77,10 @@ public class MessageTransformation extends Transformation { return receivedAt; } + public BareJid senderIdentity() { + return senderIdentity; + } + public E getExtension(final Class clazz) { checkArgument(clazz); final var extension = Iterables.find(this.extensions, clazz::isInstance, null); @@ -97,6 +106,7 @@ public class MessageTransformation extends Transformation { @NonNull final Instant receivedAt, @NonNull final Jid remote, final String stanzaId, + final BareJid senderId, final String occupantId) { final var to = message.getTo(); final var from = message.getFrom(); @@ -121,6 +131,7 @@ public class MessageTransformation extends Transformation { type, messageId, stanzaId, + senderId, occupantId, extensionListBuilder.build(), requests); diff --git a/app/src/main/java/im/conversations/android/transformer/TransformationFactory.java b/app/src/main/java/im/conversations/android/transformer/TransformationFactory.java index a32d102ee..900fc3ce2 100644 --- a/app/src/main/java/im/conversations/android/transformer/TransformationFactory.java +++ b/app/src/main/java/im/conversations/android/transformer/TransformationFactory.java @@ -8,6 +8,7 @@ import im.conversations.android.xmpp.manager.DiscoManager; import im.conversations.android.xmpp.model.occupant.OccupantId; import im.conversations.android.xmpp.model.stanza.Message; import java.time.Instant; +import org.jxmpp.jid.BareJid; import org.jxmpp.jid.Jid; public class TransformationFactory extends XmppConnection.Delegate { @@ -44,6 +45,13 @@ public class TransformationFactory extends XmppConnection.Delegate { } else { occupantId = null; } - return MessageTransformation.of(message, receivedAt, remote, stanzaId, occupantId); + final BareJid senderIdentity; + if (message.getType() == Message.Type.GROUPCHAT) { + senderIdentity = null; // TODO discover real jid + } else { + senderIdentity = from == null ? null : from.asBareJid(); + } + return MessageTransformation.of( + message, receivedAt, remote, stanzaId, senderIdentity, occupantId); } } diff --git a/app/src/main/java/im/conversations/android/transformer/Transformer.java b/app/src/main/java/im/conversations/android/transformer/Transformer.java index fbfbbfa43..7e6e959ba 100644 --- a/app/src/main/java/im/conversations/android/transformer/Transformer.java +++ b/app/src/main/java/im/conversations/android/transformer/Transformer.java @@ -96,7 +96,8 @@ public class Transformer { final MessageContentWrapper contents; if (encrypted != null) { try { - final var payload = axolotlService.decrypt(transformation.from, encrypted); + final var payload = + axolotlService.decrypt(transformation.senderIdentity(), encrypted); if (payload.hasPayload()) { contents = MessageContentWrapper.ofAxolotl(payload); } else { diff --git a/app/src/main/java/im/conversations/android/xmpp/Managers.java b/app/src/main/java/im/conversations/android/xmpp/Managers.java index 6eaa90e7d..6eeeb7839 100644 --- a/app/src/main/java/im/conversations/android/xmpp/Managers.java +++ b/app/src/main/java/im/conversations/android/xmpp/Managers.java @@ -23,6 +23,7 @@ import im.conversations.android.xmpp.manager.ReceiptManager; import im.conversations.android.xmpp.manager.RegistrationManager; import im.conversations.android.xmpp.manager.RosterManager; import im.conversations.android.xmpp.manager.StanzaIdManager; +import im.conversations.android.xmpp.manager.TrustManager; public final class Managers { @@ -52,6 +53,7 @@ public final class Managers { .put(RegistrationManager.class, new RegistrationManager(context, connection)) .put(RosterManager.class, new RosterManager(context, connection)) .put(StanzaIdManager.class, new StanzaIdManager(context, connection)) + .put(TrustManager.class, new TrustManager(context, connection)) .build(); } } diff --git a/app/src/main/java/im/conversations/android/tls/TrustManager.java b/app/src/main/java/im/conversations/android/xmpp/manager/TrustManager.java similarity index 56% rename from app/src/main/java/im/conversations/android/tls/TrustManager.java rename to app/src/main/java/im/conversations/android/xmpp/manager/TrustManager.java index 46fac9cb7..369104614 100644 --- a/app/src/main/java/im/conversations/android/tls/TrustManager.java +++ b/app/src/main/java/im/conversations/android/xmpp/manager/TrustManager.java @@ -1,19 +1,19 @@ -package im.conversations.android.tls; +package im.conversations.android.xmpp.manager; import android.content.Context; -import im.conversations.android.database.model.Account; +import im.conversations.android.AppSettings; +import im.conversations.android.xmpp.XmppConnection; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import javax.net.ssl.X509TrustManager; -public class TrustManager implements X509TrustManager { +public class TrustManager extends AbstractManager implements X509TrustManager { - private final Context context; - private final Account account; + private final AppSettings appSettings; - public TrustManager(final Context context, final Account account) { - this.context = context; - this.account = account; + public TrustManager(final Context context, final XmppConnection connection) { + super(context, connection); + this.appSettings = new AppSettings(context); } @Override