Skip to content

Commit

Permalink
Attempt sbs resolution in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblum committed Dec 20, 2018
1 parent 1b043b9 commit c180996
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
22 changes: 18 additions & 4 deletions go/chat/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"math"
"sort"
"strings"
"time"

"github.com/keybase/client/go/chat/globals"
Expand Down Expand Up @@ -502,6 +503,16 @@ func FindConversations(ctx context.Context, g *globals.Context, debugger utils.D
topicName = globals.DefaultTeamTopic
}

// Attempt to resolve any sbs convs incase the team already exists.
var nameInfo *types.NameInfo
if strings.Contains(tlfName, "@") {
// Fetch the TLF ID from specified name
if info, err := CreateNameInfoSource(ctx, g, membersType).LookupID(ctx, tlfName, vis == keybase1.TLFVisibility_PUBLIC); err == nil {
nameInfo = &info
tlfName = nameInfo.CanonicalName
}
}

query := &chat1.GetInboxLocalQuery{
Name: &chat1.NameQuery{
Name: tlfName,
Expand Down Expand Up @@ -535,10 +546,13 @@ func FindConversations(ctx context.Context, g *globals.Context, debugger utils.D
// are not any public team chats.

// Fetch the TLF ID from specified name
nameInfo, err := CreateNameInfoSource(ctx, g, membersType).LookupID(ctx, tlfName, false)
if err != nil {
debugger.Debug(ctx, "FindConversations: failed to get TLFID from name: %s", err.Error())
return res, err
if nameInfo == nil {
info, err := CreateNameInfoSource(ctx, g, membersType).LookupID(ctx, tlfName, false)
if err != nil {
debugger.Debug(ctx, "FindConversations: failed to get TLFID from name: %s", err.Error())
return res, err
}
nameInfo = &info
}
tlfConvs, err := g.TeamChannelSource.GetChannelsFull(ctx, uid, nameInfo.ID, topicType)
if err != nil {
Expand Down
45 changes: 45 additions & 0 deletions go/chat/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2541,6 +2541,51 @@ func TestChatSrvFindConversations(t *testing.T) {
})
}

func TestChatSrvFindConversationsWithSBS(t *testing.T) {
runWithMemberTypes(t, func(mt chat1.ConversationMembersType) {
switch mt {
case chat1.ConversationMembersType_TEAM, chat1.ConversationMembersType_KBFS:
return
}

ctc := makeChatTestContext(t, "FindConversations", 2)
defer ctc.cleanup()
users := ctc.users()

// Create a conversation between both users. Attempt to send to
// `user1,user2@rooter` and make sure we resolve and find the
// conversation correctly.
created := mustCreateConversationForTest(t, ctc, users[0], chat1.TopicType_CHAT,
mt, users[1])
tc1 := ctc.world.Tcs[users[1].Username]
sbsName := strings.Join([]string{users[0].Username, fmt.Sprintf("%s@rooter", users[1].Username)}, ",")

ctx := ctc.as(t, users[0]).startCtx
// Fail since we haven't proved rooter yet
res, err := ctc.as(t, users[0]).chatLocalHandler().FindConversationsLocal(ctx,
chat1.FindConversationsLocalArg{
TlfName: sbsName,
MembersType: mt,
TopicType: chat1.TopicType_CHAT,
IdentifyBehavior: keybase1.TLFIdentifyBehavior_CHAT_CLI,
})
require.NoError(t, err)
require.Zero(t, len(res.Conversations))

proveRooter(t, tc1.Context().ExternalG(), users[1])
res, err = ctc.as(t, users[0]).chatLocalHandler().FindConversationsLocal(ctx,
chat1.FindConversationsLocalArg{
TlfName: sbsName,
MembersType: mt,
TopicType: chat1.TopicType_CHAT,
IdentifyBehavior: keybase1.TLFIdentifyBehavior_CHAT_CLI,
})
require.NoError(t, err)
require.Equal(t, 1, len(res.Conversations), "no conv found")
require.Equal(t, created.Id, res.Conversations[0].GetConvID(), "wrong conv")
})
}

func receiveThreadResult(t *testing.T, cb chan kbtest.NonblockThreadResult) (res *chat1.UIMessages) {
var tres kbtest.NonblockThreadResult
select {
Expand Down

0 comments on commit c180996

Please sign in to comment.