From 8c1db7a2f5f75ce43737acc4dc76bc875b94f8b7 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Wed, 25 Dec 2019 15:56:57 -0500 Subject: [PATCH] better UX for cancelling channel transfers --- irc/accounts.go | 5 +++-- irc/chanserv.go | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/irc/accounts.go b/irc/accounts.go index 64a406c7..88a11822 100644 --- a/irc/accounts.go +++ b/irc/accounts.go @@ -780,6 +780,7 @@ func (am *AccountManager) LoadAccount(accountName string) (result ClientAccount, } result, err = am.deserializeRawAccount(raw) + result.NameCasefolded = casefoldedAccount return } @@ -1366,8 +1367,8 @@ type AccountSettings struct { // ClientAccount represents a user account. type ClientAccount struct { // Name of the account. - Name string - // RegisteredAt represents the time that the account was registered. + Name string + NameCasefolded string RegisteredAt time.Time Credentials AccountCredentials Verified bool diff --git a/irc/chanserv.go b/irc/chanserv.go index f0be2dd5..35ad0e16 100644 --- a/irc/chanserv.go +++ b/irc/chanserv.go @@ -98,7 +98,8 @@ To prevent accidental transfers, a verification code is required. For example, $bTRANSFER #channel alice$b displays the required confirmation code, then $bTRANSFER #channel alice 2930242125$b initiates the transfer. Unless you are an IRC operator with the correct permissions, alice must -then accept the transfer, which she can do with $bTRANSFER accept #channel$b.`, +then accept the transfer, which she can do with $bTRANSFER accept #channel$b. +To cancel a pending transfer, transfer the channel to yourself.`, helpShort: `$bTRANSFER$b transfers ownership of a channel to another user.`, enabled: chanregEnabled, minParams: 2, @@ -418,17 +419,19 @@ func csTransferHandler(server *Server, client *Client, command string, params [] return } target := params[1] - _, err := server.accounts.LoadAccount(params[1]) + targetAccount, err := server.accounts.LoadAccount(params[1]) if err != nil { csNotice(rb, client.t("Account does not exist")) return } - expectedCode := unregisterConfirmationCode(regInfo.Name, regInfo.RegisteredAt) - codeValidated := 2 < len(params) && params[2] == expectedCode - if !codeValidated { - csNotice(rb, ircfmt.Unescape(client.t("$bWarning: you are about to transfer control of your channel to another user.$b"))) - csNotice(rb, fmt.Sprintf(client.t("To confirm your channel transfer, type: /CS TRANSFER %[1]s %[2]s %[3]s"), chname, target, expectedCode)) - return + if targetAccount.NameCasefolded != account { + expectedCode := unregisterConfirmationCode(regInfo.Name, regInfo.RegisteredAt) + codeValidated := 2 < len(params) && params[2] == expectedCode + if !codeValidated { + csNotice(rb, ircfmt.Unescape(client.t("$bWarning: you are about to transfer control of your channel to another user.$b"))) + csNotice(rb, fmt.Sprintf(client.t("To confirm your channel transfer, type: /CS TRANSFER %[1]s %[2]s %[3]s"), chname, target, expectedCode)) + return + } } status, err := channel.Transfer(client, target, hasPrivs) if err == nil {