mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-08-28 07:34:16 +00:00
core: don't create group-only feature items in channels (#7220)
This commit is contained in:
@@ -2973,9 +2973,12 @@ createContactsFeatureItems user cts chatDir ciFeature ciOffer getPref = do
|
||||
cup = getContactUserPreference f cups
|
||||
cup' = getContactUserPreference f cups'
|
||||
|
||||
groupFeatures :: GroupInfo -> [AGroupFeature]
|
||||
groupFeatures g = if useRelays' g then channelGroupFeatures else allGroupFeatures
|
||||
|
||||
createGroupFeatureChangedItems :: MsgDirectionI d => User -> ChatDirection 'CTGroup d -> (GroupFeature -> GroupPreference -> Maybe Int -> Maybe GroupMemberRole -> CIContent d) -> GroupInfo -> GroupInfo -> CM ()
|
||||
createGroupFeatureChangedItems user cd ciContent GroupInfo {fullGroupPreferences = gps} GroupInfo {fullGroupPreferences = gps'} =
|
||||
forM_ allGroupFeatures $ \(AGF f) -> do
|
||||
createGroupFeatureChangedItems user cd ciContent GroupInfo {fullGroupPreferences = gps} g'@GroupInfo {fullGroupPreferences = gps'} =
|
||||
forM_ (groupFeatures g') $ \(AGF f) -> do
|
||||
let state = groupFeatureState $ getGroupPreference f gps
|
||||
pref' = getGroupPreference f gps'
|
||||
state'@(_, param', role') = groupFeatureState pref'
|
||||
@@ -2989,8 +2992,8 @@ createGroupFeatureItems :: MsgDirectionI d => User -> ChatDirection 'CTGroup d -
|
||||
createGroupFeatureItems user cd ciContent g = createGroupFeatureItems_ user cd False ciContent g >>= toView . CEvtNewChatItems user
|
||||
|
||||
createGroupFeatureItems_ :: MsgDirectionI d => User -> ChatDirection 'CTGroup d -> ShowGroupAsSender -> (GroupFeature -> GroupPreference -> Maybe Int -> Maybe GroupMemberRole -> CIContent d) -> GroupInfo -> CM [AChatItem]
|
||||
createGroupFeatureItems_ user cd showGroupAsSender ciContent GroupInfo {fullGroupPreferences} =
|
||||
forM allGroupFeatures $ \(AGF f) -> do
|
||||
createGroupFeatureItems_ user cd showGroupAsSender ciContent g@GroupInfo {fullGroupPreferences} =
|
||||
forM (groupFeatures g) $ \(AGF f) -> do
|
||||
let p = getGroupPreference f fullGroupPreferences
|
||||
(_, param, role) = groupFeatureState p
|
||||
createChatItem user cd showGroupAsSender (ciContent (toGroupFeature f) (toGroupPreference p) param role) Nothing Nothing Nothing
|
||||
|
||||
@@ -236,11 +236,8 @@ groupFeatureMemberAllowed' feature role prefs =
|
||||
let pref = getGroupPreference feature prefs
|
||||
in getField @"enable" pref == FEOn && maybe True (role >=) (getField @"role" pref)
|
||||
|
||||
-- TODO: some preferences are channel-only (e.g., comments) and should not generate
|
||||
-- UI items or be configurable in regular groups. Currently they are simply excluded
|
||||
-- from this list. When more channel-only or group-only preferences are added,
|
||||
-- consider adding a scope property to GroupFeatureI (e.g., GFScopeAll | GFScopeChannel | GFScopeGroup)
|
||||
-- and filtering at the call sites in createGroupFeatureItems_ / createGroupFeatureChangedItems.
|
||||
-- Sessions and comments are channel-only features not shown in any client yet,
|
||||
-- so they are omitted from generated feature items entirely.
|
||||
allGroupFeatures :: [AGroupFeature]
|
||||
allGroupFeatures =
|
||||
[ AGF SGFTimedMessages,
|
||||
@@ -255,6 +252,26 @@ allGroupFeatures =
|
||||
AGF SGFSupport
|
||||
]
|
||||
|
||||
-- Channels (public groups) show a subset of group features. Direct messages, voice,
|
||||
-- files, SimpleX links and member reports are group-only and excluded in channels.
|
||||
channelGroupFeatures :: [AGroupFeature]
|
||||
channelGroupFeatures = filter (\(AGF f) -> groupFeatureInChannel (toGroupFeature f)) allGroupFeatures
|
||||
|
||||
groupFeatureInChannel :: GroupFeature -> Bool
|
||||
groupFeatureInChannel = \case
|
||||
GFTimedMessages -> True
|
||||
GFDirectMessages -> False
|
||||
GFFullDelete -> True
|
||||
GFReactions -> True
|
||||
GFVoice -> False
|
||||
GFFiles -> False
|
||||
GFSimplexLinks -> False
|
||||
GFReports -> False
|
||||
GFHistory -> True
|
||||
GFSupport -> True
|
||||
GFSessions -> False
|
||||
GFComments -> False
|
||||
|
||||
groupPrefSel :: SGroupFeature f -> GroupPreferences -> Maybe (GroupFeaturePreference f)
|
||||
groupPrefSel f GroupPreferences {timedMessages, directMessages, fullDelete, reactions, voice, files, simplexLinks, reports, history, support, sessions, comments} = case f of
|
||||
SGFTimedMessages -> timedMessages
|
||||
|
||||
Reference in New Issue
Block a user