terminal: set voice message preferences (#1447)

* terminal: set voice message preferences

* enable all tests
This commit is contained in:
Evgeny Poberezkin
2022-11-27 13:54:34 +00:00
committed by GitHub
parent 7f0355ec67
commit 8af0229f52
5 changed files with 133 additions and 24 deletions
+4 -1
View File
@@ -250,6 +250,9 @@ data ChatCommand
| ShowProfile
| UpdateProfile ContactName Text
| UpdateProfileImage (Maybe ImageData)
| SetUserFeature ChatFeature FeatureAllowed
| SetContactFeature ChatFeature ContactName (Maybe FeatureAllowed)
| SetGroupFeature ChatFeature GroupName GroupFeatureEnabled
| QuitChat
| ShowVersion
| DebugLocks
@@ -536,7 +539,7 @@ data ChatErrorType
| CEFileImageType {filePath :: FilePath}
| CEFileImageSize {filePath :: FilePath}
| CEFileNotReceived {fileId :: FileTransferId}
| CEFileLargeSentInline {fileId :: FileTransferId}
| CEInlineFileProhibited {fileId :: FileTransferId}
| CEInvalidQuote
| CEInvalidChatItemUpdate
| CEInvalidChatItemDelete
+26
View File
@@ -303,6 +303,14 @@ instance PreferenceI FullPreferences where
CFVoice -> voice
{-# INLINE getPreference #-}
setPreference :: ChatFeature -> Maybe FeatureAllowed -> Maybe Preferences -> Preferences
setPreference f allow_ prefs_ =
let prefs = toChatPrefs $ mergePreferences Nothing prefs_
pref = (\allow -> (getPreference f prefs :: Preference) {allow}) <$> allow_
in case f of
CFVoice -> prefs {voice = pref}
CFFullDelete -> prefs {fullDelete = pref}
-- collection of optional chat preferences for the user and the contact
data Preferences = Preferences
{ fullDelete :: Maybe Preference,
@@ -361,6 +369,14 @@ instance ToField GroupPreferences where
instance FromField GroupPreferences where
fromField = fromTextField_ decodeJSON
setGroupPreference :: ChatFeature -> GroupFeatureEnabled -> Maybe GroupPreferences -> GroupPreferences
setGroupPreference f enable prefs_ =
let prefs = mergeGroupPreferences prefs_
pref = (getGroupPreference f prefs :: GroupPreference) {enable}
in toGroupPreferences $ case f of
CFVoice -> prefs {voice = pref}
CFFullDelete -> prefs {fullDelete = pref}
-- full collection of chat preferences defined in the app - it is used to ensure we include all preferences and to simplify processing
-- if some of the preferences are not defined in Preferences, defaults from defaultChatPrefs are used here.
data FullPreferences = FullPreferences
@@ -534,6 +550,16 @@ mergeGroupPreferences groupPreferences =
where
pref pt = fromMaybe (getGroupPreference pt defaultGroupPrefs) (groupPreferences >>= groupPrefSel pt)
toGroupPreferences :: FullGroupPreferences -> GroupPreferences
toGroupPreferences groupPreferences =
GroupPreferences
{ fullDelete = pref CFFullDelete,
-- receipts = pref CFReceipts,
voice = pref CFVoice
}
where
pref f = Just $ getGroupPreference f groupPreferences
data PrefEnabled = PrefEnabled {forUser :: Bool, forContact :: Bool}
deriving (Eq, Show, Generic, FromJSON)
+1 -1
View File
@@ -1083,7 +1083,7 @@ viewChatError = \case
CEFileImageType _ -> ["image type must be jpg, send as a file using " <> highlight' "/f"]
CEFileImageSize _ -> ["max image size: " <> sShow maxImageSize <> " bytes, resize it or send as a file using " <> highlight' "/f"]
CEFileNotReceived fileId -> ["file " <> sShow fileId <> " not received"]
CEFileLargeSentInline _ -> ["A small file sent without acceptance - you can enable receiving such files automatically with -f option."]
CEInlineFileProhibited _ -> ["A small file sent without acceptance - you can enable receiving such files with -f option."]
CEInvalidQuote -> ["cannot reply to this message"]
CEInvalidChatItemUpdate -> ["cannot update this item"]
CEInvalidChatItemDelete -> ["cannot delete this item"]