WIP: refactor

This commit is contained in:
2025-08-18 21:10:04 +02:00
parent 573a0da672
commit f88c2af404
6 changed files with 395 additions and 245 deletions
+20 -13
View File
@@ -44,16 +44,21 @@ func handleSlashPrivMsg(params []string, client *irc.Client) tea.Cmd {
timestamp := fmt.Sprintf("[%02d:%02d]", now.Hour(), now.Minute())
msg := fmt.Sprintf("%s: %s", client.Nickname, strings.Join(params[1:], " "))
for i, c := range client.Channels {
if c.Name == target {
client.ActiveChannelIndex = i
client.ActiveChannel = target
c := client.RootChannel
for {
if c.Value.Name == target {
client.ActiveChannel = c
client.Channels[i].AppendMsg(timestamp, msg, msgOpts)
c.Value.AppendMsg(timestamp, msg, msgOpts)
client.SendCommand(commands.PRIVMSG, params...)
return cmds.SwitchChannels
}
c = c.Next
if c == client.RootChannel {
break
}
}
// If we're messaging a user and their "channel" wasn't found in the previous loop, then create it and append it
@@ -64,11 +69,8 @@ func handleSlashPrivMsg(params []string, client *irc.Client) tea.Cmd {
}
newChannel.AppendMsg(timestamp, msg, msgOpts)
client.ActiveChannel = client.AppendChannel(newChannel)
client.ActiveChannelIndex = len(client.Channels)
client.ActiveChannel = target
client.Channels = append(client.Channels, newChannel)
batchedCmds = append(batchedCmds, cmds.UpdateTabBar)
}
@@ -84,12 +86,17 @@ func handleSlashJoin(params []string, client *irc.Client) tea.Cmd {
channel = strings.ToLower(params[0])
}
for i, c := range client.Channels {
if c.Name == channel {
client.ActiveChannelIndex = i
client.ActiveChannel = channel
c := client.RootChannel
for {
if c.Value.Name == channel {
client.ActiveChannel = c
return cmds.SwitchChannels
}
c = c.Next
if c == client.RootChannel {
break
}
}
client.SendCommand(commands.JOIN, params...)