3
0
mirror of https://github.com/ergochat/ergo.git synced 2025-01-03 08:32:43 +01:00

Merge pull request #1223 from hhirtz/rename

Update draft/rename impl
This commit is contained in:
Shivaram Lingamneni 2020-08-05 14:02:15 -07:00 committed by GitHub
commit 7b28fc73e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 11 deletions

View File

@ -289,6 +289,14 @@ func (cm *ChannelManager) Rename(name string, newName string) (err error) {
cm.Lock()
defer cm.Unlock()
if newCfname == cfname {
entry := cm.chans[cfname]
if entry == nil || !entry.channel.IsLoaded() {
return errNoSuchChannel
}
entry.channel.Rename(newName, cfname)
return nil
}
if cm.chans[newCfname] != nil || cm.registeredChannels.Has(newCfname) {
return errChannelNameInUse
}

View File

@ -453,10 +453,12 @@ func (channel *Channel) NameCasefolded() string {
func (channel *Channel) Rename(name, nameCasefolded string) {
channel.stateMutex.Lock()
channel.name = name
if channel.nameCasefolded != nameCasefolded {
channel.nameCasefolded = nameCasefolded
if channel.registeredFounder != "" {
channel.registeredTime = time.Now().UTC()
}
}
channel.stateMutex.Unlock()
}

View File

@ -2421,8 +2421,7 @@ func rehashHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
}
// RENAME <oldchan> <newchan> [<reason>]
func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) (result bool) {
result = false
func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
oldName, newName := msg.Params[0], msg.Params[1]
var reason string
if 2 < len(msg.Params) {
@ -2434,6 +2433,8 @@ func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
rb.Add(nil, server.name, ERR_NOSUCHCHANNEL, client.Nick(), utils.SafeErrorParam(oldName), client.t("No such channel"))
return false
}
oldName = channel.Name()
if !(channel.ClientIsAtLeast(client, modes.ChannelOperator) || client.HasRoleCapabs("chanreg")) {
rb.Add(nil, server.name, ERR_CHANOPRIVSNEEDED, client.Nick(), oldName, client.t("You're not a channel operator"))
return false
@ -2441,14 +2442,14 @@ func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
founder := channel.Founder()
if founder != "" && founder != client.Account() {
rb.Add(nil, server.name, ERR_CANNOTRENAME, client.Nick(), oldName, newName, client.t("Only channel founders can change registered channels"))
rb.Add(nil, server.name, "FAIL", "RENAME", "CANNOT_RENAME", oldName, utils.SafeErrorParam(newName), client.t("Only channel founders can change registered channels"))
return false
}
config := server.Config()
status, _ := channel.historyStatus(config)
if status == HistoryPersistent {
rb.Add(nil, server.name, ERR_CANNOTRENAME, client.Nick(), oldName, newName, client.t("Channels with persistent history cannot be renamed"))
rb.Add(nil, server.name, "FAIL", "RENAME", "CANNOT_RENAME", oldName, utils.SafeErrorParam(newName), client.t("Channels with persistent history cannot be renamed"))
return false
}
@ -2457,9 +2458,9 @@ func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
if err == errInvalidChannelName {
rb.Add(nil, server.name, ERR_NOSUCHCHANNEL, client.Nick(), utils.SafeErrorParam(newName), client.t(err.Error()))
} else if err == errChannelNameInUse {
rb.Add(nil, server.name, ERR_CHANNAMEINUSE, client.Nick(), utils.SafeErrorParam(newName), client.t(err.Error()))
rb.Add(nil, server.name, "FAIL", "RENAME", "CHANNEL_NAME_IN_USE", oldName, utils.SafeErrorParam(newName), client.t(err.Error()))
} else if err != nil {
rb.Add(nil, server.name, ERR_CANNOTRENAME, client.Nick(), oldName, utils.SafeErrorParam(newName), client.t("Cannot rename channel"))
rb.Add(nil, server.name, "FAIL", "RENAME", "CANNOT_RENAME", oldName, utils.SafeErrorParam(newName), client.t("Cannot rename channel"))
}
if err != nil {
return false

View File

@ -168,8 +168,6 @@ const (
ERR_CANNOTSENDRP = "573"
RPL_WHOISSECURE = "671"
RPL_YOURLANGUAGESARE = "687"
ERR_CHANNAMEINUSE = "692"
ERR_CANNOTRENAME = "693"
ERR_INVALIDMODEPARAM = "696"
ERR_LISTMODEALREADYSET = "697"
ERR_LISTMODENOTSET = "698"