Merge pull request #609 from poixen/chat_mention_fixes
Chat mention fixes
This commit is contained in:
commit
93cf7dbaaf
2 changed files with 22 additions and 5 deletions
|
@ -9,7 +9,6 @@
|
||||||
#include "pixmapgenerator.h"
|
#include "pixmapgenerator.h"
|
||||||
#include "settingscache.h"
|
#include "settingscache.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "userlist.h"
|
|
||||||
#include "tab_userlists.h"
|
#include "tab_userlists.h"
|
||||||
|
|
||||||
const QColor MENTION_COLOR = QColor(190, 25, 85); // maroon
|
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 userMention = message.left(mentionEndIndex);
|
||||||
QString userName = userMention.right(userMention.size()-1).normalized(QString::NormalizationForm_D);
|
QString userName = userMention.right(userMention.size()-1).normalized(QString::NormalizationForm_D);
|
||||||
QMap<QString, UserListTWI *> userList = tabSupervisor->getUserListsTab()->getAllUsersList()->getUsers();
|
QMap<QString, UserListTWI *> userList = tabSupervisor->getUserListsTab()->getAllUsersList()->getUsers();
|
||||||
if (userList.contains(userName)) {
|
QString correctUserName = getNameFromUserList(userList, userName);
|
||||||
UserListTWI *vlu = userList.value(userName);
|
if (!correctUserName.isEmpty()) {
|
||||||
mentionFormatOtherUser.setAnchorHref("user://" + QString::number(vlu->getUserInfo().user_level()) + "_" + userName);
|
UserListTWI *vlu = userList.value(correctUserName);
|
||||||
cursor.insertText("@" + userName, mentionFormatOtherUser);
|
mentionFormatOtherUser.setAnchorHref("user://" + QString::number(vlu->getUserInfo().user_level()) + "_" + correctUserName);
|
||||||
|
cursor.insertText("@" + correctUserName, mentionFormatOtherUser);
|
||||||
} else
|
} else
|
||||||
cursor.insertText("@" + userName, defaultFormat);
|
cursor.insertText("@" + userName, defaultFormat);
|
||||||
message = message.mid(userName.size() + 1);
|
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());
|
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<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() {
|
void ChatView::clearChat() {
|
||||||
document()->clear();
|
document()->clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <QTextFragment>
|
#include <QTextFragment>
|
||||||
#include <QTextCursor>
|
#include <QTextCursor>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
#include "userlist.h"
|
||||||
#include "user_level.h"
|
#include "user_level.h"
|
||||||
#include "tab_supervisor.h"
|
#include "tab_supervisor.h"
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ private:
|
||||||
QTextCursor prepareBlock(bool same = false);
|
QTextCursor prepareBlock(bool same = false);
|
||||||
void appendCardTag(QTextCursor &cursor, const QString &cardName);
|
void appendCardTag(QTextCursor &cursor, const QString &cardName);
|
||||||
void appendUrlTag(QTextCursor &cursor, QString url);
|
void appendUrlTag(QTextCursor &cursor, QString url);
|
||||||
|
QString getNameFromUserList(QMap<QString, UserListTWI *> &userList, QString &userName);
|
||||||
private slots:
|
private slots:
|
||||||
void openLink(const QUrl &link);
|
void openLink(const QUrl &link);
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue