Guild leaving / deleting didn't clean up properly
Too many wrong IFs that prevented anything from happening at all and the
chatview wasn't properly cleaned up with the corresponding function.
MODIFY
ui/guildlist.go
ui/guildlist.go
@@ -105,17 +105,12 @@ func (g *GuildList) SetOnGuildSelect(handler func(guildID string)) {
// RemoveGuild removes the node that refers to the given guildID.
func (g *GuildList) RemoveGuild(guildID string) {
children := g.GetRoot().GetChildren()
- indexToRemove := -1
for index, node := range children {
if node.GetReference() == guildID {
- indexToRemove = index
+ g.GetRoot().SetChildren(append(children[:index], children[index+1:]...))
break
}
}
-
- if indexToRemove != -1 {
- g.GetRoot().SetChildren(append(children[:indexToRemove], children[indexToRemove+1:]...))
- }
}
// AddGuild adds a new node that references the given guildID and shows the
@@ -128,11 +123,9 @@ func (g *GuildList) AddGuild(guildID, name string) {
// UpdateName updates the name of the guild with the given ID.
func (g *GuildList) UpdateName(guildID, newName string) {
- for _, node := range g.GetRoot().GetChildren() {
- if node.GetReference() == guildID {
+ node := tviewutil.GetNodeByReference(guildID, g.TreeView)
+ if node != nil {
node.SetText(tviewutil.Escape(newName))
- break
- }
}
}
@@ -144,7 +137,7 @@ func (g *GuildList) setNotificationCount(count int) {
}
}
-func (g *GuildList) amountOfUnreadGuilds() int {
+func (g *GuildList) countUnreadGuilds() int {
var unreadCount int
for _, child := range g.GetRoot().GetChildren() {
if !readstate.HasGuildBeenRead((child.GetReference()).(string)) {
@@ -158,7 +151,7 @@ func (g *GuildList) amountOfUnreadGuilds() int {
// UpdateUnreadGuildCount finds the number of guilds containing unread
// channels and updates the title accordingly.
func (g *GuildList) UpdateUnreadGuildCount() {
- g.setNotificationCount(g.amountOfUnreadGuilds())
+ g.setNotificationCount(g.countUnreadGuilds())
}
// MarkAsLoaded selects the guild and marks it as loaded.

MODIFY
ui/window.go
ui/window.go
@@ -1879,25 +1879,25 @@ func (window *Window) registerGuildHandlers() {
go func() {
for guildRemove := range guildRemoveChannel {
- if window.selectedGuild == nil {
- continue
- }
-
if window.previousChannel != nil && window.previousChannel.GuildID == guildRemove.ID {
window.previousChannel = nil
}
- if window.selectedGuild.ID == guildRemove.ID {
guildID := guildRemove.ID
+ window.guildList.RemoveGuild(guildID)
+
+ selectedGuild := window.selectedGuild
+ if selectedGuild != nil && selectedGuild.ID == guildID {
window.app.QueueUpdateDraw(func() {
if window.selectedChannel != nil && window.selectedChannel.GuildID == guildID {
- window.chatView.ClearViewAndCache()
- window.selectedChannel = nil
+ window.UnloadChannel()
+ //Unload channel sets the selectedChannel as the previous
+ //one, which isn't correct.
+ window.previousChannel = nil
}
window.channelTree.Clear()
window.userList.Clear()
- window.guildList.RemoveGuild(guildID)
window.selectedGuild = nil
})
}

Guild leaving / deleting didn't clean up properly

Too many wrong IFs that prevented anything from happening at all and the
chatview wasn't properly cleaned up with the corresponding function.