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:
parent
370255bec1
commit
e4c9351254
@ -842,8 +842,18 @@ func (am *AccountManager) Unregister(account string) error {
|
|||||||
var clients []*Client
|
var clients []*Client
|
||||||
|
|
||||||
var registeredChannels []string
|
var registeredChannels []string
|
||||||
|
// on our way out, unregister all the account's channels and delete them from the db
|
||||||
defer func() {
|
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
|
var credText string
|
||||||
|
@ -165,10 +165,13 @@ func (channel *Channel) SetRegistered(founder string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetUnregistered deletes the channel's registration information.
|
// SetUnregistered deletes the channel's registration information.
|
||||||
func (channel *Channel) SetUnregistered() {
|
func (channel *Channel) SetUnregistered(expectedFounder string) {
|
||||||
channel.stateMutex.Lock()
|
channel.stateMutex.Lock()
|
||||||
defer channel.stateMutex.Unlock()
|
defer channel.stateMutex.Unlock()
|
||||||
|
|
||||||
|
if channel.registeredFounder != expectedFounder {
|
||||||
|
return
|
||||||
|
}
|
||||||
channel.registeredFounder = ""
|
channel.registeredFounder = ""
|
||||||
var zeroTime time.Time
|
var zeroTime time.Time
|
||||||
channel.registeredTime = zeroTime
|
channel.registeredTime = zeroTime
|
||||||
|
@ -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
|
// 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.
|
// persisted under its new name, and the old name is cleaned up if necessary.
|
||||||
func (reg *ChannelRegistry) Rename(channel *Channel, casefoldedOldName string) {
|
func (reg *ChannelRegistry) Rename(channel *Channel, casefoldedOldName string) {
|
||||||
|
@ -277,11 +277,13 @@ func csUnregisterHandler(server *Server, client *Client, command string, params
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
hasPrivs := client.HasRoleCapabs("chanreg")
|
founder := channel.Founder()
|
||||||
if !hasPrivs {
|
if founder == "" {
|
||||||
founder := channel.Founder()
|
csNotice(rb, client.t("That channel is not registered"))
|
||||||
hasPrivs = founder != "" && founder == client.Account()
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hasPrivs := client.HasRoleCapabs("chanreg") || founder == client.Account()
|
||||||
if !hasPrivs {
|
if !hasPrivs {
|
||||||
csNotice(rb, client.t("Insufficient privileges"))
|
csNotice(rb, client.t("Insufficient privileges"))
|
||||||
return
|
return
|
||||||
@ -295,8 +297,8 @@ func csUnregisterHandler(server *Server, client *Client, command string, params
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
channel.SetUnregistered()
|
channel.SetUnregistered(founder)
|
||||||
go server.channelRegistry.Delete(channelKey, info)
|
server.channelRegistry.Delete(channelKey, info)
|
||||||
csNotice(rb, fmt.Sprintf(client.t("Channel %s is now unregistered"), channelKey))
|
csNotice(rb, fmt.Sprintf(client.t("Channel %s is now unregistered"), channelKey))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user