Skip to content

Commit

Permalink
utils: add comment and tests for adding name to a TLF
Browse files Browse the repository at this point in the history
Suggested by mmaxim.

Issue: #16067
  • Loading branch information
strib committed Feb 22, 2019
1 parent db3fe30 commit 66f97af
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions go/chat/utils/utils.go
Expand Up @@ -1708,6 +1708,10 @@ func AddUserToTLFName(g *globals.Context, tlfName string, vis keybase1.TLFVisibi
return username
}

// KBFS creates TLFs with suffixes (e.g., folder names that
// conflict after an assertion has been resolved) and readers,
// so we need to handle those types of TLF names here so that
// edit history works correctly.
split1 := strings.SplitN(tlfName, " ", 2) // split off suffix
split2 := strings.Split(split1[0], "#") // split off readers
// Add the name to the writers list (assume the current user
Expand Down
38 changes: 38 additions & 0 deletions go/chat/utils/utils_test.go
Expand Up @@ -8,7 +8,9 @@ import (
"testing"
"time"

"github.com/keybase/client/go/chat/globals"
"github.com/keybase/client/go/chat/types"
"github.com/keybase/client/go/externalstest"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/chat1"
"github.com/keybase/client/go/protocol/gregor1"
Expand Down Expand Up @@ -237,3 +239,39 @@ func TestDecorateMentions(t *testing.T) {
require.Equal(t, c.result, res)
}
}

type configUsernamer struct {
libkb.ConfigReader
username libkb.NormalizedUsername
}

func (c configUsernamer) GetUsername() libkb.NormalizedUsername {
return c.username
}

func TestAddUserToTlfName(t *testing.T) {
tc := externalstest.SetupTest(t, "chat-utils", 0)
g := globals.NewContext(tc.G, &globals.ChatContext{})
g.Env.SetConfig(
&configUsernamer{g.Env.GetConfig(), "charlie"}, g.Env.GetConfigWriter())

priv := keybase1.TLFVisibility_PRIVATE
mem := chat1.ConversationMembersType_IMPTEAMNATIVE
s := AddUserToTLFName(g, "alice,bob", priv, mem)
require.Equal(t, "alice,bob,charlie", s)
s = AddUserToTLFName(g, "charlie", priv, mem)
require.Equal(t, "charlie,charlie", s)
s = AddUserToTLFName(
g, "alice,bob (conflicted copy 2019-02-14 #1)", priv, mem)
require.Equal(t, "alice,bob,charlie (conflicted copy 2019-02-14 #1)", s)
s = AddUserToTLFName(
g, "alice#bob", priv, mem)
require.Equal(t, "alice,charlie#bob", s)
s = AddUserToTLFName(
g, "alice#bob (conflicted copy 2019-02-14 #1)", priv, mem)
require.Equal(t, "alice,charlie#bob (conflicted copy 2019-02-14 #1)", s)

pub := keybase1.TLFVisibility_PUBLIC
s = AddUserToTLFName(g, "alice,bob", pub, mem)
require.Equal(t, "alice,bob", s)
}

0 comments on commit 66f97af

Please sign in to comment.