commit
5a516de26a
1 changed files with 42 additions and 18 deletions
|
@ -161,43 +161,53 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
|
||||||
}
|
}
|
||||||
cursor.setCharFormat(messageFormat);
|
cursor.setCharFormat(messageFormat);
|
||||||
|
|
||||||
int index = -1, bracket = -1, at = -1;
|
int index = -1, bracketFirstIndex = -1, mentionFirstIndex = -1, urlFirstIndex = -1;
|
||||||
bool mentionEnabled = settingsCache->getChatMention();
|
bool mentionEnabled = settingsCache->getChatMention();
|
||||||
while (message.size())
|
while (message.size())
|
||||||
{
|
{
|
||||||
// search for the first [ or @
|
// search for the first [ or @
|
||||||
bracket = message.indexOf('[');
|
bracketFirstIndex = message.indexOf('[');
|
||||||
at = mentionEnabled ? message.indexOf('@') : -1;
|
mentionFirstIndex = mentionEnabled ? message.indexOf('@') : -1;
|
||||||
if(bracket == -1)
|
urlFirstIndex = message.indexOf(QRegExp("https?://|www."));
|
||||||
{
|
if(bracketFirstIndex == -1) {
|
||||||
if(at == -1)
|
if(mentionFirstIndex == -1) {
|
||||||
{
|
if (urlFirstIndex == -1) {
|
||||||
// quick way out
|
// quick way out
|
||||||
cursor.insertText(message);
|
cursor.insertText(message);
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
// url
|
||||||
|
index = urlFirstIndex;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// mention
|
if (urlFirstIndex == -1) {
|
||||||
index = at;
|
// mention
|
||||||
|
index = mentionFirstIndex;
|
||||||
|
} else {
|
||||||
|
index = std::min(urlFirstIndex, mentionFirstIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(at == -1)
|
if(mentionFirstIndex == -1) {
|
||||||
{
|
|
||||||
// bracket
|
// bracket
|
||||||
index = bracket;
|
index = bracketFirstIndex;
|
||||||
} else {
|
} else {
|
||||||
// both, pick up the first one
|
// both, pick up the first one
|
||||||
index = std::min(bracket, at);
|
index = std::min(bracketFirstIndex, mentionFirstIndex);
|
||||||
|
}
|
||||||
|
if(urlFirstIndex != -1) {
|
||||||
|
index = std::min(index, urlFirstIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert the message text up to the [ / @
|
// insert the message text up to the [ / @ / https://
|
||||||
if(index > 0)
|
if(index > 0)
|
||||||
{
|
{
|
||||||
cursor.insertText(message.left(index), defaultFormat);
|
cursor.insertText(message.left(index), defaultFormat);
|
||||||
message = message.mid(index);
|
message = message.mid(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(index == bracket)
|
if(index == bracketFirstIndex)
|
||||||
{
|
{
|
||||||
if (message.startsWith("[card]")) {
|
if (message.startsWith("[card]")) {
|
||||||
message = message.mid(6);
|
message = message.mid(6);
|
||||||
|
@ -234,6 +244,20 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
|
||||||
cursor.insertText("[", defaultFormat);
|
cursor.insertText("[", defaultFormat);
|
||||||
message = message.mid(1);
|
message = message.mid(1);
|
||||||
}
|
}
|
||||||
|
} else if (index == urlFirstIndex) {
|
||||||
|
int urlEndIndex = message.indexOf(QRegExp("\\s"), 0);
|
||||||
|
if (urlEndIndex == -1)
|
||||||
|
urlEndIndex = message.size();
|
||||||
|
QString urlText = message.left(urlEndIndex);
|
||||||
|
QUrl qUrl(urlText);
|
||||||
|
if (qUrl.isValid())
|
||||||
|
appendUrlTag(cursor, urlText);
|
||||||
|
else
|
||||||
|
cursor.insertText(urlText);
|
||||||
|
if (urlEndIndex == -1)
|
||||||
|
message.clear();
|
||||||
|
else
|
||||||
|
message = message.mid(urlEndIndex);
|
||||||
} else {
|
} else {
|
||||||
if (message.startsWith(mention, Qt::CaseInsensitive)) {
|
if (message.startsWith(mention, Qt::CaseInsensitive)) {
|
||||||
// you have been mentioned
|
// you have been mentioned
|
||||||
|
|
Loading…
Reference in a new issue