fix: properly implement /join

This commit is contained in:
2022-01-24 08:18:30 +02:00
parent 998dd0828a
commit 92d6449e46
2 changed files with 22 additions and 21 deletions
+20 -5
View File
@@ -73,11 +73,26 @@ func handleJoin(msg parser.IRCMessage, client *irc.Client) {
channel := msg.Parameters[0]
joinMsg := fmt.Sprintf("== %s has joined", nick)
for i, c := range client.Channels {
if c.Name == channel {
client.Channels[i].History += joinMsg + irc.CRLF
if _, exists := client.Channels[i].Users[nick]; !exists {
client.Channels[i].Users[nick] = irc.User{}
if nick == client.Nickname {
client.Channels = append(client.Channels, irc.Channel{
Name: channel,
Users: make(map[string]irc.User),
})
client.ActiveChannelIndex = len(client.Channels) - 1
client.ActiveChannel = channel
client.Channels[client.ActiveChannelIndex].History += joinMsg + irc.CRLF
if _, exists := client.Channels[client.ActiveChannelIndex].Users[nick]; !exists {
client.Channels[client.ActiveChannelIndex].Users[nick] = irc.User{}
}
client.Tea.Send(cmds.UpdateTabBar())
} else {
for i, c := range client.Channels {
if c.Name == channel {
client.Channels[i].History += joinMsg + irc.CRLF
if _, exists := client.Channels[i].Users[nick]; !exists {
client.Channels[i].Users[nick] = irc.User{}
}
}
}
}
+2 -16
View File
@@ -26,35 +26,21 @@ import (
)
func handleSlashJoin(params []string, client *irc.Client) tea.Cmd {
// TODO: only add channel to client slice when
// we get a JOIN command from the server with our nickname
// TODO: handle comma separated channels
var cmdsToProcess []tea.Cmd
channel := ""
if len(params) > 0 {
channel = params[0]
}
client.ActiveChannel = channel
for i, c := range client.Channels {
if c.Name == channel {
client.ActiveChannelIndex = i
client.ActiveChannel = channel
break
} else if i == len(client.Channels)-1 {
client.Channels = append(client.Channels, irc.Channel{
Name: channel,
Users: make(map[string]irc.User),
})
client.ActiveChannelIndex = len(client.Channels) - 1
cmdsToProcess = append(cmdsToProcess, cmds.UpdateTabBar)
}
}
client.SendCommand(commands.JOIN, params...)
cmdsToProcess = append(cmdsToProcess, cmds.SwitchChannels)
return tea.Batch(cmdsToProcess...)
return cmds.SwitchChannels
}
func HandleSlashCommand(msg string, client *irc.Client) tea.Cmd {