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(
|
let sortId = Reaction.getSortId(
|
||||||
db,
|
db,
|
||||||
interactionId: cellViewModel.id,
|
interactionId: cellViewModel.id,
|
||||||
emoji: emoji,
|
emoji: emoji
|
||||||
timestamp: sentTimestamp
|
|
||||||
)
|
)
|
||||||
try Reaction(
|
try Reaction(
|
||||||
interactionId: cellViewModel.id,
|
interactionId: cellViewModel.id,
|
||||||
|
|
|
@ -108,8 +108,7 @@ public extension Reaction {
|
||||||
static func getSortId(
|
static func getSortId(
|
||||||
_ db: Database,
|
_ db: Database,
|
||||||
interactionId: Int64,
|
interactionId: Int64,
|
||||||
emoji: String,
|
emoji: String
|
||||||
timestamp: Int64
|
|
||||||
) -> Int64 {
|
) -> Int64 {
|
||||||
if let existingSortId: Int64 = try? Reaction
|
if let existingSortId: Int64 = try? Reaction
|
||||||
.select(Columns.sortId)
|
.select(Columns.sortId)
|
||||||
|
@ -121,6 +120,15 @@ public extension Reaction {
|
||||||
return existingSortId
|
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()
|
dependencies: SMKDependencies = SMKDependencies()
|
||||||
) -> [Reaction] {
|
) -> [Reaction] {
|
||||||
var results: [Reaction] = []
|
var results: [Reaction] = []
|
||||||
guard let reactions = message.reactions else { return results }
|
|
||||||
let userPublicKey: String = getUserHexEncodedPublicKey(db)
|
let userPublicKey: String = getUserHexEncodedPublicKey(db)
|
||||||
let blindedUserPublicKey: String? = SessionThread
|
let blindedUserPublicKey: String? = SessionThread
|
||||||
.getUserHexEncodedBlindedKey(
|
.getUserHexEncodedBlindedKey(
|
||||||
threadId: openGroupId,
|
threadId: openGroupId,
|
||||||
threadVariant: .openGroup
|
threadVariant: .openGroup
|
||||||
)
|
)
|
||||||
for (encodedEmoji, rawReaction) in reactions {
|
for (encodedEmoji, rawReaction) in message.reactions {
|
||||||
if let emoji = encodedEmoji.removingPercentEncoding,
|
if let emoji = encodedEmoji.removingPercentEncoding,
|
||||||
rawReaction.count > 0,
|
rawReaction.count > 0,
|
||||||
let reactors = rawReaction.reactors
|
let reactors = rawReaction.reactors
|
||||||
{
|
{
|
||||||
var count = rawReaction.count
|
var count = rawReaction.count
|
||||||
let sortId: Int64 = Int64(floor((rawReaction.first * 1000)))
|
let sortId: Int64 = rawReaction.index
|
||||||
for reactor in reactors {
|
for reactor in reactors {
|
||||||
if reactor == blindedUserPublicKey { continue } // Will add a reaction for this case outside of the loop
|
if reactor == blindedUserPublicKey { continue } // Will add a reaction for this case outside of the loop
|
||||||
let reaction = Reaction(
|
let reaction = Reaction(
|
||||||
|
|
|
@ -40,16 +40,16 @@ extension OpenGroupAPI {
|
||||||
case count
|
case count
|
||||||
case reactors
|
case reactors
|
||||||
case you
|
case you
|
||||||
case first
|
case index
|
||||||
}
|
}
|
||||||
|
|
||||||
public let count: Int64
|
public let count: Int64
|
||||||
public let reactors: [String]?
|
public let reactors: [String]?
|
||||||
public let you: Bool
|
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),
|
whisperTo: try? container.decode(String.self, forKey: .whisperTo),
|
||||||
base64EncodedData: maybeBase64EncodedData,
|
base64EncodedData: maybeBase64EncodedData,
|
||||||
base64EncodedSignature: maybeBase64EncodedSignature,
|
base64EncodedSignature: maybeBase64EncodedSignature,
|
||||||
reactions: maybeReactions
|
reactions: maybeReactions ?? [:]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ extension OpenGroupAPI.Message.Reaction {
|
||||||
count: try container.decode(Int64.self, forKey: .count),
|
count: try container.decode(Int64.self, forKey: .count),
|
||||||
reactors: try? container.decode([String].self, forKey: .reactors),
|
reactors: try? container.decode([String].self, forKey: .reactors),
|
||||||
you: (try? container.decode(Bool.self, forKey: .you)) ?? false,
|
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
|
// Process the messages
|
||||||
sortedMessages.forEach { message in
|
sortedMessages.forEach { message in
|
||||||
if message.base64EncodedData == nil && message.reactions == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle messages
|
// Handle messages
|
||||||
if let base64EncodedString: String = message.base64EncodedData,
|
if let base64EncodedString: String = message.base64EncodedData,
|
||||||
let data = Data(base64Encoded: base64EncodedString)
|
let data = Data(base64Encoded: base64EncodedString)
|
||||||
|
@ -560,27 +556,25 @@ public final class OpenGroupManager: NSObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle reactions
|
// Handle reactions
|
||||||
if message.reactions != nil {
|
do {
|
||||||
do {
|
let reactions: [Reaction] = Message.processRawReceivedReactions(
|
||||||
let reactions: [Reaction] = Message.processRawReceivedReactions(
|
db,
|
||||||
|
openGroupId: openGroup.id,
|
||||||
|
message: message,
|
||||||
|
dependencies: dependencies
|
||||||
|
)
|
||||||
|
|
||||||
|
if !reactions.isEmpty {
|
||||||
|
try MessageReceiver.handleOpenGroupReactions(
|
||||||
db,
|
db,
|
||||||
openGroupId: openGroup.id,
|
openGroupMessageServerId: message.id,
|
||||||
message: message,
|
openGroupReactions: reactions
|
||||||
dependencies: dependencies
|
|
||||||
)
|
)
|
||||||
|
|
||||||
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
|
// Handle any deletions that are needed
|
||||||
|
|
|
@ -327,8 +327,7 @@ extension MessageReceiver {
|
||||||
let sortId = Reaction.getSortId(
|
let sortId = Reaction.getSortId(
|
||||||
db,
|
db,
|
||||||
interactionId: interactionId,
|
interactionId: interactionId,
|
||||||
emoji: reaction.emoji,
|
emoji: reaction.emoji
|
||||||
timestamp: Int64(messageSentTimestamp * 1000)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
switch reaction.kind {
|
switch reaction.kind {
|
||||||
|
|
Loading…
Reference in New Issue