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
+15
View File
@@ -73,6 +73,20 @@ func handleJoin(msg parser.IRCMessage, client *irc.Client) {
channel := msg.Parameters[0] channel := msg.Parameters[0]
joinMsg := fmt.Sprintf("== %s has joined", nick) joinMsg := fmt.Sprintf("== %s has joined", nick)
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 { for i, c := range client.Channels {
if c.Name == channel { if c.Name == channel {
client.Channels[i].History += joinMsg + irc.CRLF client.Channels[i].History += joinMsg + irc.CRLF
@@ -81,6 +95,7 @@ func handleJoin(msg parser.IRCMessage, client *irc.Client) {
} }
} }
} }
}
if channel == client.ActiveChannel { if channel == client.ActiveChannel {
client.Tea.Send(cmds.SwitchChannels()) client.Tea.Send(cmds.SwitchChannels())
+2 -16
View File
@@ -26,35 +26,21 @@ import (
) )
func handleSlashJoin(params []string, client *irc.Client) tea.Cmd { 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 := "" channel := ""
if len(params) > 0 { if len(params) > 0 {
channel = params[0] channel = params[0]
} }
client.ActiveChannel = channel
for i, c := range client.Channels { for i, c := range client.Channels {
if c.Name == channel { if c.Name == channel {
client.ActiveChannelIndex = i client.ActiveChannelIndex = i
client.ActiveChannel = channel
break 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...) client.SendCommand(commands.JOIN, params...)
cmdsToProcess = append(cmdsToProcess, cmds.SwitchChannels) return cmds.SwitchChannels
return tea.Batch(cmdsToProcess...)
} }
func HandleSlashCommand(msg string, client *irc.Client) tea.Cmd { func HandleSlashCommand(msg string, client *irc.Client) tea.Cmd {