diff --git a/cockatrice/src/chatview.cpp b/cockatrice/src/chatview.cpp index 746fdbf5..ff36a091 100644 --- a/cockatrice/src/chatview.cpp +++ b/cockatrice/src/chatview.cpp @@ -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 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 = getNameFromUserList(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,20 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use verticalScrollBar()->setValue(verticalScrollBar()->maximum()); } +/** + Returns the correct case version of the provided username, if no correct casing version + was found then the provided name is not available and will return an empty QString. + */ +QString ChatView::getNameFromUserList(QMap &userList, QString &userName) { + QMap::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(); } diff --git a/cockatrice/src/chatview.h b/cockatrice/src/chatview.h index 68037d4a..17cdd398 100644 --- a/cockatrice/src/chatview.h +++ b/cockatrice/src/chatview.h @@ -5,6 +5,7 @@ #include #include #include +#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 getNameFromUserList(QMap &userList, QString &userName); private slots: void openLink(const QUrl &link); public: