disappearing message config to proto

pull/941/head
Ryan Zhao 2 years ago
parent 95d065f775
commit 03b3136316

@ -20,6 +20,24 @@ public struct DisappearingMessagesConfiguration: Codable, Identifiable, Equatabl
public enum DisappearingMessageType: Int, Codable, Hashable, DatabaseValueConvertible {
case disappearAfterRead
case disappearAfterSend
init(protoType: SNProtoContent.SNProtoContentExpirationType) {
switch protoType {
case .deleteAfterSend:
self = .disappearAfterSend
case .deleteAfterRead:
self = .disappearAfterRead
}
}
func toProto() -> SNProtoContent.SNProtoContentExpirationType {
switch self {
case .disappearAfterRead:
return .deleteAfterRead
case .disappearAfterSend:
return .deleteAfterSend
}
}
}
public var id: String { threadId } // Identifiable

@ -183,6 +183,19 @@ public final class VisibleMessage: Message {
dataMessage.setReaction(reactionProto)
}
// DisappearingMessagesConfiguration
if let threadId = self.threadId,
let disappearingMessagesConfiguration = try? DisappearingMessagesConfiguration.fetchOne(db, id: threadId)
{
proto.setExpirationTimer(UInt32(disappearingMessagesConfiguration.durationSeconds))
if disappearingMessagesConfiguration.isEnabled,
let type = disappearingMessagesConfiguration.type
{
proto.setExpirationType(type.toProto())
}
}
// Group context
do {
try setGroupContextIfNeeded(db, on: dataMessage)

Loading…
Cancel
Save