core: don't keep connection of the merged contact (#2507)

This commit is contained in:
spaced4ndy
2023-05-25 20:54:31 +04:00
committed by GitHub
parent f9f34911b1
commit 6093219ce9
8 changed files with 77 additions and 49 deletions

View File

@@ -2656,7 +2656,7 @@ processAgentMessageConn user@User {userId} corrId agentConnId agentMessage = do
_ -> Nothing
processDirectMessage :: ACommand 'Agent e -> ConnectionEntity -> Connection -> Maybe Contact -> m ()
processDirectMessage agentMsg connEntity conn@Connection {connId, viaUserContactLink, groupLinkId, customUserProfileId} = \case
processDirectMessage agentMsg connEntity conn@Connection {connId, viaUserContactLink, customUserProfileId} = \case
Nothing -> case agentMsg of
CONF confId _ connInfo -> do
-- [incognito] send saved profile
@@ -2758,7 +2758,6 @@ processAgentMessageConn user@User {userId} corrId agentConnId agentMessage = do
whenUserNtfs user $ do
setActive $ ActiveC c
showToast (c <> "> ") "connected"
forM_ groupLinkId $ \_ -> probeMatchingContacts ct $ contactConnIncognito ct
forM_ viaUserContactLink $ \userContactLinkId ->
withStore' (\db -> getUserContactLinkById db userId userContactLinkId) >>= \case
Just (UserContactLink {autoAccept = Just AutoAccept {autoReply = mc_}}, groupId_, gLinkMemRole) -> do
@@ -2903,6 +2902,11 @@ processAgentMessageConn user@User {userId} corrId agentConnId agentMessage = do
whenUserNtfs user $ do
setActive $ ActiveG gName
showToast ("#" <> gName) "you are connected to group"
withStore' (\db -> getContactViaMember db user m) >>= \case
Nothing -> messageWarning "connected host does not have contact"
Just ct@Contact {activeConn = Connection {groupLinkId}} -> do
let connectedIncognito = contactConnIncognito ct || memberIncognito membership
forM_ groupLinkId $ \_ -> probeMatchingContacts ct connectedIncognito
GCInviteeMember -> do
memberConnectedChatItem gInfo m
toView $ CRJoinedGroupMember user gInfo m {memberStatus = GSMemConnected}
@@ -3825,8 +3829,9 @@ processAgentMessageConn user@User {userId} corrId agentConnId agentMessage = do
probeMatch c1@Contact {contactId = cId1, profile = p1} c2@Contact {contactId = cId2, profile = p2} probe =
if profilesMatch (fromLocalProfile p1) (fromLocalProfile p2) && cId1 /= cId2
then do
void . sendDirectContactMessage c1 $ XInfoProbeOk probe
mergeContacts c1 c2
let (toCt, fromCt) = mergeToFromContacts c1 c2
void . sendDirectContactMessage toCt $ XInfoProbeOk probe
mergeContacts toCt fromCt
else messageWarning "probeMatch ignored: profiles don't match or same contact id"
xInfoProbeOk :: Contact -> Probe -> m ()
@@ -3834,9 +3839,22 @@ processAgentMessageConn user@User {userId} corrId agentConnId agentMessage = do
r <- withStore' $ \db -> matchSentProbe db user c1 probe
forM_ r $ \c2@Contact {contactId = cId2} ->
if cId1 /= cId2
then mergeContacts c1 c2
then do
let (toCt, fromCt) = mergeToFromContacts c1 c2
mergeContacts toCt fromCt
else messageWarning "xInfoProbeOk ignored: same contact id"
mergeToFromContacts :: Contact -> Contact -> (Contact, Contact)
mergeToFromContacts c1 c2
| d1 && not d2 = (c1, c2)
| d2 && not d1 = (c2, c1)
| ctCreatedAt c1 <= ctCreatedAt c2 = (c1, c2)
| otherwise = (c2, c1)
where
d1 = directOrUsed c1
d2 = directOrUsed c2
ctCreatedAt Contact {createdAt} = createdAt
-- to party accepting call
xCallInv :: Contact -> CallId -> CallInvitation -> RcvMessage -> MsgMeta -> m ()
xCallInv ct@Contact {contactId} callId CallInvitation {callType, callDhPubKey} msg@RcvMessage {sharedMsgId_} msgMeta = do
@@ -3943,9 +3961,10 @@ processAgentMessageConn user@User {userId} corrId agentConnId agentMessage = do
messageError $ eventName <> ": wrong call state " <> T.pack (show $ callStateTag callState)
mergeContacts :: Contact -> Contact -> m ()
mergeContacts c1 c2 = do
withStore' $ \db -> mergeContactRecords db userId c1 c2
toView $ CRContactsMerged user c1 c2
mergeContacts toCt fromCt = do
deleteAgentConnectionAsync user $ aConnId $ contactConn fromCt
withStore' $ \db -> mergeContactRecords db userId toCt fromCt
toView $ CRContactsMerged user toCt fromCt
saveConnInfo :: Connection -> ConnInfo -> m ()
saveConnInfo activeConn connInfo = do