mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-06-09 06:23:25 +00:00
core, mobile: logic for enabling disappearing messages (#1588)
* core: logic for enabled for disappearing messages * refactor * update feature enabled in UI
This commit is contained in:
committed by
GitHub
parent
6b8705e9f4
commit
8786e2147a
@@ -305,11 +305,10 @@ ciTimedToTTL timed_ = timed_ >>= \CITimed {ttl} -> Just ttl
|
||||
|
||||
contactCITimedTTL :: Contact -> Maybe Int
|
||||
contactCITimedTTL Contact {mergedPreferences = ContactUserPreferences {timedMessages = ContactUserPreference {enabled, userPreference}}}
|
||||
| forUser enabled && forContact enabled = case userPreference of
|
||||
CUPContact TimedMessagesPreference {ttl = Just t} -> Just t
|
||||
CUPUser TimedMessagesPreference {ttl = Just t} -> Just t
|
||||
_ -> Nothing
|
||||
| forUser enabled && forContact enabled = ttl
|
||||
| otherwise = Nothing
|
||||
where
|
||||
TimedMessagesPreference {ttl} = preference (userPreference :: ContactUserPref TimedMessagesPreference)
|
||||
|
||||
groupCITimedTTL :: GroupInfo -> Maybe Int
|
||||
groupCITimedTTL GroupInfo {fullGroupPreferences = FullGroupPreferences {timedMessages = TimedMessagesGroupPreference {enable, ttl}}}
|
||||
|
||||
@@ -787,10 +787,10 @@ instance ToJSON PrefEnabled where
|
||||
toJSON = J.genericToJSON J.defaultOptions
|
||||
toEncoding = J.genericToEncoding J.defaultOptions
|
||||
|
||||
prefEnabled :: FeatureI f => FeaturePreference f -> FeaturePreference f -> PrefEnabled
|
||||
prefEnabled user contact = case (getField @"allow" user, getField @"allow" contact) of
|
||||
(FAAlways, FANo) -> PrefEnabled {forUser = False, forContact = True}
|
||||
(FANo, FAAlways) -> PrefEnabled {forUser = True, forContact = False}
|
||||
prefEnabled :: FeatureI f => Bool -> FeaturePreference f -> FeaturePreference f -> PrefEnabled
|
||||
prefEnabled asymmetric user contact = case (getField @"allow" user, getField @"allow" contact) of
|
||||
(FAAlways, FANo) -> PrefEnabled {forUser = False, forContact = asymmetric}
|
||||
(FANo, FAAlways) -> PrefEnabled {forUser = asymmetric, forContact = False}
|
||||
(_, FANo) -> PrefEnabled False False
|
||||
(FANo, _) -> PrefEnabled False False
|
||||
_ -> PrefEnabled True True
|
||||
@@ -819,12 +819,14 @@ contactUserPreferences user userPreferences contactPreferences connectedIncognit
|
||||
pref :: FeatureI f => SChatFeature f -> ContactUserPreference (FeaturePreference f)
|
||||
pref f =
|
||||
ContactUserPreference
|
||||
{ enabled = prefEnabled userPref ctPref,
|
||||
{ enabled = prefEnabled (asymmetric f) userPref ctPref,
|
||||
-- incognito contact cannot have default user preference used
|
||||
userPreference = if connectedIncognito then CUPContact ctUserPref else maybe (CUPUser userPref) CUPContact ctUserPref_,
|
||||
contactPreference = ctPref
|
||||
}
|
||||
where
|
||||
asymmetric SCFTimedMessages = False
|
||||
asymmetric _ = True
|
||||
ctUserPref = getPreference f userPreferences
|
||||
ctUserPref_ = chatPrefSel f userPreferences
|
||||
userPref = getPreference f ctUserPrefs
|
||||
|
||||
Reference in New Issue
Block a user