store senderIdentity in message

This commit is contained in:
Daniel Gultsch 2023-03-01 14:52:11 +01:00
parent 303f14200f
commit c2bf9d0413
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
10 changed files with 120 additions and 55 deletions

View file

@ -2,7 +2,7 @@
"formatVersion": 1, "formatVersion": 1,
"database": { "database": {
"version": 1, "version": 1,
"identityHash": "9d2672ebdefc9df52add6eebf635031f", "identityHash": "5152f8eab684376f6f4076cf392e22d7",
"entities": [ "entities": [
{ {
"tableName": "account", "tableName": "account",
@ -482,16 +482,6 @@
], ],
"orders": [], "orders": [],
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_axolotl_identity_accountId_address_identityKey` ON `${TABLE_NAME}` (`accountId`, `address`, `identityKey`)" "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": [ "foreignKeys": [
@ -1516,7 +1506,7 @@
}, },
{ {
"tableName": "message", "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": [ "fields": [
{ {
"fieldPath": "id", "fieldPath": "id",
@ -1578,6 +1568,12 @@
"affinity": "TEXT", "affinity": "TEXT",
"notNull": false "notNull": false
}, },
{
"fieldPath": "senderIdentity",
"columnName": "senderIdentity",
"affinity": "TEXT",
"notNull": false
},
{ {
"fieldPath": "messageId", "fieldPath": "messageId",
"columnName": "messageId", "columnName": "messageId",
@ -2380,7 +2376,7 @@
"views": [], "views": [],
"setupQueries": [ "setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", "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')"
] ]
} }
} }

View file

@ -70,7 +70,8 @@ public class MessageTransformationTest {
final var reaction = reactions.addExtension(new Reaction()); final var reaction = reactions.addExtension(new Reaction());
reaction.setContent("Y"); reaction.setContent("Y");
this.transformer.transform( 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(); final var originalMessage = new Message();
originalMessage.setId("1"); originalMessage.setId("1");
originalMessage.setTo(REMOTE); originalMessage.setTo(REMOTE);
@ -78,7 +79,8 @@ public class MessageTransformationTest {
final var body = originalMessage.addExtension(new Body()); final var body = originalMessage.addExtension(new Body());
body.setContent(GREETING); body.setContent(GREETING);
this.transformer.transform( 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); final var messages = database.messageDao().getMessages(1L);
Assert.assertEquals(1, messages.size()); Assert.assertEquals(1, messages.size());
@ -98,21 +100,22 @@ public class MessageTransformationTest {
message.addExtension(new Body("Please give me a thumbs up")); message.addExtension(new Body("Please give me a thumbs up"));
message.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-a"))); message.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-a")));
this.transformer.transform( 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); final var reactionA = new Message(Message.Type.GROUPCHAT);
reactionA.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-b"))); reactionA.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-b")));
reactionA.addExtension(Reactions.to("stanza-a")).addExtension(new Reaction("Y")); reactionA.addExtension(Reactions.to("stanza-a")).addExtension(new Reaction("Y"));
this.transformer.transform( this.transformer.transform(
MessageTransformation.of( 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); final var reactionB = new Message(Message.Type.GROUPCHAT);
reactionB.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-c"))); reactionB.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-c")));
reactionB.addExtension(Reactions.to("stanza-a")).addExtension(new Reaction("Y")); reactionB.addExtension(Reactions.to("stanza-a")).addExtension(new Reaction("Y"));
this.transformer.transform( this.transformer.transform(
MessageTransformation.of( 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); final var reactionC = new Message(Message.Type.GROUPCHAT);
reactionC.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-d"))); reactionC.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-d")));
@ -121,7 +124,7 @@ public class MessageTransformationTest {
reactions.addExtension(new Reaction("Z")); reactions.addExtension(new Reaction("Z"));
this.transformer.transform( this.transformer.transform(
MessageTransformation.of( 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); final var messages = database.messageDao().getMessages(1L);
Assert.assertEquals(1, messages.size()); Assert.assertEquals(1, messages.size());
@ -148,7 +151,7 @@ public class MessageTransformationTest {
this.transformer.transform( this.transformer.transform(
MessageTransformation.of( 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 // the correction should not show up as a message
Assert.assertEquals(0, database.messageDao().getMessages(1L).size()); Assert.assertEquals(0, database.messageDao().getMessages(1L).size());
@ -160,7 +163,8 @@ public class MessageTransformationTest {
messageWithTypo.addExtension(new Body()).setContent("Hii example!"); messageWithTypo.addExtension(new Body()).setContent("Hii example!");
this.transformer.transform( 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); final var messages = database.messageDao().getMessages(1L);
@ -182,7 +186,8 @@ public class MessageTransformationTest {
messageWithTypo.addExtension(new Body()).setContent("Hii example!"); messageWithTypo.addExtension(new Body()).setContent("Hii example!");
this.transformer.transform( 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()); Assert.assertEquals(1, database.messageDao().getMessages(1L).size());
@ -195,7 +200,7 @@ public class MessageTransformationTest {
this.transformer.transform( this.transformer.transform(
MessageTransformation.of( MessageTransformation.of(
messageCorrection, Instant.now(), REMOTE, "stanza-b", null)); messageCorrection, Instant.now(), REMOTE, "stanza-b", null, null));
final var messages = database.messageDao().getMessages(1L); 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.addExtension(new Body("Please give me a thumbs up"));
message.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-a"))); message.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-a")));
this.transformer.transform( 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); final var reactionA = new Message(Message.Type.GROUPCHAT);
reactionA.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-b"))); reactionA.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-b")));
reactionA.addExtension(Reactions.to("stanza-a")).addExtension(new Reaction("N")); reactionA.addExtension(Reactions.to("stanza-a")).addExtension(new Reaction("N"));
this.transformer.transform( this.transformer.transform(
MessageTransformation.of( 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); final var reactionB = new Message(Message.Type.GROUPCHAT);
reactionB.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-b"))); reactionB.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-b")));
reactionB.addExtension(Reactions.to("stanza-a")).addExtension(new Reaction("Y")); reactionB.addExtension(Reactions.to("stanza-a")).addExtension(new Reaction("Y"));
this.transformer.transform( this.transformer.transform(
MessageTransformation.of( 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); final var messages = database.messageDao().getMessages(1L);
Assert.assertEquals(1, messages.size()); Assert.assertEquals(1, messages.size());
@ -255,6 +261,7 @@ public class MessageTransformationTest {
Instant.ofEpochMilli(2000), Instant.ofEpochMilli(2000),
REMOTE, REMOTE,
"irrelevant-stanza-id1", "irrelevant-stanza-id1",
null,
"id-user-a")); "id-user-a"));
// second correction // second correction
@ -269,6 +276,7 @@ public class MessageTransformationTest {
Instant.ofEpochMilli(3000), Instant.ofEpochMilli(3000),
REMOTE, REMOTE,
"irrelevant-stanza-id2", "irrelevant-stanza-id2",
null,
"id-user-a")); "id-user-a"));
// a reaction // a reaction
@ -277,7 +285,12 @@ public class MessageTransformationTest {
reactionB.addExtension(Reactions.to(ogStanzaId)).addExtension(new Reaction("Y")); reactionB.addExtension(Reactions.to(ogStanzaId)).addExtension(new Reaction("Y"));
this.transformer.transform( this.transformer.transform(
MessageTransformation.of( 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 // the original message
final var m4 = new Message(Message.Type.GROUPCHAT); final var m4 = new Message(Message.Type.GROUPCHAT);
@ -286,7 +299,7 @@ public class MessageTransformationTest {
m4.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-a"))); m4.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-a")));
this.transformer.transform( this.transformer.transform(
MessageTransformation.of( 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); final var messages = database.messageDao().getMessages(1L);
Assert.assertEquals(1, messages.size()); Assert.assertEquals(1, messages.size());
@ -310,7 +323,12 @@ public class MessageTransformationTest {
reactionA.addExtension(Reactions.to(ogStanzaId)).addExtension(new Reaction("Y")); reactionA.addExtension(Reactions.to(ogStanzaId)).addExtension(new Reaction("Y"));
this.transformer.transform( this.transformer.transform(
MessageTransformation.of( 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 // second reaction
final var reactionB = new Message(Message.Type.GROUPCHAT); final var reactionB = new Message(Message.Type.GROUPCHAT);
@ -318,7 +336,12 @@ public class MessageTransformationTest {
reactionB.addExtension(Reactions.to(ogStanzaId)).addExtension(new Reaction("Y")); reactionB.addExtension(Reactions.to(ogStanzaId)).addExtension(new Reaction("Y"));
this.transformer.transform( this.transformer.transform(
MessageTransformation.of( 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 // a correction
final var m1 = new Message(Message.Type.GROUPCHAT); final var m1 = new Message(Message.Type.GROUPCHAT);
@ -331,6 +354,7 @@ public class MessageTransformationTest {
Instant.ofEpochMilli(2000), Instant.ofEpochMilli(2000),
REMOTE, REMOTE,
"irrelevant-stanza-id3", "irrelevant-stanza-id3",
null,
"id-user-a")); "id-user-a"));
// the original message // the original message
@ -340,7 +364,7 @@ public class MessageTransformationTest {
m4.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-a"))); m4.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-a")));
this.transformer.transform( this.transformer.transform(
MessageTransformation.of( 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); final var messages = database.messageDao().getMessages(1L);
Assert.assertEquals(1, messages.size()); Assert.assertEquals(1, messages.size());
@ -366,7 +390,7 @@ public class MessageTransformationTest {
m4.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-a"))); m4.setFrom(JidCreate.fullFrom(group, Resourcepart.from("user-a")));
this.transformer.transform( this.transformer.transform(
MessageTransformation.of( MessageTransformation.of(
m4, Instant.ofEpochMilli(1000), REMOTE, ogStanzaId, "id-user-a")); m4, Instant.ofEpochMilli(1000), REMOTE, ogStanzaId, null, "id-user-a"));
// first reaction // first reaction
final var reactionA = new Message(Message.Type.GROUPCHAT); final var reactionA = new Message(Message.Type.GROUPCHAT);
@ -374,7 +398,12 @@ public class MessageTransformationTest {
reactionA.addExtension(Reactions.to(ogStanzaId)).addExtension(new Reaction("Y")); reactionA.addExtension(Reactions.to(ogStanzaId)).addExtension(new Reaction("Y"));
this.transformer.transform( this.transformer.transform(
MessageTransformation.of( 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 // second reaction
final var reactionB = new Message(Message.Type.GROUPCHAT); final var reactionB = new Message(Message.Type.GROUPCHAT);
@ -382,7 +411,12 @@ public class MessageTransformationTest {
reactionB.addExtension(Reactions.to(ogStanzaId)).addExtension(new Reaction("Y")); reactionB.addExtension(Reactions.to(ogStanzaId)).addExtension(new Reaction("Y"));
this.transformer.transform( this.transformer.transform(
MessageTransformation.of( 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); final var messages = database.messageDao().getMessages(1L);
Assert.assertEquals(1, messages.size()); Assert.assertEquals(1, messages.size());
@ -404,7 +438,8 @@ public class MessageTransformationTest {
m1.addExtension(new Body("Hi. How are you?")); m1.addExtension(new Body("Hi. How are you?"));
this.transformer.transform( 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(); final var m2 = new Message();
m2.setId("2"); m2.setId("2");
@ -416,7 +451,8 @@ public class MessageTransformationTest {
reply.setTo(REMOTE); reply.setTo(REMOTE);
this.transformer.transform( 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); final var messages = database.messageDao().getMessages(1L);
Assert.assertEquals(2, messages.size()); Assert.assertEquals(2, messages.size());
@ -440,14 +476,18 @@ public class MessageTransformationTest {
m1.setFrom(JidCreate.fullFrom(ACCOUNT, Resourcepart.from("junit"))); m1.setFrom(JidCreate.fullFrom(ACCOUNT, Resourcepart.from("junit")));
m1.addExtension(new Body("Hi. How are you?")); 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(); final var m2 = new Message();
m2.setTo(JidCreate.fullFrom(ACCOUNT, Resourcepart.from("junit"))); m2.setTo(JidCreate.fullFrom(ACCOUNT, Resourcepart.from("junit")));
m2.setFrom(JidCreate.fullFrom(REMOTE, Resourcepart.from("junit"))); m2.setFrom(JidCreate.fullFrom(REMOTE, Resourcepart.from("junit")));
m2.addExtension(new Received()).setId("1"); 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 messages = database.messageDao().getMessages(1L);
final var message = Iterables.getOnlyElement(messages); final var message = Iterables.getOnlyElement(messages);
@ -463,14 +503,16 @@ public class MessageTransformationTest {
m1.setId("m1"); m1.setId("m1");
m1.addExtension(new Body("It is raining outside")); 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(); final var m2 = new Message();
m2.setTo(ACCOUNT); m2.setTo(ACCOUNT);
m2.setFrom(JidCreate.fullFrom(REMOTE, Resourcepart.from("junit"))); m2.setFrom(JidCreate.fullFrom(REMOTE, Resourcepart.from("junit")));
m2.addExtension(new Retract()).setId("m1"); 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 messages = database.messageDao().getMessages(1L);
final var message = Iterables.getOnlyElement(messages); final var message = Iterables.getOnlyElement(messages);

View file

@ -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 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 // when found by messageId the from must either match (for corrections) or not be set (null) and
// we only look up stubs // we only look up stubs
// TODO `senderIdentity` should probably match too
@Query( @Query(
"SELECT id,stanzaId,messageId,fromBare,latestVersion as version FROM message WHERE" "SELECT id,stanzaId,messageId,fromBare,latestVersion as version FROM message WHERE"
+ " chatId=:chatId AND (fromBare=:fromBare OR fromBare IS NULL) AND" + " chatId=:chatId AND (fromBare=:fromBare OR fromBare IS NULL) AND"
@ -207,8 +208,8 @@ public abstract class MessageDao {
Preconditions.checkArgument( Preconditions.checkArgument(
messageId != null, "A modification must reference a message id"); messageId != null, "A modification must reference a message id");
final MessageIdentifier messageIdentifier; final MessageIdentifier messageIdentifier;
// TODO use type for condition and then null check occupantID
if (transformation.type == Message.Type.GROUPCHAT) { if (transformation.type == Message.Type.GROUPCHAT) {
// TODO if modification == moderation do not take occupant Id into account
Preconditions.checkNotNull( Preconditions.checkNotNull(
transformation.occupantId, transformation.occupantId,
"To create a version of a group chat message occupant id must be set"); "To create a version of a group chat message occupant id must be set");
@ -227,6 +228,8 @@ public abstract class MessageDao {
modification, modification,
messageId, messageId,
transformation.fromBare()); transformation.fromBare());
// TODO when creating a stub for 'moderation' we should not include occupant id and
// senderId in there since we dont know who those are
final var messageEntity = MessageEntity.stub(chat.id, messageId, transformation); final var messageEntity = MessageEntity.stub(chat.id, messageId, transformation);
final long messageEntityId = insert(messageEntity); final long messageEntityId = insert(messageEntity);
final long messageVersionId = final long messageVersionId =
@ -426,6 +429,7 @@ public abstract class MessageDao {
+ " FROM chat JOIN message on message.chatId=chat.id JOIN message_version ON" + " FROM chat JOIN message on message.chatId=chat.id JOIN message_version ON"
+ " message.latestVersion=message_version.id LEFT JOIN axolotl_identity ON" + " message.latestVersion=message_version.id LEFT JOIN axolotl_identity ON"
+ " chat.accountId=axolotl_identity.accountId AND" + " chat.accountId=axolotl_identity.accountId AND"
+ " message.senderIdentity=axolotl_identity.address AND"
+ " message_version.identityKey=axolotl_identity.identityKey WHERE chat.id=:chatId" + " message_version.identityKey=axolotl_identity.identityKey WHERE chat.id=:chatId"
+ " AND latestVersion IS NOT NULL ORDER BY message.receivedAt") + " AND latestVersion IS NOT NULL ORDER BY message.receivedAt")
public abstract List<MessageWithContentReactions> getMessages(long chatId); public abstract List<MessageWithContentReactions> getMessages(long chatId);

View file

@ -21,10 +21,7 @@ import org.whispersystems.libsignal.IdentityKey;
indices = { indices = {
@Index( @Index(
value = {"accountId", "address", "identityKey"}, value = {"accountId", "address", "identityKey"},
unique = true), unique = true)
@Index(
value = {"accountId", "identityKey"},
unique = false)
}) })
public class AxolotlIdentityEntity { public class AxolotlIdentityEntity {

View file

@ -55,6 +55,8 @@ public class MessageEntity {
public String occupantId; public String occupantId;
public BareJid senderIdentity;
public String messageId; public String messageId;
public String stanzaId; public String stanzaId;
// the stanza id might not be verified if this MessageEntity was created as a stub parent to // 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.fromBare = transformation.fromBare();
entity.fromResource = transformation.fromResource(); entity.fromResource = transformation.fromResource();
entity.occupantId = transformation.occupantId; entity.occupantId = transformation.occupantId;
entity.senderIdentity = transformation.senderIdentity();
entity.messageId = transformation.messageId; entity.messageId = transformation.messageId;
entity.stanzaId = transformation.stanzaId; entity.stanzaId = transformation.stanzaId;
entity.stanzaIdVerified = Objects.nonNull(transformation.stanzaId); entity.stanzaIdVerified = Objects.nonNull(transformation.stanzaId);
@ -94,6 +97,7 @@ public class MessageEntity {
entity.messageId = messageId; entity.messageId = messageId;
entity.stanzaIdVerified = false; entity.stanzaIdVerified = false;
entity.occupantId = transformation.occupantId; entity.occupantId = transformation.occupantId;
entity.senderIdentity = transformation.senderIdentity();
return entity; return entity;
} }

View file

@ -24,6 +24,7 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.Jid; import org.jxmpp.jid.Jid;
public class MessageTransformation extends Transformation { public class MessageTransformation extends Transformation {
@ -42,6 +43,8 @@ public class MessageTransformation extends Transformation {
Reply.class, Reply.class,
Retract.class); Retract.class);
private final BareJid senderIdentity;
private final List<Extension> extensions; private final List<Extension> extensions;
public final Collection<DeliveryReceiptRequest> deliveryReceiptRequests; public final Collection<DeliveryReceiptRequest> deliveryReceiptRequests;
@ -54,10 +57,12 @@ public class MessageTransformation extends Transformation {
final Message.Type type, final Message.Type type,
final String messageId, final String messageId,
final String stanzaId, final String stanzaId,
final BareJid senderIdentity,
final String occupantId, final String occupantId,
final List<Extension> extensions, final List<Extension> extensions,
final Collection<DeliveryReceiptRequest> deliveryReceiptRequests) { final Collection<DeliveryReceiptRequest> deliveryReceiptRequests) {
super(receivedAt, to, from, remote, type, messageId, stanzaId, occupantId); super(receivedAt, to, from, remote, type, messageId, stanzaId, occupantId);
this.senderIdentity = senderIdentity;
this.extensions = extensions; this.extensions = extensions;
this.deliveryReceiptRequests = deliveryReceiptRequests; this.deliveryReceiptRequests = deliveryReceiptRequests;
} }
@ -72,6 +77,10 @@ public class MessageTransformation extends Transformation {
return receivedAt; return receivedAt;
} }
public BareJid senderIdentity() {
return senderIdentity;
}
public <E extends Extension> E getExtension(final Class<E> clazz) { public <E extends Extension> E getExtension(final Class<E> clazz) {
checkArgument(clazz); checkArgument(clazz);
final var extension = Iterables.find(this.extensions, clazz::isInstance, null); 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 Instant receivedAt,
@NonNull final Jid remote, @NonNull final Jid remote,
final String stanzaId, final String stanzaId,
final BareJid senderId,
final String occupantId) { final String occupantId) {
final var to = message.getTo(); final var to = message.getTo();
final var from = message.getFrom(); final var from = message.getFrom();
@ -121,6 +131,7 @@ public class MessageTransformation extends Transformation {
type, type,
messageId, messageId,
stanzaId, stanzaId,
senderId,
occupantId, occupantId,
extensionListBuilder.build(), extensionListBuilder.build(),
requests); requests);

View file

@ -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.occupant.OccupantId;
import im.conversations.android.xmpp.model.stanza.Message; import im.conversations.android.xmpp.model.stanza.Message;
import java.time.Instant; import java.time.Instant;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.Jid; import org.jxmpp.jid.Jid;
public class TransformationFactory extends XmppConnection.Delegate { public class TransformationFactory extends XmppConnection.Delegate {
@ -44,6 +45,13 @@ public class TransformationFactory extends XmppConnection.Delegate {
} else { } else {
occupantId = null; 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);
} }
} }

View file

@ -96,7 +96,8 @@ public class Transformer {
final MessageContentWrapper contents; final MessageContentWrapper contents;
if (encrypted != null) { if (encrypted != null) {
try { try {
final var payload = axolotlService.decrypt(transformation.from, encrypted); final var payload =
axolotlService.decrypt(transformation.senderIdentity(), encrypted);
if (payload.hasPayload()) { if (payload.hasPayload()) {
contents = MessageContentWrapper.ofAxolotl(payload); contents = MessageContentWrapper.ofAxolotl(payload);
} else { } else {

View file

@ -23,6 +23,7 @@ import im.conversations.android.xmpp.manager.ReceiptManager;
import im.conversations.android.xmpp.manager.RegistrationManager; import im.conversations.android.xmpp.manager.RegistrationManager;
import im.conversations.android.xmpp.manager.RosterManager; import im.conversations.android.xmpp.manager.RosterManager;
import im.conversations.android.xmpp.manager.StanzaIdManager; import im.conversations.android.xmpp.manager.StanzaIdManager;
import im.conversations.android.xmpp.manager.TrustManager;
public final class Managers { public final class Managers {
@ -52,6 +53,7 @@ public final class Managers {
.put(RegistrationManager.class, new RegistrationManager(context, connection)) .put(RegistrationManager.class, new RegistrationManager(context, connection))
.put(RosterManager.class, new RosterManager(context, connection)) .put(RosterManager.class, new RosterManager(context, connection))
.put(StanzaIdManager.class, new StanzaIdManager(context, connection)) .put(StanzaIdManager.class, new StanzaIdManager(context, connection))
.put(TrustManager.class, new TrustManager(context, connection))
.build(); .build();
} }
} }

View file

@ -1,19 +1,19 @@
package im.conversations.android.tls; package im.conversations.android.xmpp.manager;
import android.content.Context; 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.CertificateException;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import javax.net.ssl.X509TrustManager; import javax.net.ssl.X509TrustManager;
public class TrustManager implements X509TrustManager { public class TrustManager extends AbstractManager implements X509TrustManager {
private final Context context; private final AppSettings appSettings;
private final Account account;
public TrustManager(final Context context, final Account account) { public TrustManager(final Context context, final XmppConnection connection) {
this.context = context; super(context, connection);
this.account = account; this.appSettings = new AppSettings(context);
} }
@Override @Override