subscribe pending connections on chat start (#95)
This commit is contained in:
@@ -278,6 +278,7 @@ subscribeUserConnections = void . runExceptT $ do
|
|||||||
user <- readTVarIO =<< asks currentUser
|
user <- readTVarIO =<< asks currentUser
|
||||||
subscribeContacts user
|
subscribeContacts user
|
||||||
subscribeGroups user
|
subscribeGroups user
|
||||||
|
subscribePendingConnections user
|
||||||
where
|
where
|
||||||
subscribeContacts user = do
|
subscribeContacts user = do
|
||||||
contacts <- withStore (`getUserContacts` user)
|
contacts <- withStore (`getUserContacts` user)
|
||||||
@@ -296,6 +297,10 @@ subscribeUserConnections = void . runExceptT $ do
|
|||||||
forM_ connectedMembers $ \(GroupMember {localDisplayName = c}, cId) ->
|
forM_ connectedMembers $ \(GroupMember {localDisplayName = c}, cId) ->
|
||||||
subscribe cId `catchError` showMemberSubError g c
|
subscribe cId `catchError` showMemberSubError g c
|
||||||
showGroupSubscribed g
|
showGroupSubscribed g
|
||||||
|
subscribePendingConnections user = do
|
||||||
|
connections <- withStore (`getPendingConnections` user)
|
||||||
|
forM_ connections $ \Connection {agentConnId} ->
|
||||||
|
subscribe agentConnId `catchError` \_ -> pure ()
|
||||||
subscribe cId = withAgent (`subscribeConnection` cId)
|
subscribe cId = withAgent (`subscribeConnection` cId)
|
||||||
|
|
||||||
processAgentMessage :: forall m. ChatMonad m => User -> ConnId -> ACommand 'Agent -> m ()
|
processAgentMessage :: forall m. ChatMonad m => User -> ConnId -> ACommand 'Agent -> m ()
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ module Simplex.Chat.Store
|
|||||||
updateUserProfile,
|
updateUserProfile,
|
||||||
updateContactProfile,
|
updateContactProfile,
|
||||||
getUserContacts,
|
getUserContacts,
|
||||||
|
getPendingConnections,
|
||||||
getContactConnections,
|
getContactConnections,
|
||||||
getConnectionChatDirection,
|
getConnectionChatDirection,
|
||||||
updateConnectionStatus,
|
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)
|
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
|
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 :: StoreMonad m => SQLiteStore -> UserId -> ContactName -> m [Connection]
|
||||||
getContactConnections st userId displayName =
|
getContactConnections st userId displayName =
|
||||||
liftIOEither . withTransaction st $ \db ->
|
liftIOEither . withTransaction st $ \db ->
|
||||||
|
|||||||
Reference in New Issue
Block a user