subscribe pending connections on chat start (#95)

This commit is contained in:
Efim Poberezkin
2021-08-28 20:54:53 +10:00
committed by GitHub
parent 9cfca4ed35
commit 97fde7ecd0
2 changed files with 22 additions and 0 deletions
+17
View File
@@ -27,6 +27,7 @@ module Simplex.Chat.Store
updateUserProfile,
updateContactProfile,
getUserContacts,
getPendingConnections,
getContactConnections,
getConnectionChatDirection,
updateConnectionStatus,
@@ -336,6 +337,22 @@ getUserContacts st User {userId} =
contactNames <- liftIO $ map fromOnly <$> DB.query db "SELECT local_display_name FROM contacts WHERE user_id = ?" (Only userId)
rights <$> mapM (runExceptT . getContact_ db userId) contactNames
getPendingConnections :: MonadUnliftIO m => SQLiteStore -> User -> m [Connection]
getPendingConnections st User {userId} =
liftIO . withTransaction st $ \db ->
map toConnection
<$> DB.queryNamed
db
[sql|
SELECT c.connection_id, c.agent_conn_id, c.conn_level, c.via_contact,
c.conn_status, c.conn_type, c.contact_id, c.group_member_id, c.created_at
FROM connections c
WHERE c.user_id = :user_id
AND c.conn_type = :conn_type
AND c.contact_id IS NULL
|]
[":user_id" := userId, ":conn_type" := ConnContact]
getContactConnections :: StoreMonad m => SQLiteStore -> UserId -> ContactName -> m [Connection]
getContactConnections st userId displayName =
liftIOEither . withTransaction st $ \db ->