diff --git a/SessionMessagingKit/Messages/Message.swift b/SessionMessagingKit/Messages/Message.swift index 17d97149c..ab6111217 100644 --- a/SessionMessagingKit/Messages/Message.swift +++ b/SessionMessagingKit/Messages/Message.swift @@ -80,6 +80,7 @@ public class Message: Codable { let type = disappearingMessagesConfiguration.type { proto.setExpirationType(type.toProto()) + proto.setLastDisappearingMessageChangeTimestamp(UInt64(disappearingMessagesConfiguration.lastChangeTimestampMs)) } } diff --git a/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift b/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift index c5dd8ca1b..ddf0ebfc5 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift @@ -189,9 +189,8 @@ public enum MessageReceiver { // follow the new config. try MessageReceiver.updateDisappearingMessagesConfigurationIfNeeded( db, - threadId: message.threadId, - sender: message.sender, - sentTimestamp: message.sentTimestamp, + message: message, + openGroupId: openGroupId, proto: proto ) @@ -319,12 +318,15 @@ public enum MessageReceiver { internal static func updateDisappearingMessagesConfigurationIfNeeded( _ db: Database, - threadId: String?, - sender: String?, - sentTimestamp: UInt64?, + message: Message, + openGroupId: String?, proto: SNProtoContent ) throws { - guard let threadId = threadId, let sender = sender, proto.hasLastDisappearingMessageChangeTimestamp else { return } + guard + let (threadId, _) = MessageReceiver.threadInfo(db, message: message, openGroupId: openGroupId), + let sender = message.sender, + proto.hasLastDisappearingMessageChangeTimestamp + else { return } let protoLastChangeTimestampMs: Int64 = Int64(proto.lastDisappearingMessageChangeTimestamp) let localConfig: DisappearingMessagesConfiguration = try DisappearingMessagesConfiguration @@ -355,7 +357,7 @@ public enum MessageReceiver { nil ) ), - timestampMs: Int64(sentTimestamp ?? 0) + timestampMs: protoLastChangeTimestampMs ).inserted(db) try remoteConfig.save(db)