From 4e40c486dea949244b73beaf73d5ceb1ef591b5b Mon Sep 17 00:00:00 2001 From: Janne Koschinski Date: Mon, 20 Jul 2020 20:02:04 -0400 Subject: [PATCH] core: Implement setname Implement the IRCv3 "setname" capability, allowing Quassel to receive updates to other nicknames' realnames, similar to "away-notify". Add the "/setname" command to allow setting one's own realname without reconnecting. This requires the server to support "setname". [Original commit by justJanne, tweaked by digitalcircuit - setname is now ratified and official, hooray!] See https://ircv3.net/specs/extensions/setname --- src/common/eventmanager.h | 1 + src/common/irccap.h | 8 ++++++++ src/core/coresessioneventprocessor.cpp | 19 +++++++++++++++++++ src/core/coresessioneventprocessor.h | 1 + src/core/coreuserinputhandler.cpp | 6 ++++++ src/core/coreuserinputhandler.h | 7 +++++++ 6 files changed, 42 insertions(+) diff --git a/src/common/eventmanager.h b/src/common/eventmanager.h index 667f32fc..7f18e66e 100644 --- a/src/common/eventmanager.h +++ b/src/common/eventmanager.h @@ -110,6 +110,7 @@ public: IrcEventTagmsg, IrcEventTopic, IrcEventError, /// ERROR message from server + IrcEventSetname, ///< Updated realname information IrcEventWallops, IrcEventRawPrivmsg, ///< Undecoded privmsg (still needs CTCP parsing) IrcEventRawNotice, ///< Undecoded notice (still needs CTCP parsing) diff --git a/src/common/irccap.h b/src/common/irccap.h index e1615f73..af7d0ab8 100644 --- a/src/common/irccap.h +++ b/src/common/irccap.h @@ -93,6 +93,13 @@ namespace IrcCap { */ const QString SASL = "sasl"; + /** + * Allows updating realname without reconnecting + * + * https://ircv3.net/specs/extensions/setname + */ + const QString SETNAME = "setname"; + /** * Userhost in names replies. * @@ -147,6 +154,7 @@ namespace IrcCap { EXTENDED_JOIN, MULTI_PREFIX, SASL, + SETNAME, USERHOST_IN_NAMES, SERVER_TIME, Vendor::TWITCH_MEMBERSHIP, diff --git a/src/core/coresessioneventprocessor.cpp b/src/core/coresessioneventprocessor.cpp index ec988ff5..6142fa86 100644 --- a/src/core/coresessioneventprocessor.cpp +++ b/src/core/coresessioneventprocessor.cpp @@ -789,6 +789,25 @@ void CoreSessionEventProcessor::processIrcEventError(IrcEvent* e) } } + +// IRCv3 SETNAME - ":nick!user@host SETNAME :realname goes here" +// Example: :batman!~batman@bat.cave SETNAME :Bruce Wayne +// +// See https://ircv3.net/specs/extensions/setname +void CoreSessionEventProcessor::processIrcEventSetname(IrcEvent* e) +{ + if (checkParamCount(e, 1)) { + IrcUser* ircuser = e->network()->updateNickFromMask(e->prefix()); + if (!ircuser) { + qWarning() << Q_FUNC_INFO << "Unknown IrcUser!"; + return; + } + + QString newname = e->params().at(0); + ircuser->setRealName(newname); + } +} + #ifdef HAVE_QCA2 void CoreSessionEventProcessor::processKeyEvent(KeyEvent* e) { diff --git a/src/core/coresessioneventprocessor.h b/src/core/coresessioneventprocessor.h index 1e743bbb..1b309f8f 100644 --- a/src/core/coresessioneventprocessor.h +++ b/src/core/coresessioneventprocessor.h @@ -64,6 +64,7 @@ public: Q_INVOKABLE void lateProcessIrcEventQuit(IrcEvent* event); Q_INVOKABLE void processIrcEventTopic(IrcEvent* event); Q_INVOKABLE void processIrcEventError(IrcEvent* event); /// ERROR message from server + Q_INVOKABLE void processIrcEventSetname(IrcEvent* event); ///< Updated realname information #ifdef HAVE_QCA2 Q_INVOKABLE void processKeyEvent(KeyEvent* event); #endif diff --git a/src/core/coreuserinputhandler.cpp b/src/core/coreuserinputhandler.cpp index 82c2b90e..8ab8dce9 100644 --- a/src/core/coreuserinputhandler.cpp +++ b/src/core/coreuserinputhandler.cpp @@ -799,6 +799,12 @@ void CoreUserInputHandler::handleSetkey(const BufferInfo& bufferInfo, const QStr #endif } +void CoreUserInputHandler::handleSetname(const BufferInfo& bufferInfo, const QString& msg) +{ + Q_UNUSED(bufferInfo) + emit putCmd("SETNAME", serverEncode(msg)); +} + void CoreUserInputHandler::handleShowkey(const BufferInfo& bufferInfo, const QString& msg) { QString bufname = bufferInfo.bufferName().isNull() ? "" : bufferInfo.bufferName(); diff --git a/src/core/coreuserinputhandler.h b/src/core/coreuserinputhandler.h index 770eae41..26e85000 100644 --- a/src/core/coreuserinputhandler.h +++ b/src/core/coreuserinputhandler.h @@ -79,6 +79,13 @@ public slots: void handleQuote(const BufferInfo& bufferInfo, const QString& text); void handleSay(const BufferInfo& bufferInfo, const QString& text); void handleSetkey(const BufferInfo& bufferInfo, const QString& text); + /** + * Handle the setname command, setting the user's realname + * + * @param bufferInfo Currently active buffer + * @param text New realname + */ + void handleSetname(const BufferInfo& bufferInfo, const QString& text); void handleShowkey(const BufferInfo& bufferInfo, const QString& text); void handleTopic(const BufferInfo& bufferInfo, const QString& text); void handleVoice(const BufferInfo& bufferInfo, const QString& text); -- 2.20.1