From 2d10a561e4a6f33abb1293b6396b4b2d71854582 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 13 Feb 2023 16:15:59 +0100 Subject: [PATCH] rename EmbeddedMessage to MessageEmbedded --- .../android/xmpp/TransformationTest.java | 28 +++++++++++++++++-- ...eddedMessage.java => MessageEmbedded.java} | 2 +- .../model/MessageWithContentReactions.java | 9 +++++- 3 files changed, 35 insertions(+), 4 deletions(-) rename src/main/java/im/conversations/android/database/model/{EmbeddedMessage.java => MessageEmbedded.java} (94%) diff --git a/src/androidTest/java/im/conversations/android/xmpp/TransformationTest.java b/src/androidTest/java/im/conversations/android/xmpp/TransformationTest.java index fb3d6e020..28da6bc12 100644 --- a/src/androidTest/java/im/conversations/android/xmpp/TransformationTest.java +++ b/src/androidTest/java/im/conversations/android/xmpp/TransformationTest.java @@ -9,7 +9,7 @@ import eu.siacs.conversations.xmpp.Jid; import im.conversations.android.IDs; import im.conversations.android.database.ConversationsDatabase; import im.conversations.android.database.entity.AccountEntity; -import im.conversations.android.database.model.EmbeddedMessage; +import im.conversations.android.database.model.MessageEmbedded; import im.conversations.android.database.model.Modification; import im.conversations.android.transformer.Transformation; import im.conversations.android.transformer.Transformer; @@ -17,6 +17,7 @@ import im.conversations.android.xmpp.model.correction.Replace; import im.conversations.android.xmpp.model.jabber.Body; import im.conversations.android.xmpp.model.reactions.Reaction; import im.conversations.android.xmpp.model.reactions.Reactions; +import im.conversations.android.xmpp.model.receipts.Received; import im.conversations.android.xmpp.model.reply.Reply; import im.conversations.android.xmpp.model.stanza.Message; import java.time.Instant; @@ -399,11 +400,34 @@ public class TransformationTest { Assert.assertEquals(2, messages.size()); final var response = Iterables.get(messages, 1); Assert.assertNotNull(response.inReplyToMessageEntityId); - final EmbeddedMessage embeddedMessage = response.inReplyTo; + final MessageEmbedded embeddedMessage = response.inReplyTo; Assert.assertNotNull(embeddedMessage); Assert.assertEquals(REMOTE, embeddedMessage.fromBare); Assert.assertEquals(1L, embeddedMessage.contents.size()); Assert.assertEquals( "Hi. How are you?", Iterables.getOnlyElement(embeddedMessage.contents).body); } + + @Test + public void messageWithReceipt() { + final var m1 = new Message(); + m1.setId("1"); + m1.setTo(REMOTE); + m1.setFrom(ACCOUNT.withResource("junit")); + m1.addExtension(new Body("Hi. How are you?")); + + this.transformer.transform(Transformation.of(m1, Instant.now(), REMOTE, null, null)); + + final var m2 = new Message(); + m2.setTo(ACCOUNT.withResource("junit")); + m2.setFrom(REMOTE.withResource("junit")); + m2.addExtension(new Received()).setId("1"); + + this.transformer.transform(Transformation.of(m2, Instant.now(), REMOTE, null, null)); + + final var messages = database.messageDao().getMessages(1L); + final var message = Iterables.getOnlyElement(messages); + + Assert.assertEquals(1L, message.states.size()); + } } diff --git a/src/main/java/im/conversations/android/database/model/EmbeddedMessage.java b/src/main/java/im/conversations/android/database/model/MessageEmbedded.java similarity index 94% rename from src/main/java/im/conversations/android/database/model/EmbeddedMessage.java rename to src/main/java/im/conversations/android/database/model/MessageEmbedded.java index 59d21b2b4..5583d5fe3 100644 --- a/src/main/java/im/conversations/android/database/model/EmbeddedMessage.java +++ b/src/main/java/im/conversations/android/database/model/MessageEmbedded.java @@ -6,7 +6,7 @@ import im.conversations.android.database.entity.MessageContentEntity; import java.time.Instant; import java.util.List; -public class EmbeddedMessage { +public class MessageEmbedded { public long id; public Jid fromBare; diff --git a/src/main/java/im/conversations/android/database/model/MessageWithContentReactions.java b/src/main/java/im/conversations/android/database/model/MessageWithContentReactions.java index 22ccf2ddd..0463c5754 100644 --- a/src/main/java/im/conversations/android/database/model/MessageWithContentReactions.java +++ b/src/main/java/im/conversations/android/database/model/MessageWithContentReactions.java @@ -8,6 +8,7 @@ import eu.siacs.conversations.xmpp.Jid; import im.conversations.android.database.entity.MessageContentEntity; import im.conversations.android.database.entity.MessageEntity; import im.conversations.android.database.entity.MessageReactionEntity; +import im.conversations.android.database.entity.MessageStateEntity; import java.time.Instant; import java.util.Collection; import java.util.List; @@ -35,7 +36,7 @@ public class MessageWithContentReactions { entity = MessageEntity.class, parentColumn = "inReplyToMessageEntityId", entityColumn = "id") - public EmbeddedMessage inReplyTo; + public MessageEmbedded inReplyTo; @Relation( entity = MessageContentEntity.class, @@ -49,6 +50,12 @@ public class MessageWithContentReactions { entityColumn = "messageEntityId") public List reactions; + @Relation( + entity = MessageStateEntity.class, + parentColumn = "version", + entityColumn = "messageVersionId") + public List states; + public Set> getAggregatedReactions() { final Map aggregatedReactions = Maps.transformValues(