core: Implement setname
authorJanne Koschinski <janne@kuschku.de>
Tue, 21 Jul 2020 00:02:04 +0000 (20:02 -0400)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 28 Nov 2020 12:42:31 +0000 (13:42 +0100)
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
src/common/irccap.h
src/core/coresessioneventprocessor.cpp
src/core/coresessioneventprocessor.h
src/core/coreuserinputhandler.cpp
src/core/coreuserinputhandler.h

index 667f32f..7f18e66 100644 (file)
@@ -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)
index e1615f7..af7d0ab 100644 (file)
@@ -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,
index ec988ff..6142fa8 100644 (file)
@@ -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 <bruce@wayne.enterprises>
+//
+// 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)
 {
index 1e743bb..1b309f8 100644 (file)
@@ -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
index 82c2b90..8ab8dce 100644 (file)
@@ -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();
index 770eae4..26e8500 100644 (file)
@@ -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);