diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index 4512168b09..6dbfd57923 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -1806,7 +1806,7 @@ processChatCommand = \case xContactId <- maybe randomXContactId pure xContactId_ connect' Nothing cReqHash xContactId Just gLinkId -> procCmd $ do - let xContactId = XContactId <$> drgRandomBytes 16 + xContactId <- XContactId <$> drgRandomBytes 16 connect' (Just gLinkId) cReqHash xContactId where connect' groupLinkId cReqHash xContactId = do diff --git a/tests/Bots/DirectoryTests.hs b/tests/Bots/DirectoryTests.hs index 21bdb6577b..b4114fedac 100644 --- a/tests/Bots/DirectoryTests.hs +++ b/tests/Bots/DirectoryTests.hs @@ -689,7 +689,7 @@ testRestoreDirectory tmp = do bob <### [ "#privacy (Privacy): connected to server(s)", "#security (Security): connected to server(s)" - ] + ] cath <## "2 contacts connected (use /cs for the list)" cath <### [ "#privacy (Privacy): connected to server(s)", diff --git a/tests/ChatTests/Groups.hs b/tests/ChatTests/Groups.hs index 2f5b2689ba..447366cd05 100644 --- a/tests/ChatTests/Groups.hs +++ b/tests/ChatTests/Groups.hs @@ -49,6 +49,7 @@ chatGroupTests = do describe "group links" $ do it "create group link, join via group link" testGroupLink it "delete group, re-join via same link" testGroupLinkDeleteGroupRejoin + it "join group twice via same link" testGroupLinkRejoin it "sending message to contact created via group link marks it used" testGroupLinkContactUsed it "create group link, join via group link - incognito membership" testGroupLinkIncognitoMembership it "unused host contact is deleted after all groups with it are deleted" testGroupLinkUnusedHostContactDeleted @@ -1721,8 +1722,8 @@ testGroupLink = alice ##> "/show link #team" alice <## "no group link, to create: /create link #team" -testGroupLinkDeleteGroupRejoin :: HasCallStack => FilePath -> IO () -testGroupLinkDeleteGroupRejoin = +testGroupLinkRejoin :: HasCallStack => FilePath -> IO () +testGroupLinkRejoin = testChat2 aliceProfile bobProfile $ \alice bob -> do alice ##> "/g team" @@ -1777,6 +1778,68 @@ testGroupLinkDeleteGroupRejoin = bob #> "#team hi there" alice <# "#team bob> hi there" +testGroupLinkDeleteGroupRejoin :: HasCallStack => FilePath -> IO () +testGroupLinkDeleteGroupRejoin = + testChat2 aliceProfile bobProfile $ + \alice bob -> do + alice ##> "/g team" + alice <## "group #team is created" + alice <## "to add members use /a team or /create link #team" + alice ##> "/create link #team" + gLink <- getGroupLink alice "team" GRMember True + + bob ##> ("/c " <> gLink) + bob <## "connection request sent!" + alice <## "bob (Bob): accepting request to join group #team..." + concurrentlyN_ + [ do + alice <## "bob (Bob): contact is connected" + alice <## "bob invited to group #team via your group link" + alice <## "#team: bob joined the group", + do + bob <## "alice (Alice): contact is connected" + bob <## "#team: you joined the group" + ] + + -- re-join via same link + bob ##> ("/c " <> gLink) + bob <## "connection request sent!" + alice <## "bob_1 (Bob): accepting request to join group #team..." + concurrentlyN_ + [ alice + <### [ "bob_1 (Bob): contact is connected", + "contact bob_1 is merged into bob", + "use @bob to send messages", + EndsWith "invited to group #team via your group link", + EndsWith "joined the group" + ], + bob + <### [ "alice_1 (Alice): contact is connected", + "contact alice_1 is merged into alice", + "use @alice to send messages", + "#team_1: you joined the group", + "#team: alice added bob_1 (Bob) to the group (connecting...)", + "#team: new member bob_1 is connected", + "#team_1: member bob_2 (Bob) is connected", + "contact bob_1 is merged into bob_2", + "use @bob_2 to send messages" + ] + ] + -- alice sends message, both bobs receive + alice #> "#team hello" + bob <### + [ EndsWith "#team alice> hello", + EndsWith "#team_1 alice> hello" + ] + -- original bob sends message + bob #> "#team hi there" + alice <# "#team bob> hi there" + bob <# "#team_1 bob_2> hi there" + -- second bob sends message + bob #> "#team_1 hey" + alice <# "#team bob> hey" + bob <# "#team bob_2> hey" + testGroupLinkContactUsed :: HasCallStack => FilePath -> IO () testGroupLinkContactUsed = testChat2 aliceProfile bobProfile $