2017-01-18 21:30:23 +01:00
|
|
|
#include "messages/message.h"
|
2017-01-05 16:07:20 +01:00
|
|
|
#include "colorscheme.h"
|
2017-01-07 20:43:55 +01:00
|
|
|
#include "emojis.h"
|
2017-01-11 18:52:09 +01:00
|
|
|
#include "emotes.h"
|
2017-01-11 01:08:20 +01:00
|
|
|
#include "fonts.h"
|
2017-01-11 18:52:09 +01:00
|
|
|
#include "ircmanager.h"
|
2017-01-18 21:30:23 +01:00
|
|
|
#include "messages/link.h"
|
2017-01-11 18:52:09 +01:00
|
|
|
#include "qcolor.h"
|
2017-01-13 18:59:11 +01:00
|
|
|
#include "resources.h"
|
2017-01-23 16:38:06 +01:00
|
|
|
#include "settings.h"
|
2017-01-05 16:07:20 +01:00
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
#include <QStringList>
|
2017-01-05 16:43:01 +01:00
|
|
|
#include <ctime>
|
2017-01-11 01:08:20 +01:00
|
|
|
#include <list>
|
2017-01-11 18:52:09 +01:00
|
|
|
#include <tuple>
|
2017-01-05 16:43:01 +01:00
|
|
|
|
2017-01-11 01:08:20 +01:00
|
|
|
#define MARGIN_LEFT 8
|
|
|
|
#define MARGIN_RIGHT 8
|
|
|
|
#define MARGIN_TOP 8
|
|
|
|
#define MARGIN_BOTTOM 8
|
|
|
|
|
2017-01-18 21:30:23 +01:00
|
|
|
namespace chatterino {
|
|
|
|
namespace messages {
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
QRegularExpression *Message::cheerRegex =
|
|
|
|
new QRegularExpression("cheer[1-9][0-9]*");
|
2017-01-07 20:43:55 +01:00
|
|
|
|
2017-01-05 16:07:20 +01:00
|
|
|
Message::Message(const QString &text)
|
2017-01-24 20:15:12 +01:00
|
|
|
: wordParts()
|
2017-01-05 16:07:20 +01:00
|
|
|
{
|
2017-01-24 20:15:12 +01:00
|
|
|
words.push_back(Word(text, Word::Text,
|
|
|
|
ColorScheme::getInstance().SystemMessageColor, text,
|
|
|
|
QString()));
|
2017-01-05 16:07:20 +01:00
|
|
|
}
|
|
|
|
|
2017-01-26 17:48:14 +01:00
|
|
|
Message::Message(const IrcPrivateMessage &ircMessage, Channel &channel,
|
2017-01-11 18:52:09 +01:00
|
|
|
bool enablePingSound, bool isReceivedWhisper,
|
|
|
|
bool isSentWhisper, bool includeChannel)
|
2017-01-24 20:15:12 +01:00
|
|
|
: wordParts()
|
2017-01-05 16:07:20 +01:00
|
|
|
{
|
2017-01-18 04:33:30 +01:00
|
|
|
this->parseTime = std::chrono::system_clock::now();
|
2017-01-05 16:07:20 +01:00
|
|
|
|
2017-01-11 01:08:20 +01:00
|
|
|
auto words = std::vector<Word>();
|
|
|
|
|
|
|
|
auto tags = ircMessage.tags();
|
2017-01-05 16:07:20 +01:00
|
|
|
|
2017-01-11 01:08:20 +01:00
|
|
|
auto iterator = tags.find("id");
|
2017-01-05 20:49:33 +01:00
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
if (iterator != tags.end()) {
|
2017-01-18 04:33:30 +01:00
|
|
|
this->id = iterator.value().toString();
|
2017-01-05 20:49:33 +01:00
|
|
|
}
|
|
|
|
|
2017-01-05 16:07:20 +01:00
|
|
|
// timestamps
|
2017-01-11 01:08:20 +01:00
|
|
|
iterator = tags.find("tmi-sent-ts");
|
2017-01-13 18:59:11 +01:00
|
|
|
|
2017-01-05 16:43:01 +01:00
|
|
|
std::time_t time = std::time(NULL);
|
2017-01-05 16:07:20 +01:00
|
|
|
|
2017-01-13 18:59:11 +01:00
|
|
|
// if (iterator != tags.end()) {
|
|
|
|
// time = strtoll(iterator.value().toString().toStdString().c_str(),
|
|
|
|
// NULL,
|
|
|
|
// 10);
|
|
|
|
// }
|
2017-01-05 16:07:20 +01:00
|
|
|
|
|
|
|
char timeStampBuffer[69];
|
|
|
|
|
|
|
|
strftime(timeStampBuffer, 69, "%H:%M", localtime(&time));
|
|
|
|
QString timestamp = QString(timeStampBuffer);
|
|
|
|
|
|
|
|
strftime(timeStampBuffer, 69, "%H:%M:%S", localtime(&time));
|
|
|
|
QString timestampWithSeconds = QString(timeStampBuffer);
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
words.push_back(Word(timestamp, Word::TimestampNoSeconds,
|
2017-01-24 20:15:12 +01:00
|
|
|
ColorScheme::getInstance().SystemMessageColor,
|
|
|
|
QString(), QString()));
|
2017-01-11 18:52:09 +01:00
|
|
|
words.push_back(Word(timestampWithSeconds, Word::TimestampWithSeconds,
|
2017-01-24 20:15:12 +01:00
|
|
|
ColorScheme::getInstance().SystemMessageColor,
|
|
|
|
QString(), QString()));
|
2017-01-06 23:28:48 +01:00
|
|
|
|
2017-01-15 16:38:30 +01:00
|
|
|
// mod buttons
|
|
|
|
static QString buttonBanTooltip("Ban user");
|
|
|
|
static QString buttonTimeoutTooltip("Timeout user");
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
words.push_back(Word(Resources::getButtonBan(), Word::ButtonBan, QString(),
|
2017-01-15 16:38:30 +01:00
|
|
|
buttonBanTooltip,
|
|
|
|
Link(Link::UserBan, ircMessage.account())));
|
2017-01-18 04:33:30 +01:00
|
|
|
words.push_back(Word(Resources::getButtonTimeout(), Word::ButtonTimeout,
|
2017-01-15 16:38:30 +01:00
|
|
|
QString(), buttonTimeoutTooltip,
|
|
|
|
Link(Link::UserTimeout, ircMessage.account())));
|
|
|
|
|
2017-01-06 23:28:48 +01:00
|
|
|
// badges
|
2017-01-11 01:08:20 +01:00
|
|
|
iterator = tags.find("badges");
|
2017-01-06 23:28:48 +01:00
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
if (iterator != tags.end()) {
|
2017-01-06 23:28:48 +01:00
|
|
|
auto badges = iterator.value().toString().split(',');
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
for (QString badge : badges) {
|
|
|
|
if (badge.startsWith("bits/")) {
|
|
|
|
long long int cheer =
|
|
|
|
strtoll(badge.mid(5).toStdString().c_str(), NULL, 10);
|
|
|
|
words.push_back(Word(
|
|
|
|
Emotes::getCheerBadge(cheer), Word::BadgeCheer, QString(),
|
|
|
|
QString("Twitch Cheer" + QString::number(cheer))));
|
|
|
|
} else if (badge == "staff/1") {
|
2017-01-18 04:33:30 +01:00
|
|
|
words.push_back(Word(Resources::getBadgeStaff(),
|
|
|
|
Word::BadgeStaff, QString(),
|
|
|
|
QString("Twitch Staff")));
|
2017-01-11 18:52:09 +01:00
|
|
|
} else if (badge == "admin/1") {
|
2017-01-18 04:33:30 +01:00
|
|
|
words.push_back(Word(Resources::getBadgeAdmin(),
|
|
|
|
Word::BadgeAdmin, QString(),
|
|
|
|
QString("Twitch Admin")));
|
2017-01-11 18:52:09 +01:00
|
|
|
} else if (badge == "global_mod/1") {
|
2017-01-18 04:33:30 +01:00
|
|
|
words.push_back(Word(Resources::getBadgeGlobalmod(),
|
2017-01-13 18:59:11 +01:00
|
|
|
Word::BadgeGlobalMod, QString(),
|
|
|
|
QString("Global Moderator")));
|
2017-01-11 18:52:09 +01:00
|
|
|
} else if (badge == "moderator/1") {
|
2017-01-15 17:21:28 +01:00
|
|
|
// TODO: implement this xD
|
2017-01-13 18:59:11 +01:00
|
|
|
words.push_back(Word(
|
2017-01-18 04:33:30 +01:00
|
|
|
Resources::getBadgeTurbo(), Word::BadgeModerator, QString(),
|
2017-01-13 18:59:11 +01:00
|
|
|
QString("Channel Moderator"))); // custom badge
|
2017-01-11 18:52:09 +01:00
|
|
|
} else if (badge == "turbo/1") {
|
2017-01-18 04:33:30 +01:00
|
|
|
words.push_back(Word(Resources::getBadgeStaff(),
|
|
|
|
Word::BadgeTurbo, QString(),
|
|
|
|
QString("Turbo Subscriber")));
|
2017-01-11 18:52:09 +01:00
|
|
|
} else if (badge == "broadcaster/1") {
|
2017-01-18 04:33:30 +01:00
|
|
|
words.push_back(Word(Resources::getBadgeBroadcaster(),
|
2017-01-13 18:59:11 +01:00
|
|
|
Word::BadgeBroadcaster, QString(),
|
2017-01-11 18:52:09 +01:00
|
|
|
QString("Channel Broadcaster")));
|
|
|
|
} else if (badge == "premium/1") {
|
2017-01-18 04:33:30 +01:00
|
|
|
words.push_back(Word(Resources::getBadgePremium(),
|
2017-01-13 18:59:11 +01:00
|
|
|
Word::BadgePremium, QString(),
|
|
|
|
QString("Twitch Prime")));
|
2017-01-06 23:28:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-05 20:49:33 +01:00
|
|
|
|
|
|
|
// color
|
2017-01-24 20:15:12 +01:00
|
|
|
QColor usernameColor = ColorScheme::getInstance().SystemMessageColor;
|
2017-01-05 20:49:33 +01:00
|
|
|
|
2017-01-11 01:08:20 +01:00
|
|
|
iterator = tags.find("color");
|
2017-01-11 18:52:09 +01:00
|
|
|
if (iterator != tags.end()) {
|
|
|
|
usernameColor = QColor(iterator.value().toString());
|
2017-01-05 20:49:33 +01:00
|
|
|
}
|
2017-01-05 16:22:55 +01:00
|
|
|
|
2017-01-05 20:49:33 +01:00
|
|
|
// channel name
|
2017-01-11 18:52:09 +01:00
|
|
|
if (includeChannel) {
|
2017-01-18 04:33:30 +01:00
|
|
|
QString channelName("#" + channel.getName());
|
|
|
|
words.push_back(Word(
|
2017-01-24 20:15:12 +01:00
|
|
|
channelName, Word::Misc,
|
|
|
|
ColorScheme::getInstance().SystemMessageColor, QString(channelName),
|
|
|
|
QString(), Link(Link::Url, channel.getName() + "\n" + this->id)));
|
2017-01-05 20:49:33 +01:00
|
|
|
}
|
2017-01-05 16:07:20 +01:00
|
|
|
|
|
|
|
// username
|
2017-01-18 04:33:30 +01:00
|
|
|
this->userName = ircMessage.account();
|
2017-01-05 16:07:20 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
if (this->userName.isEmpty()) {
|
2017-01-11 01:08:20 +01:00
|
|
|
auto iterator = tags.find("login");
|
2017-01-05 16:07:20 +01:00
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
if (iterator != tags.end()) {
|
2017-01-18 04:33:30 +01:00
|
|
|
this->userName = iterator.value().toString();
|
2017-01-05 16:07:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString displayName;
|
|
|
|
|
2017-01-11 01:08:20 +01:00
|
|
|
iterator = tags.find("display-name");
|
|
|
|
if (iterator == tags.end()) {
|
2017-01-05 20:49:33 +01:00
|
|
|
displayName = ircMessage.account();
|
2017-01-11 18:52:09 +01:00
|
|
|
} else {
|
2017-01-05 16:07:20 +01:00
|
|
|
displayName = iterator.value().toString();
|
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
bool hasLocalizedName =
|
|
|
|
QString::compare(displayName, ircMessage.account()) == 0;
|
|
|
|
QString userDisplayString =
|
|
|
|
displayName +
|
|
|
|
(hasLocalizedName ? (" (" + ircMessage.account() + ")") : QString());
|
2017-01-05 16:07:20 +01:00
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
if (isSentWhisper) {
|
2017-01-18 04:33:30 +01:00
|
|
|
userDisplayString = IrcManager::account->getUsername() + " -> ";
|
2017-01-07 20:43:55 +01:00
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
if (isReceivedWhisper) {
|
2017-01-18 04:33:30 +01:00
|
|
|
userDisplayString += " -> " + IrcManager::account->getUsername();
|
2017-01-07 20:43:55 +01:00
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
if (!ircMessage.isAction()) {
|
2017-01-07 20:43:55 +01:00
|
|
|
userDisplayString += ": ";
|
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
words.push_back(Word(userDisplayString, Word::Username, usernameColor,
|
|
|
|
userDisplayString, QString()));
|
2017-01-05 16:07:20 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
// highlights
|
|
|
|
// TODO: implement this xD
|
2017-01-05 16:07:20 +01:00
|
|
|
|
|
|
|
// bits
|
|
|
|
QString bits = "";
|
|
|
|
|
2017-01-11 01:08:20 +01:00
|
|
|
iterator = tags.find("bits");
|
2017-01-11 18:52:09 +01:00
|
|
|
if (iterator != tags.end()) {
|
|
|
|
bits = iterator.value().toString();
|
2017-01-05 16:07:20 +01:00
|
|
|
}
|
|
|
|
|
2017-01-06 23:28:48 +01:00
|
|
|
// twitch emotes
|
2017-01-11 18:52:09 +01:00
|
|
|
std::vector<std::pair<long int, LazyLoadedImage *>> twitchEmotes;
|
2017-01-06 23:28:48 +01:00
|
|
|
|
2017-01-11 01:08:20 +01:00
|
|
|
iterator = tags.find("emotes");
|
2017-01-05 16:07:20 +01:00
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
if (iterator != tags.end()) {
|
2017-01-06 23:28:48 +01:00
|
|
|
auto emotes = iterator.value().toString().split('/');
|
2017-01-05 16:07:20 +01:00
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
for (QString emote : emotes) {
|
|
|
|
if (!emote.contains(':'))
|
|
|
|
continue;
|
2017-01-06 23:28:48 +01:00
|
|
|
|
|
|
|
QStringList parameters = emote.split(':');
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
if (parameters.length() < 2)
|
|
|
|
continue;
|
2017-01-06 23:28:48 +01:00
|
|
|
|
|
|
|
long int id = std::stol(parameters.at(0).toStdString(), NULL, 10);
|
|
|
|
|
|
|
|
QStringList occurences = parameters.at(1).split(',');
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
for (QString occurence : occurences) {
|
2017-01-06 23:28:48 +01:00
|
|
|
QStringList coords = occurence.split('-');
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
if (coords.length() < 2)
|
|
|
|
continue;
|
2017-01-06 23:28:48 +01:00
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
long int start =
|
|
|
|
std::stol(coords.at(0).toStdString(), NULL, 10);
|
2017-01-06 23:28:48 +01:00
|
|
|
long int end = std::stol(coords.at(1).toStdString(), NULL, 10);
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
if (start >= end || start < 0 ||
|
|
|
|
end > ircMessage.content().length())
|
|
|
|
continue;
|
2017-01-06 23:28:48 +01:00
|
|
|
|
|
|
|
QString name = ircMessage.content().mid(start, end - start);
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
twitchEmotes.push_back(std::pair<long int, LazyLoadedImage *>(
|
|
|
|
start, Emotes::getTwitchEmoteById(name, id)));
|
2017-01-05 16:07:20 +01:00
|
|
|
}
|
|
|
|
}
|
2017-01-06 23:28:48 +01:00
|
|
|
|
|
|
|
std::sort(twitchEmotes.begin(), twitchEmotes.end(), sortTwitchEmotes);
|
2017-01-05 16:07:20 +01:00
|
|
|
}
|
2017-01-05 20:49:33 +01:00
|
|
|
|
2017-01-06 23:28:48 +01:00
|
|
|
auto currentTwitchEmote = twitchEmotes.begin();
|
|
|
|
|
|
|
|
// words
|
2017-01-11 18:52:09 +01:00
|
|
|
QColor textColor =
|
2017-01-24 20:15:12 +01:00
|
|
|
ircMessage.isAction() ? usernameColor : ColorScheme::getInstance().Text;
|
2017-01-05 20:49:33 +01:00
|
|
|
|
2017-01-06 23:28:48 +01:00
|
|
|
QStringList splits = ircMessage.content().split(' ');
|
|
|
|
|
|
|
|
long int i = 0;
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
for (QString split : splits) {
|
2017-01-06 23:28:48 +01:00
|
|
|
// twitch emote
|
2017-01-15 16:38:30 +01:00
|
|
|
if (currentTwitchEmote != twitchEmotes.end() &&
|
|
|
|
currentTwitchEmote->first == i) {
|
2017-01-11 18:52:09 +01:00
|
|
|
words.push_back(Word(currentTwitchEmote->second,
|
|
|
|
Word::TwitchEmoteImage,
|
2017-01-18 04:33:30 +01:00
|
|
|
currentTwitchEmote->second->getName(),
|
|
|
|
currentTwitchEmote->second->getName() +
|
2017-01-11 18:52:09 +01:00
|
|
|
QString("\nTwitch Emote")));
|
2017-01-18 04:33:30 +01:00
|
|
|
words.push_back(Word(currentTwitchEmote->second->getName(),
|
2017-01-11 18:52:09 +01:00
|
|
|
Word::TwitchEmoteText, textColor,
|
2017-01-18 04:33:30 +01:00
|
|
|
currentTwitchEmote->second->getName(),
|
|
|
|
currentTwitchEmote->second->getName() +
|
2017-01-11 18:52:09 +01:00
|
|
|
QString("\nTwitch Emote")));
|
2017-01-06 23:28:48 +01:00
|
|
|
|
|
|
|
i += split.length() + 1;
|
|
|
|
currentTwitchEmote = std::next(currentTwitchEmote);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// split words
|
2017-01-11 18:52:09 +01:00
|
|
|
std::vector<std::tuple<LazyLoadedImage *, QString>> parsed;
|
2017-01-07 20:43:55 +01:00
|
|
|
|
|
|
|
Emojis::parseEmojis(parsed, split);
|
2017-01-11 18:52:09 +01:00
|
|
|
for (const std::tuple<LazyLoadedImage *, QString> &tuple : parsed) {
|
|
|
|
LazyLoadedImage *image = std::get<0>(tuple);
|
2017-01-15 16:38:30 +01:00
|
|
|
|
|
|
|
if (image == NULL) { // is text
|
2017-01-07 20:43:55 +01:00
|
|
|
QString string = std::get<1>(tuple);
|
|
|
|
|
|
|
|
// cheers
|
2017-01-11 18:52:09 +01:00
|
|
|
if (!bits.isEmpty() && string.length() >= 6 &&
|
|
|
|
cheerRegex->match(string).isValid()) {
|
2017-01-07 20:43:55 +01:00
|
|
|
auto cheer = string.mid(5).toInt();
|
|
|
|
|
|
|
|
QString color;
|
|
|
|
|
|
|
|
QColor bitsColor;
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
if (cheer >= 10000) {
|
2017-01-07 20:43:55 +01:00
|
|
|
color = "red";
|
|
|
|
bitsColor = QColor::fromHslF(0, 1, 0.5);
|
2017-01-11 18:52:09 +01:00
|
|
|
} else if (cheer >= 5000) {
|
2017-01-07 20:43:55 +01:00
|
|
|
color = "blue";
|
|
|
|
bitsColor = QColor::fromHslF(0.61, 1, 0.4);
|
2017-01-11 18:52:09 +01:00
|
|
|
} else if (cheer >= 1000) {
|
2017-01-07 20:43:55 +01:00
|
|
|
color = "green";
|
|
|
|
bitsColor = QColor::fromHslF(0.5, 1, 0.5);
|
2017-01-11 18:52:09 +01:00
|
|
|
} else if (cheer >= 100) {
|
2017-01-07 20:43:55 +01:00
|
|
|
color = "purple";
|
|
|
|
bitsColor = QColor::fromHslF(0.8, 1, 0.5);
|
2017-01-11 18:52:09 +01:00
|
|
|
} else {
|
2017-01-07 20:43:55 +01:00
|
|
|
color = "gray";
|
|
|
|
bitsColor = QColor::fromHslF(0.5f, 0.5f, 0.5f);
|
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
QString bitsLinkAnimated = QString(
|
|
|
|
"http://static-cdn.jtvnw.net/bits/dark/animated/" +
|
|
|
|
color + "/1");
|
|
|
|
QString bitsLink = QString(
|
|
|
|
"http://static-cdn.jtvnw.net/bits/dark/static/" +
|
|
|
|
color + "/1");
|
|
|
|
|
|
|
|
LazyLoadedImage *imageAnimated =
|
2017-01-18 04:33:30 +01:00
|
|
|
Emotes::getMiscImageFromCache().getOrAdd(
|
2017-01-11 18:52:09 +01:00
|
|
|
bitsLinkAnimated, [&bitsLinkAnimated] {
|
|
|
|
return new LazyLoadedImage(bitsLinkAnimated);
|
|
|
|
});
|
|
|
|
LazyLoadedImage *image =
|
2017-01-18 04:33:30 +01:00
|
|
|
Emotes::getMiscImageFromCache().getOrAdd(
|
2017-01-11 18:52:09 +01:00
|
|
|
bitsLink, [&bitsLink] {
|
|
|
|
return new LazyLoadedImage(bitsLink);
|
|
|
|
});
|
|
|
|
|
|
|
|
words.push_back(
|
|
|
|
Word(imageAnimated, Word::BitsAnimated,
|
|
|
|
QString("cheer"), QString("Twitch Cheer"),
|
|
|
|
Link(Link::Url,
|
|
|
|
QString("https://blog.twitch.tv/"
|
|
|
|
"introducing-cheering-celebrate-"
|
|
|
|
"together-da62af41fac6"))));
|
|
|
|
words.push_back(
|
2017-01-22 12:46:35 +01:00
|
|
|
Word(image, Word::BitsStatic, QString("cheer"),
|
2017-01-11 18:52:09 +01:00
|
|
|
QString("Twitch Cheer"),
|
|
|
|
Link(Link::Url,
|
|
|
|
QString("https://blog.twitch.tv/"
|
|
|
|
"introducing-cheering-celebrate-"
|
|
|
|
"together-da62af41fac6"))));
|
|
|
|
|
|
|
|
words.push_back(
|
|
|
|
Word(QString("x" + string.mid(5)), Word::BitsAmount,
|
|
|
|
bitsColor, QString(string.mid(5)),
|
|
|
|
QString("Twitch Cheer"),
|
|
|
|
Link(Link::Url,
|
|
|
|
QString("https://blog.twitch.tv/"
|
|
|
|
"introducing-cheering-celebrate-"
|
|
|
|
"together-da62af41fac6"))));
|
2017-01-07 20:43:55 +01:00
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
continue;
|
2017-01-11 01:08:20 +01:00
|
|
|
}
|
2017-01-07 20:43:55 +01:00
|
|
|
|
|
|
|
// bttv / ffz emotes
|
2017-01-11 18:52:09 +01:00
|
|
|
LazyLoadedImage *bttvEmote;
|
|
|
|
|
2017-01-15 17:21:28 +01:00
|
|
|
// TODO: Implement this (ignored emotes)
|
2017-01-18 04:33:30 +01:00
|
|
|
if (Emotes::getBttvEmotes().tryGet(string, bttvEmote) ||
|
|
|
|
channel.getBttvChannelEmotes().tryGet(string, bttvEmote) ||
|
|
|
|
Emotes::getFfzEmotes().tryGet(string, bttvEmote) ||
|
|
|
|
channel.getFfzChannelEmotes().tryGet(string, bttvEmote) ||
|
|
|
|
Emotes::getChatterinoEmotes().tryGet(string, bttvEmote)) {
|
2017-01-11 18:52:09 +01:00
|
|
|
words.push_back(Word(bttvEmote, Word::BttvEmoteImage,
|
2017-01-18 04:33:30 +01:00
|
|
|
bttvEmote->getName(),
|
|
|
|
bttvEmote->getTooltip(),
|
|
|
|
Link(Link::Url, bttvEmote->getUrl())));
|
2017-01-07 20:43:55 +01:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// actually just a word
|
|
|
|
QString link = matchLink(string);
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
words.push_back(
|
|
|
|
Word(string, Word::Text, textColor, string, QString(),
|
|
|
|
link.isEmpty() ? Link() : Link(Link::Url, link)));
|
2017-01-15 16:38:30 +01:00
|
|
|
} else { // is emoji
|
|
|
|
static QString emojiTooltip("Emoji");
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
words.push_back(Word(image, Word::EmojiImage, image->getName(),
|
|
|
|
emojiTooltip));
|
|
|
|
Word(image->getName(), Word::EmojiText, textColor,
|
|
|
|
image->getName(), emojiTooltip);
|
2017-01-07 20:43:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i += split.length() + 1;
|
2017-01-06 23:28:48 +01:00
|
|
|
}
|
2017-01-07 20:43:55 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
this->words = words;
|
2017-01-07 20:43:55 +01:00
|
|
|
|
2017-01-15 17:21:28 +01:00
|
|
|
// TODO: Implement this xD
|
2017-01-11 18:52:09 +01:00
|
|
|
// if (!isReceivedWhisper &&
|
|
|
|
// AppSettings.HighlightIgnoredUsers.ContainsKey(Username))
|
|
|
|
// {
|
|
|
|
// HighlightTab = false;
|
|
|
|
// }
|
2017-01-06 23:28:48 +01:00
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
bool
|
|
|
|
Message::layout(int width, bool enableEmoteMargins)
|
2017-01-11 01:08:20 +01:00
|
|
|
{
|
2017-01-23 16:38:06 +01:00
|
|
|
auto &settings = Settings::getInstance();
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2017-01-11 01:08:20 +01:00
|
|
|
width = width - (width % 2);
|
|
|
|
|
|
|
|
int mediumTextLineHeight = Fonts::getFontMetrics(Fonts::Medium).height();
|
2017-01-13 18:59:11 +01:00
|
|
|
int spaceWidth = 4;
|
2017-01-11 01:08:20 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
bool redraw = width != this->currentLayoutWidth || this->relayoutRequested;
|
2017-01-11 01:08:20 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
bool recalculateImages = this->emoteGeneration != Emotes::getGeneration();
|
|
|
|
bool recalculateText = this->fontGeneration != Fonts::getGeneration();
|
2017-01-15 16:38:30 +01:00
|
|
|
|
2017-01-22 23:00:35 +01:00
|
|
|
qreal emoteScale = settings.emoteScale.get();
|
|
|
|
bool scaleEmotesByLineHeight = settings.scaleEmotesByLineHeight.get();
|
2017-01-20 06:10:28 +01:00
|
|
|
|
2017-01-15 16:38:30 +01:00
|
|
|
if (recalculateImages || recalculateText) {
|
2017-01-18 04:33:30 +01:00
|
|
|
this->emoteGeneration = Emotes::getGeneration();
|
|
|
|
this->fontGeneration = Fonts::getGeneration();
|
2017-01-15 16:38:30 +01:00
|
|
|
|
2017-01-11 01:08:20 +01:00
|
|
|
redraw = true;
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
for (auto &word : this->words) {
|
2017-01-11 18:52:09 +01:00
|
|
|
if (word.isImage()) {
|
2017-01-15 16:38:30 +01:00
|
|
|
if (recalculateImages) {
|
2017-01-11 18:52:09 +01:00
|
|
|
auto &image = word.getImage();
|
2017-01-11 01:08:20 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
qreal w = image.getWidth();
|
|
|
|
qreal h = image.getHeight();
|
2017-01-11 01:08:20 +01:00
|
|
|
|
2017-01-20 06:10:28 +01:00
|
|
|
if (scaleEmotesByLineHeight) {
|
|
|
|
word.setSize(w * mediumTextLineHeight / h * emoteScale,
|
|
|
|
mediumTextLineHeight * emoteScale);
|
2017-01-11 18:52:09 +01:00
|
|
|
} else {
|
2017-01-20 06:10:28 +01:00
|
|
|
word.setSize(w * image.getScale() * emoteScale,
|
|
|
|
h * image.getScale() * emoteScale);
|
2017-01-11 01:08:20 +01:00
|
|
|
}
|
|
|
|
}
|
2017-01-11 18:52:09 +01:00
|
|
|
} else {
|
2017-01-15 16:38:30 +01:00
|
|
|
if (recalculateText) {
|
2017-01-11 18:52:09 +01:00
|
|
|
QFontMetrics &metrics = word.getFontMetrics();
|
|
|
|
word.setSize(metrics.width(word.getText()),
|
|
|
|
metrics.height());
|
2017-01-11 01:08:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-13 18:59:11 +01:00
|
|
|
if (!redraw) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-01-11 01:08:20 +01:00
|
|
|
|
2017-01-13 18:59:11 +01:00
|
|
|
int x = MARGIN_LEFT;
|
|
|
|
int y = MARGIN_TOP;
|
2017-01-11 01:08:20 +01:00
|
|
|
|
2017-01-13 18:59:11 +01:00
|
|
|
int right = width - MARGIN_RIGHT - MARGIN_LEFT;
|
2017-01-11 01:08:20 +01:00
|
|
|
|
2017-01-15 16:38:30 +01:00
|
|
|
std::vector<WordPart> *parts = new std::vector<WordPart>();
|
2017-01-11 01:08:20 +01:00
|
|
|
|
2017-01-15 16:38:30 +01:00
|
|
|
int lineStart = 0;
|
2017-01-13 18:59:11 +01:00
|
|
|
int lineHeight = 0;
|
2017-01-15 16:38:30 +01:00
|
|
|
bool first = true;
|
2017-01-11 01:08:20 +01:00
|
|
|
|
2017-01-13 18:59:11 +01:00
|
|
|
auto alignParts = [&lineStart, &lineHeight, &parts, this] {
|
2017-01-18 14:48:42 +01:00
|
|
|
for (size_t i = lineStart; i < parts->size(); i++) {
|
2017-01-15 16:38:30 +01:00
|
|
|
WordPart &wordPart2 = parts->at(i);
|
2017-01-11 01:08:20 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
wordPart2.setY(wordPart2.getY() + lineHeight);
|
2017-01-13 18:59:11 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-01-23 16:38:06 +01:00
|
|
|
uint32_t flags = Settings::getInstance().getWordTypeMask();
|
2017-01-13 18:59:11 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
for (auto it = this->words.begin(); it != this->words.end(); ++it) {
|
2017-01-13 18:59:11 +01:00
|
|
|
Word &word = *it;
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
if ((word.getType() & flags) == Word::None) {
|
2017-01-13 18:59:11 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int xOffset = 0, yOffset = 0;
|
2017-01-11 01:08:20 +01:00
|
|
|
|
2017-01-13 18:59:11 +01:00
|
|
|
if (enableEmoteMargins) {
|
2017-01-18 04:33:30 +01:00
|
|
|
if (word.isImage() && word.getImage().getIsHat()) {
|
|
|
|
xOffset = -word.getWidth() + 2;
|
2017-01-13 18:59:11 +01:00
|
|
|
} else {
|
2017-01-18 04:33:30 +01:00
|
|
|
xOffset = word.getXOffset();
|
|
|
|
yOffset = word.getYOffset();
|
2017-01-11 01:08:20 +01:00
|
|
|
}
|
2017-01-13 18:59:11 +01:00
|
|
|
}
|
2017-01-11 01:08:20 +01:00
|
|
|
|
2017-01-15 16:38:30 +01:00
|
|
|
// word wrapping
|
2017-01-18 04:33:30 +01:00
|
|
|
if (word.isText() && word.getWidth() + MARGIN_LEFT > right) {
|
2017-01-15 16:38:30 +01:00
|
|
|
alignParts();
|
|
|
|
|
|
|
|
y += lineHeight;
|
|
|
|
|
|
|
|
const QString &text = word.getText();
|
|
|
|
|
|
|
|
int start = 0;
|
|
|
|
QFontMetrics &metrics = word.getFontMetrics();
|
|
|
|
|
|
|
|
int width = 0;
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
std::vector<short> &charWidths = word.getCharacterWidthCache();
|
2017-01-15 16:38:30 +01:00
|
|
|
|
|
|
|
if (charWidths.size() == 0) {
|
|
|
|
charWidths.reserve(text.length());
|
|
|
|
|
|
|
|
for (int i = 0; i < text.length(); i++) {
|
2017-01-18 14:48:42 +01:00
|
|
|
charWidths.push_back(metrics.width(text, i));
|
2017-01-15 16:38:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 2; i <= text.length(); i++) {
|
|
|
|
if ((width = width + charWidths[i - 1]) + MARGIN_LEFT > right) {
|
|
|
|
QString mid = text.mid(start, i - start - 1);
|
|
|
|
|
|
|
|
parts->push_back(WordPart(word, MARGIN_LEFT, y, width,
|
2017-01-18 04:33:30 +01:00
|
|
|
word.getHeight(), mid, mid));
|
2017-01-15 16:38:30 +01:00
|
|
|
|
|
|
|
y += metrics.height();
|
|
|
|
|
|
|
|
start = i - 1;
|
|
|
|
|
|
|
|
width = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString mid(text.mid(start));
|
|
|
|
width = metrics.width(mid);
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
parts->push_back(WordPart(word, MARGIN_LEFT, y - word.getHeight(),
|
|
|
|
width, word.getHeight(), mid, mid));
|
2017-01-15 16:38:30 +01:00
|
|
|
x = width + MARGIN_LEFT + spaceWidth;
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
lineHeight = word.getHeight();
|
2017-01-15 16:38:30 +01:00
|
|
|
|
|
|
|
lineStart = parts->size() - 1;
|
|
|
|
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
|
2017-01-13 18:59:11 +01:00
|
|
|
// fits in the line
|
2017-01-18 04:33:30 +01:00
|
|
|
else if (first || x + word.getWidth() + xOffset <= right) {
|
2017-01-13 18:59:11 +01:00
|
|
|
parts->push_back(
|
2017-01-18 04:33:30 +01:00
|
|
|
WordPart(word, x, y - word.getHeight(), word.getCopyText()));
|
2017-01-11 01:08:20 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
x += word.getWidth() + xOffset;
|
2017-01-15 16:38:30 +01:00
|
|
|
x += spaceWidth;
|
2017-01-13 18:59:11 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
lineHeight = std::max(word.getHeight(), lineHeight);
|
2017-01-11 01:08:20 +01:00
|
|
|
|
2017-01-15 16:38:30 +01:00
|
|
|
first = false;
|
|
|
|
}
|
2017-01-13 18:59:11 +01:00
|
|
|
|
|
|
|
// doesn't fit in the line
|
|
|
|
else {
|
|
|
|
alignParts();
|
|
|
|
|
|
|
|
y += lineHeight;
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
parts->push_back(WordPart(word, MARGIN_LEFT, y - word.getHeight(),
|
|
|
|
word.getCopyText()));
|
2017-01-13 18:59:11 +01:00
|
|
|
|
2017-01-15 16:38:30 +01:00
|
|
|
lineStart = parts->size() - 1;
|
2017-01-11 01:08:20 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
lineHeight = word.getHeight();
|
2017-01-13 18:59:11 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
x = word.getWidth() + MARGIN_LEFT;
|
2017-01-15 16:38:30 +01:00
|
|
|
x += spaceWidth;
|
2017-01-13 18:59:11 +01:00
|
|
|
}
|
2017-01-11 01:08:20 +01:00
|
|
|
}
|
|
|
|
|
2017-01-13 18:59:11 +01:00
|
|
|
alignParts();
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
auto tmp = this->wordParts;
|
|
|
|
this->wordParts = parts;
|
2017-01-13 18:59:11 +01:00
|
|
|
delete tmp;
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
this->height = y + lineHeight;
|
2017-01-13 18:59:11 +01:00
|
|
|
|
|
|
|
return true;
|
2017-01-11 01:08:20 +01:00
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
bool
|
|
|
|
Message::sortTwitchEmotes(const std::pair<long int, LazyLoadedImage *> &a,
|
|
|
|
const std::pair<long int, LazyLoadedImage *> &b)
|
2017-01-06 23:28:48 +01:00
|
|
|
{
|
|
|
|
return a.first < b.first;
|
2017-01-05 16:07:20 +01:00
|
|
|
}
|
2017-01-07 20:43:55 +01:00
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
QString
|
|
|
|
Message::matchLink(const QString &string)
|
2017-01-07 20:43:55 +01:00
|
|
|
{
|
2017-01-15 17:21:28 +01:00
|
|
|
// TODO: Implement this xD
|
2017-01-07 20:43:55 +01:00
|
|
|
return QString();
|
|
|
|
}
|
2017-01-18 21:30:23 +01:00
|
|
|
}
|
|
|
|
}
|