update sortId logic after open group reaction index
This commit is contained in:
parent
91afad99d5
commit
7383ddad04
|
@ -1088,8 +1088,7 @@ extension ConversationVC:
|
|||
let sortId = Reaction.getSortId(
|
||||
db,
|
||||
interactionId: cellViewModel.id,
|
||||
emoji: emoji,
|
||||
timestamp: sentTimestamp
|
||||
emoji: emoji
|
||||
)
|
||||
try Reaction(
|
||||
interactionId: cellViewModel.id,
|
||||
|
|
|
@ -108,8 +108,7 @@ public extension Reaction {
|
|||
static func getSortId(
|
||||
_ db: Database,
|
||||
interactionId: Int64,
|
||||
emoji: String,
|
||||
timestamp: Int64
|
||||
emoji: String
|
||||
) -> Int64 {
|
||||
if let existingSortId: Int64 = try? Reaction
|
||||
.select(Columns.sortId)
|
||||
|
@ -121,6 +120,15 @@ public extension Reaction {
|
|||
return existingSortId
|
||||
}
|
||||
|
||||
return timestamp
|
||||
if let existingLargestSortId: Int64 = try? Reaction
|
||||
.select(max(Columns.sortId))
|
||||
.filter(Columns.interactionId == interactionId)
|
||||
.asRequest(of: Int64.self)
|
||||
.fetchOne(db)
|
||||
{
|
||||
return existingLargestSortId + 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -356,20 +356,19 @@ public extension Message {
|
|||
dependencies: SMKDependencies = SMKDependencies()
|
||||
) -> [Reaction] {
|
||||
var results: [Reaction] = []
|
||||
guard let reactions = message.reactions else { return results }
|
||||
let userPublicKey: String = getUserHexEncodedPublicKey(db)
|
||||
let blindedUserPublicKey: String? = SessionThread
|
||||
.getUserHexEncodedBlindedKey(
|
||||
threadId: openGroupId,
|
||||
threadVariant: .openGroup
|
||||
)
|
||||
for (encodedEmoji, rawReaction) in reactions {
|
||||
for (encodedEmoji, rawReaction) in message.reactions {
|
||||
if let emoji = encodedEmoji.removingPercentEncoding,
|
||||
rawReaction.count > 0,
|
||||
let reactors = rawReaction.reactors
|
||||
{
|
||||
var count = rawReaction.count
|
||||
let sortId: Int64 = Int64(floor((rawReaction.first * 1000)))
|
||||
let sortId: Int64 = rawReaction.index
|
||||
for reactor in reactors {
|
||||
if reactor == blindedUserPublicKey { continue } // Will add a reaction for this case outside of the loop
|
||||
let reaction = Reaction(
|
||||
|
|
|
@ -40,16 +40,16 @@ extension OpenGroupAPI {
|
|||
case count
|
||||
case reactors
|
||||
case you
|
||||
case first
|
||||
case index
|
||||
}
|
||||
|
||||
public let count: Int64
|
||||
public let reactors: [String]?
|
||||
public let you: Bool
|
||||
public let first: TimeInterval
|
||||
public let index: Int64
|
||||
}
|
||||
|
||||
public let reactions: [String:Reaction]?
|
||||
public let reactions: [String:Reaction]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ extension OpenGroupAPI.Message {
|
|||
whisperTo: try? container.decode(String.self, forKey: .whisperTo),
|
||||
base64EncodedData: maybeBase64EncodedData,
|
||||
base64EncodedSignature: maybeBase64EncodedSignature,
|
||||
reactions: maybeReactions
|
||||
reactions: maybeReactions ?? [:]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ extension OpenGroupAPI.Message.Reaction {
|
|||
count: try container.decode(Int64.self, forKey: .count),
|
||||
reactors: try? container.decode([String].self, forKey: .reactors),
|
||||
you: (try? container.decode(Bool.self, forKey: .you)) ?? false,
|
||||
first: ((try? container.decode(TimeInterval.self, forKey: .first)) ?? Date().timeIntervalSince1970)
|
||||
index: (try container.decode(Int64.self, forKey: .index))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -515,10 +515,6 @@ public final class OpenGroupManager: NSObject {
|
|||
|
||||
// Process the messages
|
||||
sortedMessages.forEach { message in
|
||||
if message.base64EncodedData == nil && message.reactions == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Handle messages
|
||||
if let base64EncodedString: String = message.base64EncodedData,
|
||||
let data = Data(base64Encoded: base64EncodedString)
|
||||
|
@ -560,27 +556,25 @@ public final class OpenGroupManager: NSObject {
|
|||
}
|
||||
|
||||
// Handle reactions
|
||||
if message.reactions != nil {
|
||||
do {
|
||||
let reactions: [Reaction] = Message.processRawReceivedReactions(
|
||||
do {
|
||||
let reactions: [Reaction] = Message.processRawReceivedReactions(
|
||||
db,
|
||||
openGroupId: openGroup.id,
|
||||
message: message,
|
||||
dependencies: dependencies
|
||||
)
|
||||
|
||||
if !reactions.isEmpty {
|
||||
try MessageReceiver.handleOpenGroupReactions(
|
||||
db,
|
||||
openGroupId: openGroup.id,
|
||||
message: message,
|
||||
dependencies: dependencies
|
||||
openGroupMessageServerId: message.id,
|
||||
openGroupReactions: reactions
|
||||
)
|
||||
|
||||
if !reactions.isEmpty {
|
||||
try MessageReceiver.handleOpenGroupReactions(
|
||||
db,
|
||||
openGroupMessageServerId: message.id,
|
||||
openGroupReactions: reactions
|
||||
)
|
||||
}
|
||||
}
|
||||
catch {
|
||||
SNLog("Couldn't handle open group reactions due to error: \(error).")
|
||||
}
|
||||
}
|
||||
catch {
|
||||
SNLog("Couldn't handle open group reactions due to error: \(error).")
|
||||
}
|
||||
}
|
||||
|
||||
// Handle any deletions that are needed
|
||||
|
|
|
@ -327,8 +327,7 @@ extension MessageReceiver {
|
|||
let sortId = Reaction.getSortId(
|
||||
db,
|
||||
interactionId: interactionId,
|
||||
emoji: reaction.emoji,
|
||||
timestamp: Int64(messageSentTimestamp * 1000)
|
||||
emoji: reaction.emoji
|
||||
)
|
||||
|
||||
switch reaction.kind {
|
||||
|
|
Loading…
Reference in New Issue