From 962287c439e7368e39dffe7051537973b6390a5f Mon Sep 17 00:00:00 2001 From: Efim Poberezkin <8711996+efim-poberezkin@users.noreply.github.com> Date: Thu, 6 Jan 2022 14:24:33 +0400 Subject: [PATCH] unprocessed group invitations - highlight, print on start (#174) --- src/Simplex/Chat.hs | 12 ++++++------ src/Simplex/Chat/View.hs | 28 ++++++++++++++++++---------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index d6635da386..14b8b5eb66 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -444,20 +444,20 @@ subscribeUserConnections = void . runExceptT $ do (subscribe (contactConnId ct) >> showContactSubscribed c) `catchError` showContactSubError c subscribeGroups user = do groups <- withStore (`getUserGroups` user) - forM_ groups $ \Group {members, membership, localDisplayName = g} -> do + forM_ groups $ \g@Group {members, membership, localDisplayName = gn} -> do let connectedMembers = mapMaybe (\m -> (m,) <$> memberConnId m) members if memberStatus membership == GSMemInvited - then pure () + then showUnprocessedGroupInvitation g else if null connectedMembers then if memberActive membership - then showGroupEmpty g - else showGroupRemoved g + then showGroupEmpty gn + else showGroupRemoved gn else do forM_ connectedMembers $ \(GroupMember {localDisplayName = c}, cId) -> - subscribe cId `catchError` showMemberSubError g c - showGroupSubscribed g + subscribe cId `catchError` showMemberSubError gn c + showGroupSubscribed gn subscribeFiles user = do withStore (`getLiveSndFileTransfers` user) >>= mapM_ subscribeSndFile withStore (`getLiveRcvFileTransfers` user) >>= mapM_ subscribeRcvFile diff --git a/src/Simplex/Chat/View.hs b/src/Simplex/Chat/View.hs index 0ee6fd8d3e..68cf7bc222 100644 --- a/src/Simplex/Chat/View.hs +++ b/src/Simplex/Chat/View.hs @@ -31,6 +31,7 @@ module Simplex.Chat.View showGroupSubscribed, showGroupEmpty, showGroupRemoved, + showUnprocessedGroupInvitation, showMemberSubError, showReceivedMessage, showReceivedGroupMessage, @@ -183,6 +184,10 @@ showGroupEmpty = printToView . groupEmpty showGroupRemoved :: ChatReader m => GroupName -> m () showGroupRemoved = printToView . groupRemoved +showUnprocessedGroupInvitation :: ChatReader m => Group -> m () +showUnprocessedGroupInvitation Group {localDisplayName = ldn, groupProfile = GroupProfile {fullName}} = + printToView [unprocessedGroupInvitation ldn fullName] + showMemberSubError :: ChatReader m => GroupName -> ContactName -> ChatError -> m () showMemberSubError = printToView .:. memberSubError @@ -494,17 +499,20 @@ groupMembers Group {membership, members} = map groupMember . filter (not . remov groupsList :: [(GroupName, Text, GroupMemberStatus)] -> [StyledString] groupsList [] = ["you have no groups!", "to create: " <> highlight' "/g "] -groupsList gs = map groupNames $ sort gs +groupsList gs = map groupSS $ sort gs where - groupNames (displayName, fullName, GSMemInvited) = - ttyGroup displayName - <> optFullName displayName fullName - <> " - you are invited (" - <> highlight' ("/j " <> T.unpack displayName) - <> " to join, " - <> highlight' ("/d #" <> T.unpack displayName) - <> " to delete invitation)" - groupNames (displayName, fullName, _) = ttyGroup displayName <> optFullName displayName fullName + groupSS (displayName, fullName, GSMemInvited) = unprocessedGroupInvitation displayName fullName + groupSS (displayName, fullName, _) = ttyGroup displayName <> optFullName displayName fullName + +unprocessedGroupInvitation :: GroupName -> Text -> StyledString +unprocessedGroupInvitation displayName fullName = + highlight ("#" <> displayName) + <> optFullName displayName fullName + <> " - you are invited (" + <> highlight ("/j " <> displayName) + <> " to join, " + <> highlight ("/d #" <> displayName) + <> " to delete invitation)" contactsMerged :: Contact -> Contact -> [StyledString] contactsMerged _to@Contact {localDisplayName = c1} _from@Contact {localDisplayName = c2} =