verify we set occupantId on modifcations in group chat

This commit is contained in:
Daniel Gultsch 2023-02-14 09:21:31 +01:00
parent 69d212141b
commit 268bef4433
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
2 changed files with 10 additions and 0 deletions

View file

@ -92,6 +92,7 @@ public class MessageEntity {
entity.fromBare = transformation.fromBare(); entity.fromBare = transformation.fromBare();
entity.messageId = messageId; entity.messageId = messageId;
entity.stanzaIdVerified = false; entity.stanzaIdVerified = false;
entity.occupantId = transformation.occupantId;
return entity; return entity;
} }

View file

@ -5,9 +5,11 @@ import androidx.room.Entity;
import androidx.room.ForeignKey; import androidx.room.ForeignKey;
import androidx.room.Index; import androidx.room.Index;
import androidx.room.PrimaryKey; import androidx.room.PrimaryKey;
import com.google.common.base.Preconditions;
import eu.siacs.conversations.xmpp.Jid; import eu.siacs.conversations.xmpp.Jid;
import im.conversations.android.database.model.Modification; import im.conversations.android.database.model.Modification;
import im.conversations.android.transformer.Transformation; import im.conversations.android.transformer.Transformation;
import im.conversations.android.xmpp.model.stanza.Message;
import java.time.Instant; import java.time.Instant;
@Entity( @Entity(
@ -43,6 +45,12 @@ public class MessageVersionEntity {
long messageEntityId, long messageEntityId,
final Modification modification, final Modification modification,
final Transformation transformation) { 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(); final var entity = new MessageVersionEntity();
entity.messageEntityId = messageEntityId; entity.messageEntityId = messageEntityId;
entity.messageId = transformation.messageId; entity.messageId = transformation.messageId;
@ -50,6 +58,7 @@ public class MessageVersionEntity {
entity.modification = modification; entity.modification = modification;
entity.modifiedBy = transformation.fromBare(); entity.modifiedBy = transformation.fromBare();
entity.modifiedByResource = transformation.fromResource(); entity.modifiedByResource = transformation.fromResource();
entity.occupantId = transformation.occupantId;
entity.receivedAt = transformation.receivedAt; entity.receivedAt = transformation.receivedAt;
return entity; return entity;
} }