1
0
mirror of https://github.com/Rudi9719/kbtui.git synced 2026-03-25 12:03:33 +00:00

Fixed bugs regarding the join command

Changes:
- made it possible join with @ and # prepended as well
- Also made it possible if it's written in a singular string ie `@team#channel`
   - also made this work with auto complete
- doesn't bug out if you do `/j @person` (with a space at the end) (which it
previously thought was a team + channel, with empty channel name
This commit is contained in:
Casper Weiss Bang
2019-10-14 21:45:14 +02:00
parent 4d24c38fe8
commit d536cbd6cd
2 changed files with 38 additions and 18 deletions

View File

@ -4,8 +4,8 @@ package main
import (
"fmt"
"samhofi.us/x/keybase"
"strings"
)
func init() {
@ -21,23 +21,31 @@ func init() {
func cmdJoin(cmd []string) {
stream = false
if len(cmd) == 3 {
channel.MembersType = keybase.TEAM
channel.Name = cmd[1]
channel.TopicName = cmd[2]
printToView("Feed", fmt.Sprintf("You are joining: @%s#%s", channel.Name, channel.TopicName))
switch l := len(cmd); l {
case 3:
fallthrough
case 2:
// if people write it in one singular line, with a `#`
firstArgSplit := strings.Split(cmd[1], "#")
channel.Name = strings.Replace(firstArgSplit[0], "@", "", 1)
joinedName := fmt.Sprintf("@%s", channel.Name)
if l == 3 || len(firstArgSplit) == 2 {
channel.MembersType = keybase.TEAM
if l == 3 {
channel.TopicName = strings.Replace(cmd[2], "#", "", 1)
} else {
channel.TopicName = firstArgSplit[1]
}
joinedName = fmt.Sprintf("%s#%s", joinedName, channel.TopicName)
} else {
channel.TopicName = ""
channel.MembersType = keybase.USER
}
printToView("Feed", fmt.Sprintf("You are joining: %s", joinedName))
clearView("Chat")
viewTitle("Input", fmt.Sprintf(" @%s#%s ", channel.Name, channel.TopicName))
viewTitle("Input", fmt.Sprintf(" %s ", joinedName))
go populateChat()
} else if len(cmd) == 2 {
channel.MembersType = keybase.USER
channel.Name = cmd[1]
channel.TopicName = ""
printToView("Feed", fmt.Sprintf("You are joining: @%s", channel.Name))
clearView("Chat")
viewTitle("Input", fmt.Sprintf(" @%s ", channel.Name))
go populateChat()
} else {
default:
printToView("Feed", fmt.Sprintf("To join a team use %sjoin <team> <channel>", cmdPrefix))
printToView("Feed", fmt.Sprintf("To join a PM use %sjoin <user>", cmdPrefix))
}