From 5f81d8efc8105d3c01e4510fbc5380a13854fcad Mon Sep 17 00:00:00 2001 From: AsamK Date: Mon, 31 Aug 2015 01:38:09 +0200 Subject: [PATCH 1/3] Remove nick from anchor names, causes problems - Nicknames that contain " could break the formatting - Nicknames containing chars like < or > were converted to html entities by the QTextBrowser so the anchor was no longer identical with the anchor stored in the _listMsg list --- retroshare-gui/src/gui/chat/ChatLobbyUserNotify.cpp | 3 +-- retroshare-gui/src/gui/chat/ChatWidget.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/retroshare-gui/src/gui/chat/ChatLobbyUserNotify.cpp b/retroshare-gui/src/gui/chat/ChatLobbyUserNotify.cpp index 68c31417b..2f0054f7b 100644 --- a/retroshare-gui/src/gui/chat/ChatLobbyUserNotify.cpp +++ b/retroshare-gui/src/gui/chat/ChatLobbyUserNotify.cpp @@ -257,9 +257,8 @@ void ChatLobbyUserNotify::chatLobbyNewMessage(ChatLobbyId lobby_id, QDateTime ti if ((bGetNickName || bFoundTextToNotify || _bCountUnRead)){ QString strAnchor = time.toString(Qt::ISODate); - strAnchor.append("_").append(senderName); MsgData msgData; - msgData.text=msg; + msgData.text=senderName + ": " + msg; msgData.unread=!(bGetNickName || bFoundTextToNotify); _listMsg[lobby_id][strAnchor]=msgData; diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index b5adf84d7..ac6a66152 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -902,7 +902,7 @@ void ChatWidget::addChatMsg(bool incoming, const QString &name, const QDateTime QString formatMsg = chatStyle.formatMessage(type, name, dtTimestamp, formattedMessage, formatFlag); QString timeStamp = dtTimestamp.toString(Qt::ISODate); - formatMsg.prepend(QString("").arg(timeStamp).arg(name)); + formatMsg.prepend(QString("").arg(timeStamp)); //To call this anchor do: ui->textBrowser->scrollToAnchor(QString("%1_%2").arg(timeStamp).arg(name)); QTextCursor textCursor = QTextCursor(ui->textBrowser->textCursor()); textCursor.movePosition(QTextCursor::End); From bd6bb8996be14f89a16eede7c5c05fb06de7be6d Mon Sep 17 00:00:00 2001 From: AsamK Date: Mon, 31 Aug 2015 02:09:55 +0200 Subject: [PATCH 2/3] Improve performance of eventFilter in chat lobbies - Only check the anchors if the visible content has actually changed by saving lastUpdateCursorPos and End - Check notify first, before doing any work - Simplify regexp as the anchors have a fixed format - Remove unnecessary conversion to utf8 and back --- retroshare-gui/src/gui/chat/ChatWidget.cpp | 28 ++++++++++------------ retroshare-gui/src/gui/chat/ChatWidget.h | 3 +++ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index ac6a66152..42344c4c8 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -448,7 +448,7 @@ bool ChatWidget::eventFilter(QObject *obj, QEvent *event) } } - if (chatType() == CHATTYPE_LOBBY) { + if (notify && chatType() == CHATTYPE_LOBBY) { if ((event->type() == QEvent::KeyPress) || (event->type() == QEvent::MouseMove) || (event->type() == QEvent::Enter) @@ -460,9 +460,11 @@ bool ChatWidget::eventFilter(QObject *obj, QEvent *event) QPoint bottom_right(ui->textBrowser->viewport()->width() - 1, ui->textBrowser->viewport()->height() - 1); int end_pos = ui->textBrowser->cursorForPosition(bottom_right).position(); cursor.setPosition(end_pos, QTextCursor::KeepAnchor); - - if (!cursor.selectedText().isEmpty()){ - QRegExp rx("toUtf8(); - std::string stdString=std::string(bytArray.begin(),bytArray.end()); - if (notify) notify->chatLobbyCleared(chatId.toLobbyId() - ,QString::fromUtf8(stdString.c_str()) - ,obj != ui->textBrowser && obj != ui->textBrowser->viewport());//, true); + notify->chatLobbyCleared(chatId.toLobbyId(), *it); } - } + } } } } @@ -490,11 +488,11 @@ bool ChatWidget::eventFilter(QObject *obj, QEvent *event) QKeyEvent *keyEvent = static_cast(event); if (keyEvent) { - if (keyEvent->key() == Qt::Key_Delete ) { + if (notify && keyEvent->key() == Qt::Key_Delete) { // Delete key pressed if (ui->textBrowser->textCursor().selectedText().length() > 0) { if (chatType() == CHATTYPE_LOBBY) { - QRegExp rx("textBrowser->textCursor().selection().toHtml(); QStringList anchors; @@ -505,9 +503,7 @@ bool ChatWidget::eventFilter(QObject *obj, QEvent *event) } for (QStringList::iterator it=anchors.begin();it!=anchors.end();++it) { - QByteArray bytArray=it->toUtf8(); - std::string stdString=std::string(bytArray.begin(),bytArray.end()); - if (notify) notify->chatLobbyCleared(chatId.toLobbyId(), QString::fromUtf8(stdString.c_str())); + notify->chatLobbyCleared(chatId.toLobbyId(), *it); } } @@ -529,7 +525,7 @@ bool ChatWidget::eventFilter(QObject *obj, QEvent *event) cursor.select(QTextCursor::WordUnderCursor); QString toolTipText = ""; if (!cursor.selectedText().isEmpty()){ - QRegExp rx(" Date: Mon, 31 Aug 2015 16:38:28 +0200 Subject: [PATCH 3/3] Escape name before inserting in name changed message and in anchor info --- retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp | 2 +- retroshare-gui/src/gui/chat/ChatLobbyUserNotify.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp b/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp index 7bc1e8c1f..a72c72bae 100644 --- a/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp +++ b/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp @@ -671,7 +671,7 @@ void ChatLobbyDialog::displayLobbyEvent(int event_type, const RsGxsId& gxs_id, c ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), - tr("%1 changed his name to: %2").arg(name).arg(newname), + tr("%1 changed his name to: %2").arg(RsHtml::plainText(name)).arg(RsHtml::plainText(newname)), ChatWidget::MSGTYPE_SYSTEM); // TODO if a user was muted and changed his name, update mute list, but only, when the muted peer, dont change his name to a other peer in your chat lobby diff --git a/retroshare-gui/src/gui/chat/ChatLobbyUserNotify.cpp b/retroshare-gui/src/gui/chat/ChatLobbyUserNotify.cpp index 2f0054f7b..bed476b7f 100644 --- a/retroshare-gui/src/gui/chat/ChatLobbyUserNotify.cpp +++ b/retroshare-gui/src/gui/chat/ChatLobbyUserNotify.cpp @@ -28,6 +28,7 @@ #include "gui/settings/rsharesettings.h" #include "util/DateTime.h" #include +#include ChatLobbyUserNotify::ChatLobbyUserNotify(QObject *parent) : UserNotify(parent) @@ -258,7 +259,7 @@ void ChatLobbyUserNotify::chatLobbyNewMessage(ChatLobbyId lobby_id, QDateTime ti if ((bGetNickName || bFoundTextToNotify || _bCountUnRead)){ QString strAnchor = time.toString(Qt::ISODate); MsgData msgData; - msgData.text=senderName + ": " + msg; + msgData.text=RsHtml::plainText(senderName) + ": " + msg; msgData.unread=!(bGetNickName || bFoundTextToNotify); _listMsg[lobby_id][strAnchor]=msgData;