core: fix plans for deleted contacts and groups to allow connecting to them again (#6041)

* core: fix plans for deleted contacts and groups to allow connecting to them again

* improve, tests

* query plans

* remove comment
This commit is contained in:
Evgeny
2025-07-05 21:45:07 +01:00
committed by GitHub
parent 2dd54c6697
commit f2e8545c0a
4 changed files with 80 additions and 29 deletions
+10 -10
View File
@@ -3398,6 +3398,7 @@ processChatCommand' vr = \case
let inv cReq = ACCL SCMInvitation $ CCLink cReq (Just l')
liftIO (getConnectionEntityViaShortLink db vr user l') >>= \case
Just (cReq, ent) -> pure $ Just (inv cReq, invitationEntityPlan Nothing ent)
-- deleted contact is returned as known, as invitation link cannot be re-used too connect anyway
Nothing -> bimap inv (CPInvitationLink . ILPKnown) <$$> getContactViaShortLinkToConnect db vr user l'
invitationReqAndPlan cReq sLnk_ contactSLinkData_ = do
plan <- invitationRequestPlan user cReq contactSLinkData_ `catchChatError` (pure . CPError)
@@ -3409,6 +3410,7 @@ processChatCommand' vr = \case
CLShort l@(CSLContact _ ct _ _) -> do
let l' = serverShortLink l
con cReq = ACCL SCMContact $ CCLink cReq (Just l')
gPlan (cReq, g) = if memberRemoved (membership g) then Nothing else Just (con cReq, CPGroupLink (GLPKnown g))
case ct of
CCTContact ->
knownLinkPlans >>= \case
@@ -3427,8 +3429,8 @@ processChatCommand' vr = \case
Just UserContactLink {connLinkContact = CCLink cReq _} -> pure $ Just (con cReq, CPContactAddress CAPOwnLink)
Nothing ->
getContactViaShortLinkToConnect db vr user l' >>= \case
Just (cReq, ct') -> pure $ Just (con cReq, CPContactAddress (CAPKnown ct'))
Nothing -> bimap con (CPGroupLink . GLPKnown) <$$> getGroupViaShortLinkToConnect db vr user l'
Just (cReq, ct') -> pure $ if contactDeleted ct' then Nothing else Just (con cReq, CPContactAddress (CAPKnown ct'))
Nothing -> (gPlan =<<) <$> getGroupViaShortLinkToConnect db vr user l'
CCTGroup ->
knownLinkPlans >>= \case
Just r -> pure r
@@ -3441,8 +3443,7 @@ processChatCommand' vr = \case
knownLinkPlans = withFastStore $ \db ->
liftIO (getGroupInfoViaUserShortLink db vr user l') >>= \case
Just (cReq, g) -> pure $ Just (con cReq, CPGroupLink (GLPOwnLink g))
Nothing ->
bimap con (CPGroupLink . GLPKnown ) <$$> getGroupViaShortLinkToConnect db vr user l'
Nothing -> (gPlan =<<) <$> getGroupViaShortLinkToConnect db vr user l'
CCTChannel -> throwCmdError "channel links are not supported in this version"
connectWithPlan :: User -> IncognitoEnabled -> ACreatedConnLink -> ConnectionPlan -> CM ChatResponse
connectWithPlan user@User {userId} incognito ccLink plan
@@ -3501,7 +3502,7 @@ processChatCommand' vr = \case
| contactDeleted ct -> pure $ CPContactAddress (CAPOk contactSLinkData_)
| otherwise -> pure $ CPContactAddress (CAPKnown ct)
-- TODO [short links] RcvGroupMsgConnection branch is deprecated? (old group link protocol?)
Just (RcvGroupMsgConnection _ gInfo _) -> groupPlan gInfo
Just (RcvGroupMsgConnection _ gInfo _) -> groupPlan gInfo Nothing
Just _ -> throwCmdError "found connection entity is not RcvDirectMsgConnection or RcvGroupMsgConnection"
groupJoinRequestPlan :: User -> ConnReqContact -> Maybe GroupShortLinkData -> CM ConnectionPlan
groupJoinRequestPlan user (CRContactUri crData) groupSLinkData_ = do
@@ -3520,15 +3521,14 @@ processChatCommand' vr = \case
| not (contactReady ct) && contactActive ct -> pure $ CPGroupLink (GLPConnectingProhibit gInfo_)
| otherwise -> pure $ CPGroupLink (GLPOk groupSLinkData_)
(Nothing, Just _) -> throwCmdError "found connection entity is not RcvDirectMsgConnection"
(Just gInfo, _) -> groupPlan gInfo
groupPlan :: GroupInfo -> CM ConnectionPlan
groupPlan gInfo@GroupInfo {membership}
(Just gInfo, _) -> groupPlan gInfo groupSLinkData_
groupPlan :: GroupInfo -> Maybe GroupShortLinkData -> CM ConnectionPlan
groupPlan gInfo@GroupInfo {membership} groupSLinkData_
| memberStatus membership == GSMemRejected = pure $ CPGroupLink (GLPKnown gInfo)
| not (memberActive membership) && not (memberRemoved membership) =
pure $ CPGroupLink (GLPConnectingProhibit $ Just gInfo)
| memberActive membership = pure $ CPGroupLink (GLPKnown gInfo)
-- TODO [short links] entity is already found - passing GroupShortLinkData doesn't make sense?
| otherwise = pure $ CPGroupLink (GLPOk Nothing)
| otherwise = pure $ CPGroupLink (GLPOk groupSLinkData_)
contactCReqSchemas :: ConnReqUriData -> (ConnReqContact, ConnReqContact)
contactCReqSchemas crData =
( CRContactUri crData {crScheme = SSSimplex},
+23 -13
View File
@@ -386,7 +386,7 @@ chatEventToView hu ChatConfig {logLevel, showReactions, showReceipts, testView}
CEvtGroupMemberSwitch u g m progress -> ttyUser u $ viewGroupMemberSwitch g m progress
CEvtContactRatchetSync u ct progress -> ttyUser u $ viewContactRatchetSync ct progress
CEvtGroupMemberRatchetSync u g m progress -> ttyUser u $ viewGroupMemberRatchetSync g m progress
CEvtChatInfoUpdated u chatInfo -> []
CEvtChatInfoUpdated _ _ -> []
CEvtNewChatItems u chatItems -> viewChatItems ttyUser unmuted u chatItems ts tz
CEvtChatItemsStatusesUpdated u chatItems
| length chatItems <= 20 ->
@@ -1895,6 +1895,7 @@ viewConnectionPlan ChatConfig {logLevel, testView} _connLink = \case
ILPConnecting (Just ct) -> [invLink ("connecting to contact " <> ttyContact' ct)]
ILPKnown ct
| nextConnectPrepared ct -> [invLink ("known prepared contact " <> ttyContact' ct)]
| contactDeleted ct -> [invLink ("known deleted contact " <> ttyContact' ct)]
| otherwise ->
[ invLink ("known contact " <> ttyContact' ct),
"use " <> ttyToContact' ct <> highlight' "<message>" <> " to send messages"
@@ -1903,7 +1904,7 @@ viewConnectionPlan ChatConfig {logLevel, testView} _connLink = \case
invLink = ("invitation link: " <>)
invOrBiz = \case
Just ContactShortLinkData {business}
| business -> ("business link: " <>)
| business -> ("business address: " <>)
_ -> ("invitation link: " <>)
CPContactAddress cap -> case cap of
CAPOk contactSLinkData -> [addrOrBiz contactSLinkData "ok to connect"] <> [viewJSON contactSLinkData | testView]
@@ -1921,7 +1922,7 @@ viewConnectionPlan ChatConfig {logLevel, testView} _connLink = \case
ctAddr = ("contact address: " <>)
addrOrBiz = \case
Just ContactShortLinkData {business}
| business -> ("business link: " <>)
| business -> ("business address: " <>)
_ -> ("contact address: " <>)
CPGroupLink glp -> case glp of
GLPOk groupSLinkData -> [grpLink "ok to connect"] <> [viewJSON groupSLinkData | testView]
@@ -1929,19 +1930,28 @@ viewConnectionPlan ChatConfig {logLevel, testView} _connLink = \case
GLPConnectingConfirmReconnect -> [grpLink "connecting, allowed to reconnect"]
GLPConnectingProhibit Nothing -> [grpLink "connecting"]
GLPConnectingProhibit (Just g) -> connecting g
GLPKnown g@GroupInfo {preparedGroup} -> case preparedGroup of
Just PreparedGroup {connLinkStartedConnection}
| connLinkStartedConnection -> connecting g
| otherwise -> [knownGroup "prepared "]
Nothing ->
[ knownGroup "",
"use " <> ttyToGroup g Nothing <> highlight' "<message>" <> " to send messages"
]
GLPKnown g@GroupInfo {preparedGroup, membership = m} -> case preparedGroup of
Just PreparedGroup {connLinkStartedConnection} -> case memberStatus m of
GSMemUnknown
| connLinkStartedConnection -> connecting g
| otherwise -> [knownGroup "prepared "]
GSMemAccepted -> connecting g
_
| memberRemoved m -> [knownGroup "deleted "] -- it should not get here, as this plan is returned as GLPOk
| otherwise -> knownActive
_ -> knownActive
where
knownGroup prepared = grpOrBiz g <> " link: known " <> prepared <> grpOrBiz g <> " " <> ttyGroup' g
knownActive =
[ knownGroup "",
"use " <> ttyToGroup g Nothing <> highlight' "<message>" <> " to send messages"
]
knownGroup prepared = grpOrBizLink g <> ": known " <> prepared <> grpOrBiz g <> " " <> ttyGroup' g
where
connecting g = [grpOrBiz g <> " link: connecting to " <> grpOrBiz g <> " " <> ttyGroup' g]
connecting g = [grpOrBizLink g <> ": connecting to " <> grpOrBiz g <> " " <> ttyGroup' g]
grpLink = ("group link: " <>)
grpOrBizLink GroupInfo {businessChat} = case businessChat of
Just _ -> "business address"
Nothing -> "group link"
grpOrBiz GroupInfo {businessChat} = case businessChat of
Just _ -> "business"
Nothing -> "group"