From 87e6b038f9a4d71f0df2f980db69d6f0b1aa67d1 Mon Sep 17 00:00:00 2001 From: Zetok Zalbavar Date: Sun, 24 May 2015 14:21:15 +0100 Subject: [PATCH] Properly fix quoting in action messages * Allow quoting in action messages if line number is >1. * Fix regression introduced by 1244d689f6ea1717ce247be4526a4fb72b93853c where '\n' was being trimmed in action messages. * Add comment about typing notifications placeholder that needs to be fixed. --- src/chatlog/chatmessage.cpp | 30 +++++++++++++++++++++--------- src/chatlog/chatmessage.h | 2 +- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/chatlog/chatmessage.cpp b/src/chatlog/chatmessage.cpp index 5c82ee2e1..c58959491 100644 --- a/src/chatlog/chatmessage.cpp +++ b/src/chatlog/chatmessage.cpp @@ -46,6 +46,8 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString &sender, const QSt if (Settings::getInstance().getUseEmoticons()) text = SmileyPack::getInstance().smileyfied(text); + //quotes (green text) + text = detectQuotes(detectAnchors(text), type); switch(type) { @@ -55,13 +57,9 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString &sender, const QSt msg->setAsAction(); break; case ALERT: - // quotes should not be available for action messages ↑ - text = detectQuotes(detectAnchors(text)); //quotes (green text) text = wrapDiv(text, "alert"); break; default: - // quotes should not be avaialble for action messages - text = detectQuotes(detectAnchors(text)); //quotes (green text) text = wrapDiv(text, "msg"); } @@ -112,6 +110,11 @@ ChatMessage::Ptr ChatMessage::createTypingNotification() ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage); // Note: "[user]..." is just a placeholder. The actual text is set in ChatForm::setFriendTyping() + // + // FIXME: Due to circumstances, placeholder is being used in a case where + // user received typing notifications constantly since contact came online. + // This causes "[user]..." to be displayed in place of user nick, as long + // as user will keep typing. Issue #1280 msg->addColumn(new NotificationIcon(QSize(18, 18)), ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right)); msg->addColumn(new Text("[user]...", Style::getFont(Style::Big), false, ""), ColumnFormat(1.0, ColumnFormat::VariableSize, ColumnFormat::Left)); @@ -198,17 +201,26 @@ QString ChatMessage::detectAnchors(const QString &str) return out; } -QString ChatMessage::detectQuotes(const QString& str) +QString ChatMessage::detectQuotes(const QString& str, MessageType type) { // detect text quotes QStringList messageLines = str.split("\n"); QString quotedText; - for (int i=0;i"; - else + // don't quote first line in action message. This makes co-existence of + // quotes and action messages possible, since only first line can cause + // problems in case where there is quote in it used. + if (QRegExp("^(>|>)( |[[]|>|[^_\\d\\W]).*").exactMatch(messageLines[i])) { + if (type != ACTION) + quotedText += "" + messageLines[i] + ""; + else if (type == ACTION && i > 0) + quotedText += "" + messageLines[i] + ""; + else if (type == ACTION && i == 0) + quotedText += messageLines[i]; + } else { quotedText += messageLines[i]; + } if (i < messageLines.size() - 1) quotedText += "
"; diff --git a/src/chatlog/chatmessage.h b/src/chatlog/chatmessage.h index f145500ac..d28967199 100644 --- a/src/chatlog/chatmessage.h +++ b/src/chatlog/chatmessage.h @@ -57,7 +57,7 @@ public: protected: static QString detectAnchors(const QString& str); - static QString detectQuotes(const QString& str); + static QString detectQuotes(const QString& str, MessageType type); static QString wrapDiv(const QString& str, const QString& div); private: