From 268bef4433b7cba1bd4845b70655eeae62e19b76 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 14 Feb 2023 09:21:31 +0100 Subject: [PATCH] verify we set occupantId on modifcations in group chat --- .../android/database/entity/MessageEntity.java | 1 + .../android/database/entity/MessageVersionEntity.java | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/main/java/im/conversations/android/database/entity/MessageEntity.java b/src/main/java/im/conversations/android/database/entity/MessageEntity.java index 9bde72179..58c5e64a4 100644 --- a/src/main/java/im/conversations/android/database/entity/MessageEntity.java +++ b/src/main/java/im/conversations/android/database/entity/MessageEntity.java @@ -92,6 +92,7 @@ public class MessageEntity { entity.fromBare = transformation.fromBare(); entity.messageId = messageId; entity.stanzaIdVerified = false; + entity.occupantId = transformation.occupantId; return entity; } diff --git a/src/main/java/im/conversations/android/database/entity/MessageVersionEntity.java b/src/main/java/im/conversations/android/database/entity/MessageVersionEntity.java index 9a717b7bf..c88685879 100644 --- a/src/main/java/im/conversations/android/database/entity/MessageVersionEntity.java +++ b/src/main/java/im/conversations/android/database/entity/MessageVersionEntity.java @@ -5,9 +5,11 @@ import androidx.room.Entity; import androidx.room.ForeignKey; import androidx.room.Index; import androidx.room.PrimaryKey; +import com.google.common.base.Preconditions; import eu.siacs.conversations.xmpp.Jid; import im.conversations.android.database.model.Modification; import im.conversations.android.transformer.Transformation; +import im.conversations.android.xmpp.model.stanza.Message; import java.time.Instant; @Entity( @@ -43,6 +45,12 @@ public class MessageVersionEntity { long messageEntityId, final Modification modification, final Transformation transformation) { + if (transformation.type == Message.Type.GROUPCHAT + && modification != Modification.ORIGINAL) { + Preconditions.checkState( + transformation.occupantId != null, + "Message versions other than original must have an occupantId in group chats"); + } final var entity = new MessageVersionEntity(); entity.messageEntityId = messageEntityId; entity.messageId = transformation.messageId; @@ -50,6 +58,7 @@ public class MessageVersionEntity { entity.modification = modification; entity.modifiedBy = transformation.fromBare(); entity.modifiedByResource = transformation.fromResource(); + entity.occupantId = transformation.occupantId; entity.receivedAt = transformation.receivedAt; return entity; }