diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index ca2ae2218..dfc94c056 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -436,10 +436,17 @@ extension ConversationVC: .filter(id: threadId) .updateAll(db, SessionThread.Columns.shouldBeVisible.set(to: true)) + let authorId: String = { + if let blindedId = self?.viewModel.threadData.currentUserBlindedPublicKey { + return blindedId + } + return self?.viewModel.threadData.currentUserPublicKey ?? getUserHexEncodedPublicKey(db) + }() + // Create the interaction let interaction: Interaction = try Interaction( threadId: threadId, - authorId: getUserHexEncodedPublicKey(db), + authorId: authorId, variant: .standardOutgoing, body: text, timestampMs: sentTimestampMs, diff --git a/SessionMessagingKit/Database/Models/SessionThread.swift b/SessionMessagingKit/Database/Models/SessionThread.swift index ca08aa182..f5d743acf 100644 --- a/SessionMessagingKit/Database/Models/SessionThread.swift +++ b/SessionMessagingKit/Database/Models/SessionThread.swift @@ -322,18 +322,31 @@ public extension SessionThread { ) -> String? { guard threadVariant == .openGroup, - let blindingInfo: (edkeyPair: Box.KeyPair?, publicKey: String?) = Storage.shared.read({ db in + let blindingInfo: (edkeyPair: Box.KeyPair?, publicKey: String?, capabilities: Set) = Storage.shared.read({ db in + struct OpenGroupInfo: Decodable, FetchableRecord { + let publicKey: String? + let server: String? + } + let openGroupInfo: OpenGroupInfo? = try OpenGroup + .filter(id: threadId) + .select(.publicKey, .server) + .asRequest(of: OpenGroupInfo.self) + .fetchOne(db) + return ( Identity.fetchUserEd25519KeyPair(db), - try OpenGroup - .filter(id: threadId) - .select(.publicKey) - .asRequest(of: String.self) - .fetchOne(db) + openGroupInfo?.publicKey, + (try? Capability + .select(.variant) + .filter(Capability.Columns.openGroupServer == openGroupInfo?.server?.lowercased()) + .asRequest(of: Capability.Variant.self) + .fetchSet(db)) + .defaulting(to: []) ) }), let userEdKeyPair: Box.KeyPair = blindingInfo.edkeyPair, - let publicKey: String = blindingInfo.publicKey + let publicKey: String = blindingInfo.publicKey, + blindingInfo.capabilities.isEmpty || blindingInfo.capabilities.contains(.blind) else { return nil } let sodium: Sodium = Sodium() diff --git a/SessionMessagingKit/Sending & Receiving/MessageSender.swift b/SessionMessagingKit/Sending & Receiving/MessageSender.swift index ee0f23da7..80c0f5ab3 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageSender.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageSender.swift @@ -597,8 +597,6 @@ public final class MessageSender { // real message has no use when we delete a message. It is OK to let it be. try interaction.with( serverHash: message.serverHash, - // Update the authorId if blinded id is enabled, otherwise it will remain the same - authorId: message.sender, // Track the open group server message ID and update server timestamp (use server // timestamp for open group messages otherwise the quote messages may not be able // to be found by the timestamp on other devices diff --git a/SessionMessagingKit/Shared Models/MessageViewModel.swift b/SessionMessagingKit/Shared Models/MessageViewModel.swift index a04fd937b..c0a3df33e 100644 --- a/SessionMessagingKit/Shared Models/MessageViewModel.swift +++ b/SessionMessagingKit/Shared Models/MessageViewModel.swift @@ -718,8 +718,12 @@ public extension MessageViewModel { \(interactionAttachment[.attachmentId]) AS \(Quote.Columns.attachmentId) FROM \(Quote.self) LEFT JOIN \(Interaction.self) ON ( - (\(quote[.authorId]) = \(interaction[.authorId]) OR - \(quote[.authorId]) = \(blindedPublicKey ?? "") AND \(userPublicKey) = \(interaction[.authorId]) ) AND + ( + \(quote[.authorId]) = \(interaction[.authorId]) OR ( + \(quote[.authorId]) = \(blindedPublicKey ?? "") AND + \(userPublicKey) = \(interaction[.authorId]) + ) + ) AND \(quote[.timestampMs]) = \(interaction[.timestampMs]) ) LEFT JOIN \(InteractionAttachment.self) ON \(interaction[.id]) = \(interactionAttachment[.interactionId])