feat: add capability check for open group emoji reacts
This commit is contained in:
parent
f7a4c92d38
commit
651373234a
|
@ -105,6 +105,7 @@ extension ContextMenuVC {
|
||||||
for cellViewModel: MessageViewModel,
|
for cellViewModel: MessageViewModel,
|
||||||
recentEmojis: [EmojiWithSkinTones],
|
recentEmojis: [EmojiWithSkinTones],
|
||||||
currentUserIsOpenGroupModerator: Bool,
|
currentUserIsOpenGroupModerator: Bool,
|
||||||
|
currentThreadIsMessageRequest: Bool,
|
||||||
delegate: ContextMenuActionDelegate?
|
delegate: ContextMenuActionDelegate?
|
||||||
) -> [Action]? {
|
) -> [Action]? {
|
||||||
// No context items for info messages
|
// No context items for info messages
|
||||||
|
@ -156,6 +157,13 @@ extension ContextMenuVC {
|
||||||
currentUserIsOpenGroupModerator
|
currentUserIsOpenGroupModerator
|
||||||
)
|
)
|
||||||
|
|
||||||
|
let shouldShowEmojiActions: Bool = {
|
||||||
|
if cellViewModel.threadVariant == .openGroup {
|
||||||
|
return OpenGroupManager.isOpenGroupSupport(.reactions, on: cellViewModel.threadOpenGroupServer)
|
||||||
|
}
|
||||||
|
return currentThreadIsMessageRequest
|
||||||
|
}()
|
||||||
|
|
||||||
let generatedActions: [Action] = [
|
let generatedActions: [Action] = [
|
||||||
(canReply ? Action.reply(cellViewModel, delegate) : nil),
|
(canReply ? Action.reply(cellViewModel, delegate) : nil),
|
||||||
(canCopy ? Action.copy(cellViewModel, delegate) : nil),
|
(canCopy ? Action.copy(cellViewModel, delegate) : nil),
|
||||||
|
@ -165,7 +173,7 @@ extension ContextMenuVC {
|
||||||
(canBan ? Action.ban(cellViewModel, delegate) : nil),
|
(canBan ? Action.ban(cellViewModel, delegate) : nil),
|
||||||
(canBan ? Action.banAndDeleteAllMessages(cellViewModel, delegate) : nil),
|
(canBan ? Action.banAndDeleteAllMessages(cellViewModel, delegate) : nil),
|
||||||
]
|
]
|
||||||
.appending(contentsOf: recentEmojis.map { Action.react(cellViewModel, $0, delegate) })
|
.appending(contentsOf: (shouldShowEmojiActions ? recentEmojis : []).map { Action.react(cellViewModel, $0, delegate) })
|
||||||
.appending(Action.emojiPlusButton(cellViewModel, delegate))
|
.appending(Action.emojiPlusButton(cellViewModel, delegate))
|
||||||
.compactMap { $0 }
|
.compactMap { $0 }
|
||||||
|
|
||||||
|
|
|
@ -671,14 +671,13 @@ extension ConversationVC:
|
||||||
contextMenuWindow == nil,
|
contextMenuWindow == nil,
|
||||||
let actions: [ContextMenuVC.Action] = ContextMenuVC.actions(
|
let actions: [ContextMenuVC.Action] = ContextMenuVC.actions(
|
||||||
for: cellViewModel,
|
for: cellViewModel,
|
||||||
recentEmojis: ((self.viewModel.threadData.threadIsMessageRequest == true) ? [] :
|
recentEmojis: (self.viewModel.threadData.recentReactionEmoji ?? []).compactMap { EmojiWithSkinTones(rawValue: $0) },
|
||||||
(self.viewModel.threadData.recentReactionEmoji ?? [])
|
|
||||||
).compactMap { EmojiWithSkinTones(rawValue: $0) },
|
|
||||||
currentUserIsOpenGroupModerator: OpenGroupManager.isUserModeratorOrAdmin(
|
currentUserIsOpenGroupModerator: OpenGroupManager.isUserModeratorOrAdmin(
|
||||||
self.viewModel.threadData.currentUserPublicKey,
|
self.viewModel.threadData.currentUserPublicKey,
|
||||||
for: self.viewModel.threadData.openGroupRoomToken,
|
for: self.viewModel.threadData.openGroupRoomToken,
|
||||||
on: self.viewModel.threadData.openGroupServer
|
on: self.viewModel.threadData.openGroupServer
|
||||||
),
|
),
|
||||||
|
currentThreadIsMessageRequest: (self.viewModel.threadData.threadIsMessageRequest == true),
|
||||||
delegate: self
|
delegate: self
|
||||||
)
|
)
|
||||||
else { return }
|
else { return }
|
||||||
|
@ -1125,7 +1124,9 @@ extension ConversationVC:
|
||||||
Emoji.addRecent(db, emoji: emoji)
|
Emoji.addRecent(db, emoji: emoji)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let openGroup: OpenGroup = try? OpenGroup.fetchOne(db, id: cellViewModel.threadId) {
|
if let openGroup: OpenGroup = try? OpenGroup.fetchOne(db, id: cellViewModel.threadId),
|
||||||
|
OpenGroupManager.isOpenGroupSupport(.reactions, on: openGroup.server)
|
||||||
|
{
|
||||||
// Send reaction to open groups
|
// Send reaction to open groups
|
||||||
guard
|
guard
|
||||||
let openGroupServerMessageId: Int64 = try? Interaction
|
let openGroupServerMessageId: Int64 = try? Interaction
|
||||||
|
|
|
@ -16,11 +16,12 @@ public struct Capability: Codable, FetchableRecord, PersistableRecord, TableReco
|
||||||
|
|
||||||
public enum Variant: Equatable, Hashable, CaseIterable, Codable, DatabaseValueConvertible {
|
public enum Variant: Equatable, Hashable, CaseIterable, Codable, DatabaseValueConvertible {
|
||||||
public static var allCases: [Variant] {
|
public static var allCases: [Variant] {
|
||||||
[.sogs, .blind]
|
[.sogs, .blind, .reactions]
|
||||||
}
|
}
|
||||||
|
|
||||||
case sogs
|
case sogs
|
||||||
case blind
|
case blind
|
||||||
|
case reactions
|
||||||
|
|
||||||
/// Fallback case if the capability isn't supported by this version of the app
|
/// Fallback case if the capability isn't supported by this version of the app
|
||||||
case unsupported(String)
|
case unsupported(String)
|
||||||
|
|
|
@ -740,6 +740,29 @@ public final class OpenGroupManager: NSObject {
|
||||||
|
|
||||||
// MARK: - Convenience
|
// MARK: - Convenience
|
||||||
|
|
||||||
|
/// This method specifies if the given capability is supported on a specified Open Group
|
||||||
|
public static func isOpenGroupSupport(
|
||||||
|
_ capability: Capability.Variant,
|
||||||
|
on server: String?,
|
||||||
|
using dependencies: OGMDependencies = OGMDependencies()
|
||||||
|
) -> Bool {
|
||||||
|
guard let server: String = server else { return false }
|
||||||
|
|
||||||
|
return dependencies.storage
|
||||||
|
.read { db in
|
||||||
|
let capabilities: [Capability.Variant] = (try? Capability
|
||||||
|
.select(.variant)
|
||||||
|
.filter(Capability.Columns.openGroupServer == server)
|
||||||
|
.filter(Capability.Columns.isMissing == false)
|
||||||
|
.asRequest(of: Capability.Variant.self)
|
||||||
|
.fetchAll(db))
|
||||||
|
.defaulting(to: [])
|
||||||
|
|
||||||
|
return capabilities.contains(capability)
|
||||||
|
}
|
||||||
|
.defaulting(to: false)
|
||||||
|
}
|
||||||
|
|
||||||
/// This method specifies if the given publicKey is a moderator or an admin within a specified Open Group
|
/// This method specifies if the given publicKey is a moderator or an admin within a specified Open Group
|
||||||
public static func isUserModeratorOrAdmin(
|
public static func isUserModeratorOrAdmin(
|
||||||
_ publicKey: String,
|
_ publicKey: String,
|
||||||
|
|
Loading…
Reference in New Issue