Correct issue where messages were over-trimmed
[quassel.git] / src / core / coreuserinputhandler.cpp
index b616a5d..8d35fec 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()) {
@@ -451,8 +460,7 @@ void CoreUserInputHandler::handleMe(const BufferInfo &bufferInfo, const QString
     QStringList messages = msg.split(QCharLF);
 
     foreach (auto message, messages) {
-        // Handle each separated message independently, ignoring any carriage returns
-        message = message.trimmed();
+        // Handle each separated message independently
         coreNetwork()->coreSession()->ctcpParser()->query(coreNetwork(), bufferInfo.bufferName(),
                                                           "ACTION", message);
         emit displayMsg(Message::Action, bufferInfo.type(), bufferInfo.bufferName(), message,
@@ -523,8 +531,7 @@ void CoreUserInputHandler::handleNotice(const BufferInfo &bufferInfo, const QStr
     QStringList messages = msg.section(' ', 1).split(QCharLF);
 
     foreach (auto message, messages) {
-        // Handle each separated message independently, ignoring any carriage returns
-        message = message.trimmed();
+        // Handle each separated message independently
         params.clear();
         params << serverEncode(bufferName) << channelEncode(bufferInfo.bufferName(), message);
         emit putCmd("NOTICE", params);
@@ -598,8 +605,7 @@ void CoreUserInputHandler::handleQuery(const BufferInfo &bufferInfo, const QStri
     QStringList messages = msg.section(' ', 1).split(QCharLF);
 
     foreach (auto message, messages) {
-        // Handle each separated message independently, ignoring any carriage returns
-        message = message.trimmed();
+        // Handle each separated message independently
         if (message.isEmpty()) {
             emit displayMsg(Message::Server, BufferInfo::QueryBuffer, target,
                             tr("Starting query with %1").arg(target), network()->myNick(),
@@ -647,11 +653,10 @@ void CoreUserInputHandler::handleSay(const BufferInfo &bufferInfo, const QString
 
     // Split apart messages at line feeds.  The IRC protocol uses those to separate commands, so
     // they need to be split into multiple messages.
-    QStringList messages = msg.split(QCharLF);
+    QStringList messages = msg.split(QCharLF, QString::SkipEmptyParts);
 
     foreach (auto message, messages) {
-        // Handle each separated message independently, ignoring any carriage returns
-        message = message.trimmed();
+        // Handle each separated message independently
 #ifdef HAVE_QCA2
         putPrivmsg(bufferInfo.bufferName(), message, encodeFunc,
                    network()->cipher(bufferInfo.bufferName()));