prohibit direct messages to group contacts unless group preferences allow them (#1476)

* prohibit direct messages to group contacts unless group preferences allow them

* tests

* refactor

* more test
This commit is contained in:
Evgeny Poberezkin authored and GitHub committed 2022-12-03 18:06:21 +00:00
1 parent e44e9a0940
commit 6f59df4e33
7 files changed
+140 -31

No files matched your search

+15
View File
@@ -91,6 +91,7 @@ module Simplex.Chat.Store
deleteGroup,
getUserGroups,
getUserGroupDetails,
getContactGroupPreferences,
getGroupInvitation,
createNewContactMember,
createNewContactMemberAsync,
@@ -1817,6 +1818,20 @@ getUserGroupDetails db User {userId, userContactId} =
|]
(userId, userContactId)
getContactGroupPreferences :: DB.Connection -> User -> Contact -> IO [FullGroupPreferences]
getContactGroupPreferences db User {userId} Contact {contactId} = do
map (mergeGroupPreferences . fromOnly)
<$> DB.query
db
[sql|
SELECT gp.preferences
FROM groups g
JOIN group_profiles gp USING (group_profile_id)
JOIN group_members m USING (group_id)
WHERE g.user_id = ? AND m.contact_id = ?
|]
(userId, contactId)
getGroupInfoByName :: DB.Connection -> User -> GroupName -> ExceptT StoreError IO GroupInfo
getGroupInfoByName db user gName = do
gId <- getGroupIdByName db user gName