From 1bc47c6910bf7e97c978de5e87a7302ee9dc3e74 Mon Sep 17 00:00:00 2001 From: Alexander Bondarenko <486682+dpwiz@users.noreply.github.com> Date: Sat, 25 May 2024 11:03:24 +0300 Subject: [PATCH] inline calls --- src/Simplex/Chat.hs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index 6d10985e63..a8ed2d8144 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -3331,28 +3331,21 @@ agentSubscriber = do subscribeUserConnections :: VersionRangeChat -> Bool -> User -> CM () subscribeUserConnections vr onlyNeeded user = do -- get user connections - -- ce <- asks $ subscriptionEvents . config conns <- if onlyNeeded then withStore' getConnectionsToSubscribe else do withStore' unsetConnectionToSubscribe - ctConns <- getContactConns - ucConns <- getUserContactLinkConns - mConns <- getGroupMemberConns - sftConns <- getSndFileTransferConns - rftConns <- getRcvFileTransferConns - pcConns <- getPendingContactConns + ctConns <- mapMaybe (\ct -> if contactActive ct then contactConnId ct else Nothing) <$> withStore_ (`getUserContacts` vr) + ucConns <- map (aConnId . fst) <$> withStore_ (`getUserContactLinks` vr) + mConns <- concatMap (\(Group _ ms) -> mapMaybe memberConnId (filter (not . memberRemoved) ms)) <$> withStore_ (`getUserGroups` vr) + sftConns <- map sndFileTransferConnId <$> withStore_ getLiveSndFileTransfers + rftConns <- mapMaybe liveRcvFileTransferConnId <$> withStore_ getLiveRcvFileTransfers + pcConns <- map aConnId' <$> withStore_ getPendingContactConnections pure $ concat [ctConns, ucConns, mConns, sftConns, rftConns, pcConns] -- subscribe using batched commands void $ withAgent (`Agent.subscribeConnections` conns) where - getContactConns = mapMaybe (\ct -> if contactActive ct then contactConnId ct else Nothing) <$> withStore_ (`getUserContacts` vr) - getUserContactLinkConns = map (aConnId . fst) <$> withStore_ (`getUserContactLinks` vr) - getGroupMemberConns = concatMap (\(Group _ ms) -> mapMaybe memberConnId (filter (not . memberRemoved) ms)) <$> withStore_ (`getUserGroups` vr) - getSndFileTransferConns = map sndFileTransferConnId <$> withStore_ getLiveSndFileTransfers - getRcvFileTransferConns = mapMaybe (\ft -> liveRcvFileTransferConnId ft) <$> withStore_ getLiveRcvFileTransfers - getPendingContactConns = map aConnId' <$> withStore_ getPendingContactConnections withStore_ :: (DB.Connection -> User -> IO [a]) -> CM [a] withStore_ a = withStore' (`a` user) `catchChatError` \e -> toView (CRChatError (Just user) e) $> []