Skip to content

Commit

Permalink
chat: handle suffixes and readers when adding username to TLF
Browse files Browse the repository at this point in the history
Otherwise a valid TLF name like "a,b (conflicted copy 2019-02-14 #1)"
becomes "a,b (conflicted copy 2019-02-14 #1),a" and everything breaks.
  • Loading branch information
strib committed Feb 14, 2019
1 parent 8944494 commit e9c235f
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions go/chat/utils/utils.go
Expand Up @@ -1646,16 +1646,32 @@ func AddUserToTLFName(g *globals.Context, tlfName string, vis keybase1.TLFVisibi
switch membersType {
case chat1.ConversationMembersType_IMPTEAMNATIVE, chat1.ConversationMembersType_IMPTEAMUPGRADE,
chat1.ConversationMembersType_KBFS:
if vis == keybase1.TLFVisibility_PUBLIC {
return tlfName
}

username := g.Env.GetUsername().String()
if vis != keybase1.TLFVisibility_PUBLIC {
if len(tlfName) == 0 {
tlfName = username
} else {
tlfName += "," + username
}
if len(tlfName) == 0 {
return username
}

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
// is a writer).
tlfName = split2[0] + "," + username
if len(split2) > 1 {
// Re-append any readers.
tlfName += "#" + split2[1]
}
if len(split1) > 1 {
// Re-append any suffix.
tlfName += " " + split1[1]
}
return tlfName
default:
return tlfName
}
return tlfName
}

func ForceReloadUPAKsForUIDs(ctx context.Context, g *globals.Context, uids []keybase1.UID) error {
Expand Down

0 comments on commit e9c235f

Please sign in to comment.