diff --git a/src/Simplex/Chat/Library/Commands.hs b/src/Simplex/Chat/Library/Commands.hs index d0f435f6a0..d45019b94c 100644 --- a/src/Simplex/Chat/Library/Commands.hs +++ b/src/Simplex/Chat/Library/Commands.hs @@ -4305,6 +4305,7 @@ processChatCommand cxt nm = \case case plan of CPContactAddress (CAPContactViaAddress Contact {contactId}) -> processChatCommand cxt nm $ APIConnectContactViaAddress userId incognito contactId + CPContactAddress (CAPOk (Just sld) _ vName@(Just _)) -> connectContactViaName sld vName CPGroupLink (GLPOk (Just GroupShortLinkInfo {direct = False}) (Just gld) _ vName) | ACCL SCMContact ccl <- ccLink -> joinChannelViaRelays ccl gld vName _ -> processChatCommand cxt nm $ APIConnect userId incognito $ Just ccLink @@ -4326,6 +4327,12 @@ processChatCommand cxt nm = \case gInfo <- withFastStore $ \db -> getGroupInfo db cxt user groupId deleteGroupConnections user gInfo False withFastStore' $ \db -> deleteGroup db user gInfo + connectContactViaName :: ContactShortLinkData -> Maybe SimplexNameInfo -> CM ChatResponse + connectContactViaName sld vName = + processChatCommand cxt nm (APIPrepareContact userId ccLink sld vName) >>= \case + CRNewPreparedChat _ (AChat SCTDirect (Chat (DirectChat Contact {contactId}) _ _)) -> + processChatCommand cxt nm (APIConnectPreparedContact contactId incognito Nothing) + _ -> throwChatError $ CEException "connectContactViaName: unexpected response from APIPrepareContact" invitationRequestPlan :: User -> ConnReqInvitation -> Maybe ContactShortLinkData -> Maybe OwnerVerification -> CM ConnectionPlan invitationRequestPlan user cReq cld ov = do maybe (CPInvitationLink (ILPOk cld ov)) (invitationEntityPlan cld ov) diff --git a/tests/ChatTests/Names.hs b/tests/ChatTests/Names.hs index d9afa8f7ab..81ad6e3c39 100644 --- a/tests/ChatTests/Names.hs +++ b/tests/ChatTests/Names.hs @@ -31,7 +31,10 @@ testConnectByName ps = withSmpServerAndNames $ \reg -> alice ##> "/_set_name 1 @alice.simplex" alice <## "new contact address set" bob ##> "/c @alice.simplex" - alice <#? bob + bob <## "alice: connection started" + alice <## "bob (Bob) wants to connect to you!" + alice <## "to accept: /ac bob" + alice <## "to reject: /rc bob (the sender will NOT be notified)" alice ##> "/ac bob" alice <## "bob (Bob): accepting contact request, you can send messages to contact" concurrently_