feat: persist open group reactions into local database

pull/638/head
ryanzhao 3 years ago
parent cd08c792d3
commit 30e48209e2

@ -90,4 +90,17 @@ public extension Reaction {
count: (count ?? self.count) count: (count ?? self.count)
) )
} }
func with(
interactionId: Int64?
) -> Reaction {
return Reaction(
interactionId: (interactionId ?? self.interactionId),
serverHash: self.serverHash,
timestampMs: self.timestampMs,
authorId: self.authorId,
emoji: self.emoji,
count: self.count
)
}
} }

@ -537,6 +537,7 @@ public final class OpenGroupManager: NSObject {
message: messageInfo.message, message: messageInfo.message,
associatedWithProto: try SNProtoContent.parseData(messageInfo.serializedProtoData), associatedWithProto: try SNProtoContent.parseData(messageInfo.serializedProtoData),
openGroupId: openGroup.id, openGroupId: openGroup.id,
openGroupReactions: messageInfo.reactions,
isBackgroundPoll: isBackgroundPoll, isBackgroundPoll: isBackgroundPoll,
dependencies: dependencies dependencies: dependencies
) )

@ -12,6 +12,7 @@ extension MessageReceiver {
message: VisibleMessage, message: VisibleMessage,
associatedWithProto proto: SNProtoContent, associatedWithProto proto: SNProtoContent,
openGroupId: String?, openGroupId: String?,
openGroupReactions: [Reaction] = [],
isBackgroundPoll: Bool, isBackgroundPoll: Bool,
dependencies: Dependencies = Dependencies() dependencies: Dependencies = Dependencies()
) throws -> Int64 { ) throws -> Int64 {
@ -140,6 +141,10 @@ extension MessageReceiver {
return recipientParts[2] return recipientParts[2]
}() }()
).inserted(db) ).inserted(db)
for reaction in openGroupReactions {
try reaction.with(interactionId: interaction.id).insert(db)
}
} }
catch { catch {
switch error { switch error {

@ -180,6 +180,7 @@ public enum MessageReceiver {
message: Message, message: Message,
associatedWithProto proto: SNProtoContent, associatedWithProto proto: SNProtoContent,
openGroupId: String?, openGroupId: String?,
openGroupReactions: [Reaction] = [],
isBackgroundPoll: Bool, isBackgroundPoll: Bool,
dependencies: SMKDependencies = SMKDependencies() dependencies: SMKDependencies = SMKDependencies()
) throws { ) throws {
@ -217,6 +218,7 @@ public enum MessageReceiver {
message: message, message: message,
associatedWithProto: proto, associatedWithProto: proto,
openGroupId: openGroupId, openGroupId: openGroupId,
openGroupReactions: openGroupReactions,
isBackgroundPoll: isBackgroundPoll isBackgroundPoll: isBackgroundPoll
) )

Loading…
Cancel
Save