From 93d9f51140c50024172e49a365ebe5a9e069d40c Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Fri, 10 Feb 2023 12:11:32 +1100 Subject: [PATCH] Included a blinded id comparison for adding the delete action --- .../Conversations/Context Menu/ContextMenuVC+Action.swift | 2 ++ Session/Conversations/ConversationVC+Interaction.swift | 1 + Session/Conversations/ConversationViewModel.swift | 8 +++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Session/Conversations/Context Menu/ContextMenuVC+Action.swift b/Session/Conversations/Context Menu/ContextMenuVC+Action.swift index 904978ab3..91dfd9c19 100644 --- a/Session/Conversations/Context Menu/ContextMenuVC+Action.swift +++ b/Session/Conversations/Context Menu/ContextMenuVC+Action.swift @@ -111,6 +111,7 @@ extension ContextMenuVC { for cellViewModel: MessageViewModel, recentEmojis: [EmojiWithSkinTones], currentUserPublicKey: String, + currentUserBlindedPublicKey: String?, currentUserIsOpenGroupModerator: Bool, currentThreadIsMessageRequest: Bool, delegate: ContextMenuActionDelegate? @@ -165,6 +166,7 @@ extension ContextMenuVC { cellViewModel.threadVariant != .openGroup || currentUserIsOpenGroupModerator || cellViewModel.authorId == currentUserPublicKey || + cellViewModel.authorId == currentUserBlindedPublicKey || cellViewModel.state == .failed ) let canBan: Bool = ( diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index c6794329a..ca2ae2218 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -778,6 +778,7 @@ extension ConversationVC: for: cellViewModel, recentEmojis: (self.viewModel.threadData.recentReactionEmoji ?? []).compactMap { EmojiWithSkinTones(rawValue: $0) }, currentUserPublicKey: self.viewModel.threadData.currentUserPublicKey, + currentUserBlindedPublicKey: self.viewModel.threadData.currentUserBlindedPublicKey, currentUserIsOpenGroupModerator: OpenGroupManager.isUserModeratorOrAdmin( self.viewModel.threadData.currentUserPublicKey, for: self.viewModel.threadData.openGroupRoomToken, diff --git a/Session/Conversations/ConversationViewModel.swift b/Session/Conversations/ConversationViewModel.swift index 92e55e45b..2249474ad 100644 --- a/Session/Conversations/ConversationViewModel.swift +++ b/Session/Conversations/ConversationViewModel.swift @@ -115,6 +115,7 @@ public class ConversationViewModel: OWSAudioPlayerDelegate { } ) ) + .populatingCurrentUserBlindedKey() /// This is all the data the screen needs to populate itself, please see the following link for tips to help optimise /// performance https://github.com/groue/GRDB.swift#valueobservation-performance @@ -130,7 +131,7 @@ public class ConversationViewModel: OWSAudioPlayerDelegate { private func setupObservableThreadData(for threadId: String) -> ValueObservation>> { return ValueObservation - .trackingConstantRegion { db -> SessionThreadViewModel? in + .trackingConstantRegion { [weak self] db -> SessionThreadViewModel? in let userPublicKey: String = getUserHexEncodedPublicKey(db) let recentReactionEmoji: [String] = try Emoji.getRecent(db, withDefaultEmoji: true) let threadViewModel: SessionThreadViewModel? = try SessionThreadViewModel @@ -139,6 +140,11 @@ public class ConversationViewModel: OWSAudioPlayerDelegate { return threadViewModel .map { $0.with(recentReactionEmoji: recentReactionEmoji) } + .map { viewModel -> SessionThreadViewModel in + viewModel.populatingCurrentUserBlindedKey( + currentUserBlindedPublicKeyForThisThread: self?.threadData.currentUserBlindedPublicKey + ) + } } .removeDuplicates() }