trim trailing whitespace, additional commands to list contacts and groups (#149)

This commit is contained in:
Evgeny Poberezkin
2021-12-10 11:45:58 +00:00
committed by GitHub
parent 2e56b3cb58
commit 1c2e49ae83
5 changed files with 53 additions and 6 deletions
+8 -1
View File
@@ -48,6 +48,7 @@ module Simplex.Chat.Store
getGroup,
deleteGroup,
getUserGroups,
getUserGroupNames,
getGroupInvitation,
createContactGroupMember,
createMemberConnection,
@@ -969,9 +970,15 @@ deleteGroup st User {userId} Group {groupId, members, localDisplayName} =
getUserGroups :: MonadUnliftIO m => SQLiteStore -> User -> m [Group]
getUserGroups st user =
liftIO . withTransaction st $ \db -> do
groupNames <- liftIO $ map fromOnly <$> DB.query db "SELECT local_display_name FROM groups WHERE user_id = ?" (Only $ userId user)
groupNames <- getUserGroupNames_ db $ userId user
map fst . rights <$> mapM (runExceptT . getGroup_ db user) groupNames
getUserGroupNames :: MonadUnliftIO m => SQLiteStore -> UserId -> m [GroupName]
getUserGroupNames st userId = liftIO $ withTransaction st (`getUserGroupNames_` userId)
getUserGroupNames_ :: DB.Connection -> UserId -> IO [GroupName]
getUserGroupNames_ db userId = map fromOnly <$> DB.query db "SELECT local_display_name FROM groups WHERE user_id = ?" (Only userId)
getGroupInvitation :: StoreMonad m => SQLiteStore -> User -> GroupName -> m ReceivedGroupInvitation
getGroupInvitation st user localDisplayName =
liftIOEither . withTransaction st $ \db -> runExceptT $ do