Merge pull request #770 from Cockatrice/fix-632
Fix #632. Url and mentions work together
This commit is contained in:
commit
342dfe7edb
1 changed files with 26 additions and 21 deletions
|
@ -148,9 +148,25 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
|
||||||
messageFormat.setForeground(Qt::darkGreen);
|
messageFormat.setForeground(Qt::darkGreen);
|
||||||
cursor.setCharFormat(messageFormat);
|
cursor.setCharFormat(messageFormat);
|
||||||
|
|
||||||
int from = 0, index = 0;
|
int from = 0, index = 0, bracket = 0, at = 0;
|
||||||
while ((index = message.indexOf('[', from)) != -1) {
|
bool mentionEnabled = settingsCache->getChatMention();
|
||||||
cursor.insertText(message.left(index));
|
while (((message.indexOf('[', from)) != -1) || (mentionEnabled && (message.indexOf('@', from)) != -1)) {
|
||||||
|
bracket = message.indexOf('[', from);
|
||||||
|
if (!mentionEnabled) {
|
||||||
|
index = bracket;
|
||||||
|
} else {
|
||||||
|
at = message.indexOf('@', from);
|
||||||
|
if (bracket == -1)
|
||||||
|
index = at;
|
||||||
|
else if (at == -1)
|
||||||
|
index = bracket;
|
||||||
|
else
|
||||||
|
index = std::min(bracket, at);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
cursor.insertText(message.left(index), defaultFormat);
|
||||||
message = message.mid(index);
|
message = message.mid(index);
|
||||||
if (message.isEmpty())
|
if (message.isEmpty())
|
||||||
break;
|
break;
|
||||||
|
@ -185,27 +201,15 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
|
||||||
message = message.mid(closeTagIndex + 6);
|
message = message.mid(closeTagIndex + 6);
|
||||||
|
|
||||||
appendUrlTag(cursor, url);
|
appendUrlTag(cursor, url);
|
||||||
} else
|
} else if (mentionEnabled) {
|
||||||
from = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settingsCache->getChatMention()) {
|
|
||||||
index = 0;
|
|
||||||
while((index = message.indexOf('@')) != -1) {
|
|
||||||
cursor.insertText(message.left(index), defaultFormat);
|
|
||||||
message = message.mid(index);
|
|
||||||
if (message.isEmpty())
|
|
||||||
break;
|
|
||||||
// you have been mentioned
|
|
||||||
if (message.toLower().startsWith(mention)) {
|
if (message.toLower().startsWith(mention)) {
|
||||||
|
// you have been mentioned
|
||||||
mentionFormat.setBackground(QBrush(getCustomMentionColor()));
|
mentionFormat.setBackground(QBrush(getCustomMentionColor()));
|
||||||
mentionFormat.setForeground(settingsCache->getChatMentionForeground() ? QBrush(Qt::white):QBrush(Qt::black));
|
mentionFormat.setForeground(settingsCache->getChatMentionForeground() ? QBrush(Qt::white):QBrush(Qt::black));
|
||||||
cursor.insertText("@" + userName, mentionFormat);
|
cursor.insertText("@" + userName, mentionFormat);
|
||||||
message = message.mid(mention.size());
|
message = message.mid(mention.size());
|
||||||
QApplication::alert(this);
|
QApplication::alert(this);
|
||||||
}
|
} else {
|
||||||
// another user has been mentioned
|
|
||||||
else {
|
|
||||||
int mentionEndIndex = message.indexOf(QRegExp("\\W"), 1);// from 1 as @ is non-char
|
int mentionEndIndex = message.indexOf(QRegExp("\\W"), 1);// from 1 as @ is non-char
|
||||||
if (mentionEndIndex == -1)
|
if (mentionEndIndex == -1)
|
||||||
mentionEndIndex = message.size(); // there is no text after the mention
|
mentionEndIndex = message.size(); // there is no text after the mention
|
||||||
|
@ -217,12 +221,13 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
|
||||||
UserListTWI *vlu = userList.value(correctUserName);
|
UserListTWI *vlu = userList.value(correctUserName);
|
||||||
mentionFormatOtherUser.setAnchorHref("user://" + QString::number(vlu->getUserInfo().user_level()) + "_" + correctUserName);
|
mentionFormatOtherUser.setAnchorHref("user://" + QString::number(vlu->getUserInfo().user_level()) + "_" + correctUserName);
|
||||||
cursor.insertText("@" + correctUserName, mentionFormatOtherUser);
|
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
|
cursor.setCharFormat(defaultFormat); // reset format after each iteration
|
||||||
}
|
} else
|
||||||
|
from = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!message.isEmpty())
|
if (!message.isEmpty())
|
||||||
|
|
Loading…
Reference in a new issue