Chat mention fixes
+ fixed some issues with highlighting entire line + added case insensative mentions
This commit is contained in:
parent
f51e558e57
commit
639cbefee0
2 changed files with 19 additions and 5 deletions
|
@ -9,7 +9,6 @@
|
|||
#include "pixmapgenerator.h"
|
||||
#include "settingscache.h"
|
||||
#include "main.h"
|
||||
#include "userlist.h"
|
||||
#include "tab_userlists.h"
|
||||
|
||||
const QColor MENTION_COLOR = QColor(190, 25, 85); // maroon
|
||||
|
@ -206,14 +205,16 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
|
|||
QString userMention = message.left(mentionEndIndex);
|
||||
QString userName = userMention.right(userMention.size()-1).normalized(QString::NormalizationForm_D);
|
||||
QMap<QString, UserListTWI *> userList = tabSupervisor->getUserListsTab()->getAllUsersList()->getUsers();
|
||||
if (userList.contains(userName)) {
|
||||
UserListTWI *vlu = userList.value(userName);
|
||||
mentionFormatOtherUser.setAnchorHref("user://" + QString::number(vlu->getUserInfo().user_level()) + "_" + userName);
|
||||
cursor.insertText("@" + userName, mentionFormatOtherUser);
|
||||
QString correctUserName = getCorrectUserName(userList, userName);
|
||||
if (!correctUserName.isEmpty()) {
|
||||
UserListTWI *vlu = userList.value(correctUserName);
|
||||
mentionFormatOtherUser.setAnchorHref("user://" + QString::number(vlu->getUserInfo().user_level()) + "_" + correctUserName);
|
||||
cursor.insertText("@" + correctUserName, mentionFormatOtherUser);
|
||||
} else
|
||||
cursor.insertText("@" + userName, defaultFormat);
|
||||
message = message.mid(userName.size() + 1);
|
||||
}
|
||||
cursor.setCharFormat(defaultFormat); // reset format after each itteration
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -224,6 +225,17 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
|
|||
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
|
||||
}
|
||||
|
||||
|
||||
QString ChatView::getCorrectUserName(QMap<QString, UserListTWI *> &userList, QString &userName) {
|
||||
QMap<QString, UserListTWI *>::iterator i;
|
||||
QString lowerUserName = userName.toLower();
|
||||
for (i = userList.begin(); i != userList.end(); ++i) {
|
||||
if (i.key().toLower() == lowerUserName)
|
||||
return i.key();
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
void ChatView::clearChat() {
|
||||
document()->clear();
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <QTextFragment>
|
||||
#include <QTextCursor>
|
||||
#include <QColor>
|
||||
#include "userlist.h"
|
||||
#include "user_level.h"
|
||||
#include "tab_supervisor.h"
|
||||
|
||||
|
@ -35,6 +36,7 @@ private:
|
|||
QTextCursor prepareBlock(bool same = false);
|
||||
void appendCardTag(QTextCursor &cursor, const QString &cardName);
|
||||
void appendUrlTag(QTextCursor &cursor, QString url);
|
||||
QString getCorrectUserName(QMap<QString, UserListTWI *> &userList, QString &userName);
|
||||
private slots:
|
||||
void openLink(const QUrl &link);
|
||||
public:
|
||||
|
|
Loading…
Reference in a new issue