fix an issue where note to self may show expiration update control messages which should be removed already.

pull/731/head
Ryan ZHAO 6 months ago
parent 084586e6ba
commit 87309ccba1

@ -192,7 +192,7 @@ extension MessageReceiver {
.init(protoType: proto.expirationType) : .init(protoType: proto.expirationType) :
.unknown .unknown
) )
let remoteConfig: DisappearingMessagesConfiguration = localConfig.with( let updatedConfig: DisappearingMessagesConfiguration = localConfig.with(
isEnabled: (durationSeconds != 0), isEnabled: (durationSeconds != 0),
durationSeconds: durationSeconds, durationSeconds: durationSeconds,
type: disappearingType type: disappearingType
@ -201,7 +201,7 @@ extension MessageReceiver {
switch threadVariant { switch threadVariant {
case .legacyGroup: case .legacyGroup:
// Only change the config when it is changed from the admin // Only change the config when it is changed from the admin
if localConfig != remoteConfig && if localConfig != updatedConfig &&
(try? GroupMember (try? GroupMember
.filter(GroupMember.Columns.groupId == threadId) .filter(GroupMember.Columns.groupId == threadId)
.filter(GroupMember.Columns.profileId == sender) .filter(GroupMember.Columns.profileId == sender)
@ -209,17 +209,24 @@ extension MessageReceiver {
.asRequest(of: GroupMember.Role.self) .asRequest(of: GroupMember.Role.self)
.fetchOne(db)) == .admin .fetchOne(db)) == .admin
{ {
_ = try remoteConfig.save(db) _ = try updatedConfig.save(db)
try SessionUtil try SessionUtil
.update( .update(
db, db,
groupPublicKey: threadId, groupPublicKey: threadId,
disappearingConfig: remoteConfig disappearingConfig: updatedConfig
) )
} }
fallthrough fallthrough
case .contact: case .contact:
// Handle Note to Self:
// We sync disappearing messages config through shared config message only.
// If the updated config from this message is different from local config,
// this control message should already be removed.
if threadId == getUserHexEncodedPublicKey(db) && updatedConfig != localConfig {
return
}
_ = try DisappearingMessagesConfiguration.insertControlMessage( _ = try DisappearingMessagesConfiguration.insertControlMessage(
db, db,
threadId: threadId, threadId: threadId,
@ -227,7 +234,7 @@ extension MessageReceiver {
authorId: sender, authorId: sender,
timestampMs: Int64(timestampMs), timestampMs: Int64(timestampMs),
serverHash: message.serverHash, serverHash: message.serverHash,
updatedConfiguration: remoteConfig, updatedConfiguration: updatedConfig,
isPreviousOff: !localConfig.isEnabled isPreviousOff: !localConfig.isEnabled
) )
default: default:

@ -133,11 +133,11 @@ internal extension SessionUtil {
.defaulting(to: DisappearingMessagesConfiguration.defaultWith(userPublicKey)) .defaulting(to: DisappearingMessagesConfiguration.defaultWith(userPublicKey))
if targetConfig != localConfig { if targetConfig != localConfig {
_ = try localConfig.with( _ = try targetConfig.save(db)
isEnabled: targetConfig.isEnabled, _ = try Interaction
durationSeconds: targetConfig.durationSeconds, .filter(Interaction.Columns.threadId == userPublicKey)
type: targetConfig.type .filter(Interaction.Columns.variant == Interaction.Variant.infoDisappearingMessagesUpdate)
).save(db) .deleteAll(db)
} }
// Update settings if needed // Update settings if needed

Loading…
Cancel
Save