mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-08-28 19:08:15 +00:00
core: chat items for group preferences (#1402)
* core: chat items for group preferences * chat items for group preference changes and sent item for contact/user prerences changes * prohibited features, tests * enable all tests * fix
This commit is contained in:
@@ -560,6 +560,8 @@ data CIContent (d :: MsgDirection) where
|
||||
CISndConnEvent :: SndConnEvent -> CIContent 'MDSnd
|
||||
CIRcvChatFeature :: ChatFeature -> PrefEnabled -> CIContent 'MDRcv
|
||||
CISndChatFeature :: ChatFeature -> PrefEnabled -> CIContent 'MDSnd
|
||||
CIRcvGroupFeature :: ChatFeature -> GroupPreference -> CIContent 'MDRcv
|
||||
CISndGroupFeature :: ChatFeature -> GroupPreference -> CIContent 'MDSnd
|
||||
CIRcvChatFeatureRejected :: ChatFeature -> CIContent 'MDRcv
|
||||
-- ^ This type is used both in API and in DB, so we use different JSON encodings for the database and for the API
|
||||
-- ! ^ Nested sum types also have to use different encodings for database and API
|
||||
@@ -714,6 +716,8 @@ ciContentToText = \case
|
||||
CISndConnEvent event -> sndConnEventToText event
|
||||
CIRcvChatFeature feature enabled -> chatFeatureToText feature <> ": " <> prefEnabledToText enabled
|
||||
CISndChatFeature feature enabled -> chatFeatureToText feature <> ": " <> prefEnabledToText enabled
|
||||
CIRcvGroupFeature feature pref -> chatFeatureToText feature <> ": " <> groupPrefToText pref
|
||||
CISndGroupFeature feature pref -> chatFeatureToText feature <> ": " <> groupPrefToText pref
|
||||
CIRcvChatFeatureRejected feature -> chatFeatureToText feature <> ": received, prohibited"
|
||||
|
||||
msgIntegrityError :: MsgErrorType -> Text
|
||||
@@ -767,6 +771,8 @@ data JSONCIContent
|
||||
| JCISndConnEvent {sndConnEvent :: SndConnEvent}
|
||||
| JCIRcvChatFeature {feature :: ChatFeature, enabled :: PrefEnabled}
|
||||
| JCISndChatFeature {feature :: ChatFeature, enabled :: PrefEnabled}
|
||||
| JCIRcvGroupFeature {feature :: ChatFeature, preference :: GroupPreference}
|
||||
| JCISndGroupFeature {feature :: ChatFeature, preference :: GroupPreference}
|
||||
| JCIRcvChatFeatureRejected {feature :: ChatFeature}
|
||||
deriving (Generic)
|
||||
|
||||
@@ -794,6 +800,8 @@ jsonCIContent = \case
|
||||
CISndConnEvent sndConnEvent -> JCISndConnEvent {sndConnEvent}
|
||||
CIRcvChatFeature feature enabled -> JCIRcvChatFeature {feature, enabled}
|
||||
CISndChatFeature feature enabled -> JCISndChatFeature {feature, enabled}
|
||||
CIRcvGroupFeature feature preference -> JCIRcvGroupFeature {feature, preference}
|
||||
CISndGroupFeature feature preference -> JCISndGroupFeature {feature, preference}
|
||||
CIRcvChatFeatureRejected feature -> JCIRcvChatFeatureRejected {feature}
|
||||
|
||||
aciContentJSON :: JSONCIContent -> ACIContent
|
||||
@@ -813,6 +821,8 @@ aciContentJSON = \case
|
||||
JCISndConnEvent {sndConnEvent} -> ACIContent SMDSnd $ CISndConnEvent sndConnEvent
|
||||
JCIRcvChatFeature {feature, enabled} -> ACIContent SMDRcv $ CIRcvChatFeature feature enabled
|
||||
JCISndChatFeature {feature, enabled} -> ACIContent SMDSnd $ CISndChatFeature feature enabled
|
||||
JCIRcvGroupFeature {feature, preference} -> ACIContent SMDRcv $ CIRcvGroupFeature feature preference
|
||||
JCISndGroupFeature {feature, preference} -> ACIContent SMDSnd $ CISndGroupFeature feature preference
|
||||
JCIRcvChatFeatureRejected {feature} -> ACIContent SMDRcv $ CIRcvChatFeatureRejected feature
|
||||
|
||||
-- platform independent
|
||||
@@ -832,6 +842,8 @@ data DBJSONCIContent
|
||||
| DBJCISndConnEvent {sndConnEvent :: DBSndConnEvent}
|
||||
| DBJCIRcvChatFeature {feature :: ChatFeature, enabled :: PrefEnabled}
|
||||
| DBJCISndChatFeature {feature :: ChatFeature, enabled :: PrefEnabled}
|
||||
| DBJCIRcvGroupFeature {feature :: ChatFeature, preference :: GroupPreference}
|
||||
| DBJCISndGroupFeature {feature :: ChatFeature, preference :: GroupPreference}
|
||||
| DBJCIRcvChatFeatureRejected {feature :: ChatFeature}
|
||||
deriving (Generic)
|
||||
|
||||
@@ -859,6 +871,8 @@ dbJsonCIContent = \case
|
||||
CISndConnEvent sce -> DBJCISndConnEvent $ SCE sce
|
||||
CIRcvChatFeature feature enabled -> DBJCIRcvChatFeature {feature, enabled}
|
||||
CISndChatFeature feature enabled -> DBJCISndChatFeature {feature, enabled}
|
||||
CIRcvGroupFeature feature preference -> DBJCIRcvGroupFeature {feature, preference}
|
||||
CISndGroupFeature feature preference -> DBJCISndGroupFeature {feature, preference}
|
||||
CIRcvChatFeatureRejected feature -> DBJCIRcvChatFeatureRejected {feature}
|
||||
|
||||
aciContentDBJSON :: DBJSONCIContent -> ACIContent
|
||||
@@ -878,6 +892,8 @@ aciContentDBJSON = \case
|
||||
DBJCISndConnEvent (SCE sce) -> ACIContent SMDSnd $ CISndConnEvent sce
|
||||
DBJCIRcvChatFeature {feature, enabled} -> ACIContent SMDRcv $ CIRcvChatFeature feature enabled
|
||||
DBJCISndChatFeature {feature, enabled} -> ACIContent SMDSnd $ CISndChatFeature feature enabled
|
||||
DBJCIRcvGroupFeature {feature, preference} -> ACIContent SMDRcv $ CIRcvGroupFeature feature preference
|
||||
DBJCISndGroupFeature {feature, preference} -> ACIContent SMDSnd $ CISndGroupFeature feature preference
|
||||
DBJCIRcvChatFeatureRejected {feature} -> ACIContent SMDRcv $ CIRcvChatFeatureRejected feature
|
||||
|
||||
data CICallStatus
|
||||
|
||||
@@ -442,6 +442,9 @@ data GroupPreference = GroupPreference
|
||||
{enable :: GroupFeatureEnabled}
|
||||
deriving (Eq, Show, Generic, FromJSON)
|
||||
|
||||
groupPrefToText :: GroupPreference -> Text
|
||||
groupPrefToText GroupPreference {enable} = safeDecodeUtf8 $ strEncode enable
|
||||
|
||||
instance ToJSON GroupPreference where toEncoding = J.genericToEncoding J.defaultOptions
|
||||
|
||||
data FeatureAllowed
|
||||
|
||||
@@ -799,16 +799,10 @@ viewGroupUpdated
|
||||
prefs = mapMaybe viewPref allChatFeatures
|
||||
viewPref pt
|
||||
| pref gps == pref gps' = Nothing
|
||||
| otherwise = Just $ plain (chatPrefName pt) <> " enabled: " <> viewGroupPreference (pref gps')
|
||||
| otherwise = Just $ plain (chatPrefName pt) <> " enabled: " <> plain (groupPrefToText $ pref gps')
|
||||
where
|
||||
pref pss = getGroupPreference pt $ mergeGroupPreferences pss
|
||||
|
||||
viewGroupPreference :: GroupPreference -> StyledString
|
||||
viewGroupPreference = \case
|
||||
GroupPreference {enable} -> case enable of
|
||||
FEOn -> "on"
|
||||
FEOff -> "off"
|
||||
|
||||
viewContactAliasUpdated :: Contact -> [StyledString]
|
||||
viewContactAliasUpdated Contact {localDisplayName = n, profile = LocalProfile {localAlias}}
|
||||
| localAlias == "" = ["contact " <> ttyContact n <> " alias removed"]
|
||||
|
||||
Reference in New Issue
Block a user