Use timestamp format for manual away, not restore
authorShane Synan <digitalcircuit36939@gmail.com>
Sun, 8 Jan 2017 22:52:38 +0000 (16:52 -0600)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 13 Apr 2017 19:56:06 +0000 (21:56 +0200)
Apply the timestamp formatting to manual /away commands, too.  This
offers consistency between the auto-away settings and manual away.

Add skipFormatting flag to handleAway/issueAway commands to skip
applying timestamp formatting.  This avoids re-processing timestamp
formatting when restarting the core, leaving any '%%' as '%%'.  The
message should already be processed once stored.

More comments!

src/core/corenetwork.cpp
src/core/coresession.cpp
src/core/coresession.h
src/core/coreuserinputhandler.cpp
src/core/coreuserinputhandler.h

index fdfc869..4d1fc01 100644 (file)
@@ -656,8 +656,11 @@ void CoreNetwork::networkInitialized()
 
     // restore away state
     QString awayMsg = Core::awayMessage(userId(), networkId());
-    if (!awayMsg.isEmpty())
-        userInputHandler()->handleAway(BufferInfo(), Core::awayMessage(userId(), networkId()));
+    if (!awayMsg.isEmpty()) {
+        // Don't re-apply any timestamp formatting in order to preserve escaped percent signs, e.g.
+        // '%%%%%%%%' -> '%%%%'  If processed again, it'd result in '%%'.
+        userInputHandler()->handleAway(BufferInfo(), awayMsg, true);
+    }
 
     sendPerform();
 
index 43b2234..39bd69b 100644 (file)
@@ -670,7 +670,7 @@ void CoreSession::clientsDisconnected()
 }
 
 
-void CoreSession::globalAway(const QString &msg)
+void CoreSession::globalAway(const QString &msg, const bool skipFormatting)
 {
     QHash<NetworkId, CoreNetwork *>::iterator netIter = _networks.begin();
     CoreNetwork *net = 0;
@@ -681,7 +681,7 @@ void CoreSession::globalAway(const QString &msg)
         if (!net->isConnected())
             continue;
 
-        net->userInputHandler()->issueAway(msg, false /* no force away */);
+        net->userInputHandler()->issueAway(msg, false /* no force away */, skipFormatting);
     }
 }
 
index 950dfb2..849575f 100644 (file)
@@ -133,8 +133,13 @@ public slots:
 
     QHash<QString, QString> persistentChannels(NetworkId) const;
 
-    //! Marks us away (or unaway) on all networks
-    void globalAway(const QString &msg = QString());
+    /**
+     * Marks us away (or unaway) on all networks
+     *
+     * @param[in] msg             Away message, or blank to set unaway
+     * @param[in] skipFormatting  If true, skip timestamp formatting codes (e.g. if already done)
+     */
+    void globalAway(const QString &msg = QString(), const bool skipFormatting = false);
 
 signals:
     void initialized();
index b616a5d..755e64a 100644 (file)
@@ -61,29 +61,38 @@ void CoreUserInputHandler::handleUserInput(const BufferInfo &bufferInfo, const Q
 // ====================
 //  Public Slots
 // ====================
-void CoreUserInputHandler::handleAway(const BufferInfo &bufferInfo, const QString &msg)
+void CoreUserInputHandler::handleAway(const BufferInfo &bufferInfo, const QString &msg,
+                                      const bool skipFormatting)
 {
     Q_UNUSED(bufferInfo)
     if (msg.startsWith("-all")) {
         if (msg.length() == 4) {
-            coreSession()->globalAway();
+            coreSession()->globalAway(QString(), skipFormatting);
             return;
         }
         Q_ASSERT(msg.length() > 4);
         if (msg[4] == ' ') {
-            coreSession()->globalAway(msg.mid(5));
+            coreSession()->globalAway(msg.mid(5), skipFormatting);
             return;
         }
     }
-    issueAway(msg);
+    issueAway(msg, true /* force away */, skipFormatting);
 }
 
 
-void CoreUserInputHandler::issueAway(const QString &msg, bool autoCheck)
+void CoreUserInputHandler::issueAway(const QString &msg, bool autoCheck, const bool skipFormatting)
 {
     QString awayMsg = msg;
     IrcUser *me = network()->me();
 
+    // Only apply timestamp formatting when requested
+    // This avoids re-processing any existing away message when the core restarts, so chained escape
+    // percent signs won't get down-processed.
+    if (!skipFormatting) {
+        // Apply the timestamp formatting to the away message (if empty, nothing will happen)
+        awayMsg = formatCurrentDateTimeInString(awayMsg);
+    }
+
     // if there is no message supplied we have to check if we are already away or not
     if (autoCheck && msg.isEmpty()) {
         if (me && !me->isAway()) {
index 821d185..b13fd39 100644 (file)
@@ -39,7 +39,17 @@ public:
     int lastParamOverrun(const QString &cmd, const QList<QByteArray> &params);
 
 public slots:
-    void handleAway(const BufferInfo &bufferInfo, const QString &text);
+    /**
+     * Handle the away command, marking as away or unaway
+     *
+     * Applies to the current network unless text begins with "-all".
+     *
+     * @param[in] bufferInfo      Currently active buffer
+     * @param[in] text            Away message, or blank to set unaway
+     * @param[in] skipFormatting  If true, skip timestamp formatting codes (e.g. if already done)
+     */
+    void handleAway(const BufferInfo &bufferInfo, const QString &text,
+                    const bool skipFormatting = true);
     void handleBan(const BufferInfo &bufferInfo, const QString &text);
     void handleUnban(const BufferInfo &bufferInfo, const QString &text);
     void handleCtcp(const BufferInfo &bufferInfo, const QString &text);
@@ -86,7 +96,15 @@ public slots:
      * @param forceImmediate  Immediately quit, skipping queue of other commands
      */
     void issueQuit(const QString &reason, bool forceImmediate = false);
-    void issueAway(const QString &msg, bool autoCheck = true);
+
+    /**
+     * Issues the away command, marking as away or unaway on the current network
+     *
+     * @param[in] msg             Away message, or blank to set unaway
+     * @param[in] autoCheck       If true, always set away, defaulting to the identity away message
+     * @param[in] skipFormatting  If true, skip timestamp formatting codes (e.g. if already done)
+     */
+    void issueAway(const QString &msg, bool autoCheck = true, const bool skipFormatting = false);
 
 protected:
     void timerEvent(QTimerEvent *event);