mirror of
https://github.com/IllusionMan1212/gorc.git
synced 2026-10-24 02:12:33 +00:00
feat: support and handle changing nicknames
This commit is contained in:
@@ -69,6 +69,12 @@ func SwitchChannels() tea.Msg {
|
|||||||
return SwitchChannelsMsg{}
|
return SwitchChannelsMsg{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UpdateNicksMsg struct{}
|
||||||
|
|
||||||
|
func UpdateNicks() tea.Msg {
|
||||||
|
return UpdateNicksMsg{}
|
||||||
|
}
|
||||||
|
|
||||||
type UpdateTabBarMsg struct{}
|
type UpdateTabBarMsg struct{}
|
||||||
|
|
||||||
func UpdateTabBar() tea.Msg {
|
func UpdateTabBar() tea.Msg {
|
||||||
|
|||||||
@@ -155,6 +155,53 @@ func handleJoin(msg irc.Message, client *irc.Client) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sent from server to client to acknowledge a nickname change, or to inform of a nickname change of another user.
|
||||||
|
func handleNick(msg irc.Message, client *irc.Client) {
|
||||||
|
oldNick := strings.SplitN(msg.Source, "!", 2)[0]
|
||||||
|
newNick := msg.Parameters[0]
|
||||||
|
|
||||||
|
// TODO: the actual case-sensitivity is determined by the CASEMAPPING feature
|
||||||
|
isMe := strings.EqualFold(oldNick, client.Nickname)
|
||||||
|
|
||||||
|
msgOpts := irc.MsgFmtOpts{
|
||||||
|
WithTimestamp: true,
|
||||||
|
AsServerMsg: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
message := ""
|
||||||
|
|
||||||
|
if isMe {
|
||||||
|
message = fmt.Sprintf("Your nickname was changed to %v", newNick)
|
||||||
|
} else {
|
||||||
|
message = fmt.Sprintf("%v changed their nickname to %v", oldNick, newNick)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, channel := range client.Channels {
|
||||||
|
// Rename this user in every channel we can find
|
||||||
|
if user, ok := channel.Users[oldNick]; ok {
|
||||||
|
delete(client.Channels[i].Users, oldNick)
|
||||||
|
client.Channels[i].Users[newNick] = user
|
||||||
|
client.Channels[i].AppendMsg(msg.Timestamp, message, msgOpts)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we have a private channel open with this user, rename it as well.
|
||||||
|
if strings.EqualFold(channel.Name, oldNick) {
|
||||||
|
client.Channels[i].Name = newNick
|
||||||
|
|
||||||
|
if client.ActiveChannelIndex == i {
|
||||||
|
client.ActiveChannel = newNick
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if isMe {
|
||||||
|
client.Channels[0].AppendMsg(msg.Timestamp, message, msgOpts)
|
||||||
|
client.Nickname = newNick
|
||||||
|
}
|
||||||
|
|
||||||
|
client.Tea.Send(cmds.UpdateNicks())
|
||||||
|
}
|
||||||
|
|
||||||
func handleQuit(msg irc.Message, client *irc.Client) {
|
func handleQuit(msg irc.Message, client *irc.Client) {
|
||||||
nick := strings.SplitN(msg.Source, "!", 2)[0]
|
nick := strings.SplitN(msg.Source, "!", 2)[0]
|
||||||
reason := msg.Parameters[0]
|
reason := msg.Parameters[0]
|
||||||
@@ -898,6 +945,8 @@ func HandleCommand(msg irc.Message, client *irc.Client) {
|
|||||||
handleNotice(msg, client)
|
handleNotice(msg, client)
|
||||||
case commands.JOIN:
|
case commands.JOIN:
|
||||||
handleJoin(msg, client)
|
handleJoin(msg, client)
|
||||||
|
case commands.NICK:
|
||||||
|
handleNick(msg, client)
|
||||||
case commands.QUIT:
|
case commands.QUIT:
|
||||||
handleQuit(msg, client)
|
handleQuit(msg, client)
|
||||||
case commands.PART:
|
case commands.PART:
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ func (s SidePanelState) Update(msg tea.Msg) (SidePanelState, tea.Cmd) {
|
|||||||
var cmdsToProcess []tea.Cmd
|
var cmdsToProcess []tea.Cmd
|
||||||
|
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case cmds.SwitchChannelsMsg:
|
case cmds.SwitchChannelsMsg, cmds.UpdateNicksMsg:
|
||||||
s.UpdateNicks()
|
s.UpdateNicks()
|
||||||
return s, nil
|
return s, nil
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
|
|||||||
Reference in New Issue
Block a user