core: group link contact connecting(ed) events to avoid adding previews in ui (#1242)

* core: group link contact connecting(ed) events to avoid adding ui previews

* fix test

* refactor

* ios types

* android types

* type in bot
This commit is contained in:
JRoberts
2022-10-23 21:18:15 +01:00
committed by GitHub
parent 341199d599
commit 15c1f9f9c8
11 changed files with 67 additions and 47 deletions
+8 -6
View File
@@ -832,11 +832,11 @@ processChatCommand = \case
(agentConnId, cReq) <- withAgent $ \a -> createConnection a True SCMInvitation
member <- withStore $ \db -> createNewContactMember db gVar user groupId contact memRole agentConnId cReq
sendInvitation member cReq
pure $ CRSentGroupInvitation gInfo contact member
pure $ CRSentGroupInvitation gInfo contact member False
Just member@GroupMember {groupMemberId, memberStatus}
| memberStatus == GSMemInvited ->
withStore' (\db -> getMemberInvitation db user groupMemberId) >>= \case
Just cReq -> sendInvitation member cReq $> CRSentGroupInvitation gInfo contact member
Just cReq -> sendInvitation member cReq $> CRSentGroupInvitation gInfo contact member False
Nothing -> throwChatError $ CEGroupCantResendInvitation gInfo cName
| otherwise -> throwChatError $ CEGroupDuplicateMember cName
APIJoinGroup groupId -> withUser $ \user@User {userId} -> do
@@ -1685,7 +1685,8 @@ processAgentMessage (Just user@User {userId, profile}) corrId agentConnId agentM
Nothing -> do
-- [incognito] print incognito profile used for this contact
incognitoProfile <- forM customUserProfileId $ \profileId -> withStore (\db -> getProfileById db userId profileId)
toView $ CRContactConnected ct (fmap fromLocalProfile incognitoProfile)
viaGroupLink <- withStore' (\db -> getConnectionViaGroupLinkFlag db user connId)
toView $ CRContactConnected ct (fmap fromLocalProfile incognitoProfile) (fromMaybe False viaGroupLink)
setActive $ ActiveC c
showToast (c <> "> ") "connected"
forM_ viaUserContactLink $ \userContactLinkId ->
@@ -1749,7 +1750,7 @@ processAgentMessage (Just user@User {userId, profile}) corrId agentConnId agentM
Just ct -> do
withStore' $ \db -> setNewContactMemberConnRequest db user m cReq
sendGrpInvitation ct m
toView $ CRSentGroupInvitationViaLink gInfo ct m
toView $ CRSentGroupInvitation gInfo ct m True
where
sendGrpInvitation :: Contact -> GroupMember -> m ()
sendGrpInvitation ct GroupMember {memberId, memberRole = memRole} = do
@@ -2533,12 +2534,13 @@ processAgentMessage (Just user@User {userId, profile}) corrId agentConnId agentM
toView $ CRContactsMerged to from
saveConnInfo :: Connection -> ConnInfo -> m ()
saveConnInfo activeConn connInfo = do
saveConnInfo activeConn@Connection {connId} connInfo = do
ChatMessage {chatMsgEvent} <- parseChatMessage connInfo
case chatMsgEvent of
XInfo p -> do
ct <- withStore $ \db -> createDirectContact db userId activeConn p
toView $ CRContactConnecting ct
viaGroupLink <- withStore' (\db -> getConnectionViaGroupLinkFlag db user connId)
toView $ CRContactConnecting ct (fromMaybe False viaGroupLink)
-- TODO show/log error, other events in SMP confirmation
_ -> pure ()
+1 -1
View File
@@ -24,7 +24,7 @@ chatBotRepl welcome answer _user cc = do
race_ (forever $ void getLine) . forever $ do
(_, resp) <- atomically . readTBQueue $ outputQ cc
case resp of
CRContactConnected contact _ -> do
CRContactConnected contact _ _ -> do
contactConnected contact
void $ sendMsg contact welcome
CRNewChatItem (AChatItem _ SMDRcv (DirectChat contact) ChatItem {content}) -> do
+3 -4
View File
@@ -281,8 +281,7 @@ data ChatResponse
| CRUserAcceptedGroupSent {groupInfo :: GroupInfo}
| CRUserDeletedMember {groupInfo :: GroupInfo, member :: GroupMember}
| CRGroupsList {groups :: [GroupInfo]}
| CRSentGroupInvitation {groupInfo :: GroupInfo, contact :: Contact, member :: GroupMember}
| CRSentGroupInvitationViaLink {groupInfo :: GroupInfo, contact :: Contact, member :: GroupMember}
| CRSentGroupInvitation {groupInfo :: GroupInfo, contact :: Contact, member :: GroupMember, viaGroupLink :: Bool}
| CRFileTransferStatus (FileTransfer, [Integer]) -- TODO refactor this type to FileTransferStatus
| CRUserProfile {profile :: Profile}
| CRUserProfileNoChange
@@ -316,8 +315,8 @@ data ChatResponse
| CRUserProfileUpdated {fromProfile :: Profile, toProfile :: Profile}
| CRContactAliasUpdated {toContact :: Contact}
| CRConnectionAliasUpdated {toConnection :: PendingContactConnection}
| CRContactConnecting {contact :: Contact}
| CRContactConnected {contact :: Contact, userCustomProfile :: Maybe Profile}
| CRContactConnecting {contact :: Contact, viaGroupLink :: Bool}
| CRContactConnected {contact :: Contact, userCustomProfile :: Maybe Profile, viaGroupLink :: Bool}
| CRContactAnotherClient {contact :: Contact}
| CRSubscriptionEnd {connectionEntity :: ConnectionEntity}
| CRContactsDisconnected {server :: SMPServer, contactRefs :: [ContactRef]}
+5
View File
@@ -68,6 +68,7 @@ module Simplex.Chat.Store
getContactConnections,
getConnectionEntity,
getConnectionById,
getConnectionViaGroupLinkFlag,
getConnectionsContacts,
getGroupAndMember,
updateConnectionStatus,
@@ -1459,6 +1460,10 @@ getConnectionById db User {userId} connId = ExceptT $ do
|]
(userId, connId)
getConnectionViaGroupLinkFlag :: DB.Connection -> User -> Int64 -> IO (Maybe Bool)
getConnectionViaGroupLinkFlag db User {userId} connId =
maybeFirstRow fromOnly $ DB.query db "SELECT via_group_link FROM connections WHERE user_id = ? AND connection_id = ? LIMIT 1" (userId, connId)
getConnectionsContacts :: DB.Connection -> UserId -> [ConnId] -> IO [ContactRef]
getConnectionsContacts db userId agentConnIds = do
DB.execute_ db "DROP TABLE IF EXISTS temp.conn_ids"
+6 -4
View File
@@ -93,8 +93,10 @@ responseToView testView = \case
CRGroupCreated g -> viewGroupCreated g
CRGroupMembers g -> viewGroupMembers g
CRGroupsList gs -> viewGroupsList gs
CRSentGroupInvitation g c _ -> ["invitation to join the group " <> ttyGroup' g <> " sent to " <> ttyContact' c]
CRSentGroupInvitationViaLink g c _ -> [ttyContact' c <> " invited to group " <> ttyGroup' g <> " via your group link"]
CRSentGroupInvitation g c _ viaLink ->
if viaLink
then [ttyContact' c <> " invited to group " <> ttyGroup' g <> " via your group link"]
else ["invitation to join the group " <> ttyGroup' g <> " sent to " <> ttyContact' c]
CRFileTransferStatus ftStatus -> viewFileTransferStatus ftStatus
CRUserProfile p -> viewUserProfile p
CRUserProfileNoChange -> ["user profile did not change"]
@@ -132,8 +134,8 @@ responseToView testView = \case
CRSndFileCancelled _ ft -> sendingFile_ "cancelled" ft
CRSndFileRcvCancelled _ ft@SndFileTransfer {recipientDisplayName = c} ->
[ttyContact c <> " cancelled receiving " <> sndFile ft]
CRContactConnecting _ -> []
CRContactConnected ct userCustomProfile -> viewContactConnected ct userCustomProfile testView
CRContactConnecting _ _ -> []
CRContactConnected ct userCustomProfile _ -> viewContactConnected ct userCustomProfile testView
CRContactAnotherClient c -> [ttyContact' c <> ": contact is connected to another client"]
CRSubscriptionEnd acEntity -> [sShow (connId (entityConnection acEntity :: Connection)) <> ": END"]
CRContactsDisconnected srv cs -> [plain $ "server disconnected " <> showSMPServer srv <> " (" <> contactList cs <> ")"]