1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Properly fix quoting in action messages

* Allow quoting in action messages if line number is >1.
* Fix regression introduced by 1244d689f6 where
  '\n' was being trimmed in action messages.
* Add comment about typing notifications placeholder that needs to be fixed.
This commit is contained in:
Zetok Zalbavar 2015-05-24 14:21:15 +01:00
parent 874abd363f
commit 87e6b038f9
No known key found for this signature in database
GPG Key ID: C953D3880212068A
2 changed files with 22 additions and 10 deletions

View File

@ -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<messageLines.size();++i)
for (int i = 0; i < messageLines.size(); ++i)
{
if (QRegExp("^(&gt;|)( |[[]|&gt;|[^_\\d\\W]).*").exactMatch(messageLines[i]))
quotedText += "<span class=quote>" + messageLines[i] + "</span>";
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("^(&gt;|)( |[[]|&gt;|[^_\\d\\W]).*").exactMatch(messageLines[i])) {
if (type != ACTION)
quotedText += "<span class=quote>" + messageLines[i] + "</span>";
else if (type == ACTION && i > 0)
quotedText += "<span class=quote>" + messageLines[i] + "</span>";
else if (type == ACTION && i == 0)
quotedText += messageLines[i];
} else {
quotedText += messageLines[i];
}
if (i < messageLines.size() - 1)
quotedText += "<br/>";

View File

@ -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: