diff --git a/irc/accounts.go b/irc/accounts.go index 509196d4..3edec142 100644 --- a/irc/accounts.go +++ b/irc/accounts.go @@ -1098,7 +1098,10 @@ func (am *AccountManager) Unregister(account string, erase bool) error { // on our way out, unregister all the account's channels and delete them from the db defer func() { for _, channelName := range registeredChannels { - am.server.channels.SetUnregistered(channelName, casefoldedAccount) + err := am.server.channels.SetUnregistered(channelName, casefoldedAccount) + if err != nil { + am.server.logger.Error("internal", "couldn't unregister channel", channelName, err.Error()) + } } }() diff --git a/irc/channelmanager.go b/irc/channelmanager.go index 9312313c..1b32ffaa 100644 --- a/irc/channelmanager.go +++ b/irc/channelmanager.go @@ -226,7 +226,13 @@ func (cm *ChannelManager) SetUnregistered(channelName string, account string) (e return err } - var info RegisteredChannel + info, err := cm.server.channelRegistry.LoadChannel(cfname) + if err != nil { + return err + } + if info.Founder != account { + return errChannelNotOwnedByAccount + } defer func() { if err == nil { @@ -237,17 +243,12 @@ func (cm *ChannelManager) SetUnregistered(channelName string, account string) (e cm.Lock() defer cm.Unlock() entry := cm.chans[cfname] - if entry == nil { - return errNoSuchChannel - } - info = entry.channel.ExportRegistration(0) - if info.Founder != account { - return errChannelNotOwnedByAccount - } - entry.channel.SetUnregistered(account) - delete(cm.registeredChannels, cfname) - if skel, err := Skeleton(entry.channel.Name()); err == nil { - delete(cm.registeredSkeletons, skel) + if entry != nil { + entry.channel.SetUnregistered(account) + delete(cm.registeredChannels, cfname) + if skel, err := Skeleton(entry.channel.Name()); err == nil { + delete(cm.registeredSkeletons, skel) + } } return nil } diff --git a/irc/channelreg.go b/irc/channelreg.go index c1140538..31b68254 100644 --- a/irc/channelreg.go +++ b/irc/channelreg.go @@ -231,6 +231,7 @@ func (reg *ChannelRegistry) LoadChannel(nameCasefolded string) (info RegisteredC info = RegisteredChannel{ Name: name, + NameCasefolded: nameCasefolded, RegisteredAt: time.Unix(regTimeInt, 0).UTC(), Founder: founder, Topic: topic,