3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

fix: set the existing channels unregistered

This commit is contained in:
Shivaram Lingamneni 2019-02-11 23:30:49 -05:00
parent 370255bec1
commit e4c9351254
4 changed files with 23 additions and 19 deletions

View File

@ -842,8 +842,18 @@ func (am *AccountManager) Unregister(account string) error {
var clients []*Client
var registeredChannels []string
// on our way out, unregister all the account's channels and delete them from the db
defer func() {
am.server.channelRegistry.deleteByAccount(casefoldedAccount, registeredChannels)
for _, channelName := range registeredChannels {
info := am.server.channelRegistry.LoadChannel(channelName)
if info != nil && info.Founder == casefoldedAccount {
am.server.channelRegistry.Delete(channelName, *info)
}
channel := am.server.channels.Get(channelName)
if channel != nil {
channel.SetUnregistered(casefoldedAccount)
}
}
}()
var credText string

View File

@ -165,10 +165,13 @@ func (channel *Channel) SetRegistered(founder string) error {
}
// SetUnregistered deletes the channel's registration information.
func (channel *Channel) SetUnregistered() {
func (channel *Channel) SetUnregistered(expectedFounder string) {
channel.stateMutex.Lock()
defer channel.stateMutex.Unlock()
if channel.registeredFounder != expectedFounder {
return
}
channel.registeredFounder = ""
var zeroTime time.Time
channel.registeredTime = zeroTime

View File

@ -215,17 +215,6 @@ func (reg *ChannelRegistry) Delete(casefoldedName string, info RegisteredChannel
})
}
// deleteByAccount is a helper to delete all channel registrations corresponding to a user account.
func (reg *ChannelRegistry) deleteByAccount(cfaccount string, cfchannels []string) {
for _, cfchannel := range cfchannels {
info := reg.LoadChannel(cfchannel)
if info == nil || info.Founder != cfaccount {
continue
}
reg.Delete(cfchannel, *info)
}
}
// Rename handles the persistence part of a channel rename: the channel is
// persisted under its new name, and the old name is cleaned up if necessary.
func (reg *ChannelRegistry) Rename(channel *Channel, casefoldedOldName string) {

View File

@ -277,11 +277,13 @@ func csUnregisterHandler(server *Server, client *Client, command string, params
return
}
hasPrivs := client.HasRoleCapabs("chanreg")
if !hasPrivs {
founder := channel.Founder()
hasPrivs = founder != "" && founder == client.Account()
if founder == "" {
csNotice(rb, client.t("That channel is not registered"))
return
}
hasPrivs := client.HasRoleCapabs("chanreg") || founder == client.Account()
if !hasPrivs {
csNotice(rb, client.t("Insufficient privileges"))
return
@ -295,8 +297,8 @@ func csUnregisterHandler(server *Server, client *Client, command string, params
return
}
channel.SetUnregistered()
go server.channelRegistry.Delete(channelKey, info)
channel.SetUnregistered(founder)
server.channelRegistry.Delete(channelKey, info)
csNotice(rb, fmt.Sprintf(client.t("Channel %s is now unregistered"), channelKey))
}