Merge branch 'master' of https://github.com/fourtf/chatterino2
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "twitchchannel.hpp"
|
||||
#include "debug/log.hpp"
|
||||
#include "messages/message.hpp"
|
||||
#include "singletons/channelmanager.hpp"
|
||||
#include "singletons/emotemanager.hpp"
|
||||
#include "singletons/ircmanager.hpp"
|
||||
#include "singletons/settingsmanager.hpp"
|
||||
@@ -156,8 +158,8 @@ void TwitchChannel::refreshLiveStatus()
|
||||
|
||||
std::weak_ptr<Channel> weak = this->shared_from_this();
|
||||
|
||||
util::twitch::get2(url, QThread::currentThread(), [weak](const rapidjson::Document &d) {
|
||||
SharedChannel shared = weak.lock();
|
||||
util::twitch::get2(url, QThread::currentThread(), false, [weak](const rapidjson::Document &d) {
|
||||
ChannelPtr shared = weak.lock();
|
||||
|
||||
if (!shared) {
|
||||
return;
|
||||
@@ -218,7 +220,7 @@ void TwitchChannel::fetchRecentMessages()
|
||||
std::weak_ptr<Channel> weak = this->shared_from_this();
|
||||
|
||||
util::twitch::get(genericURL.arg(roomID), QThread::currentThread(), [weak](QJsonObject obj) {
|
||||
SharedChannel shared = weak.lock();
|
||||
ChannelPtr shared = weak.lock();
|
||||
|
||||
if (!shared) {
|
||||
return;
|
||||
@@ -230,7 +232,6 @@ void TwitchChannel::fetchRecentMessages()
|
||||
auto msgArray = obj.value("messages").toArray();
|
||||
if (msgArray.size() > 0) {
|
||||
std::vector<messages::MessagePtr> messages;
|
||||
messages.resize(msgArray.size());
|
||||
|
||||
for (int i = 0; i < msgArray.size(); i++) {
|
||||
QByteArray content = msgArray[i].toString().toUtf8();
|
||||
@@ -239,7 +240,9 @@ void TwitchChannel::fetchRecentMessages()
|
||||
|
||||
messages::MessageParseArgs args;
|
||||
twitch::TwitchMessageBuilder builder(channel, privMsg, args);
|
||||
messages.at(i) = builder.parse();
|
||||
if (!builder.isIgnored()) {
|
||||
messages.push_back(builder.build());
|
||||
}
|
||||
}
|
||||
channel->addMessagesAtStart(messages);
|
||||
}
|
||||
|
||||
@@ -27,15 +27,28 @@ TwitchMessageBuilder::TwitchMessageBuilder(Channel *_channel,
|
||||
, tags(this->ircMessage->tags())
|
||||
, usernameColor(singletons::ThemeManager::getInstance().messages.textColors.system)
|
||||
{
|
||||
this->originalMessage = this->ircMessage->content();
|
||||
}
|
||||
|
||||
MessagePtr TwitchMessageBuilder::parse()
|
||||
bool TwitchMessageBuilder::isIgnored() const
|
||||
{
|
||||
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
|
||||
std::shared_ptr<std::vector<QString>> ignoredKeywords = settings.getIgnoredKeywords();
|
||||
|
||||
for (const QString &keyword : *ignoredKeywords) {
|
||||
if (this->originalMessage.contains(keyword, Qt::CaseInsensitive)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
MessagePtr TwitchMessageBuilder::build()
|
||||
{
|
||||
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
|
||||
singletons::EmoteManager &emoteManager = singletons::EmoteManager::getInstance();
|
||||
|
||||
this->originalMessage = this->ircMessage->content();
|
||||
|
||||
// PARSING
|
||||
this->parseUsername();
|
||||
|
||||
@@ -43,11 +56,14 @@ MessagePtr TwitchMessageBuilder::parse()
|
||||
// this->appendWord(Word(Resources::getInstance().badgeCollapsed, Word::Collapsed, QString(),
|
||||
// QString()));
|
||||
|
||||
// The timestamp is always appended to the builder
|
||||
// Whether or not will be rendered is decided/checked later
|
||||
// PARSING
|
||||
this->parseMessageID();
|
||||
|
||||
// Appends the correct timestamp if the message is a past message
|
||||
this->parseRoomID();
|
||||
|
||||
this->appendChannelName();
|
||||
|
||||
// timestamp
|
||||
bool isPastMsg = this->tags.contains("historical");
|
||||
if (isPastMsg) {
|
||||
// This may be architecture dependent(datatype)
|
||||
@@ -58,20 +74,11 @@ MessagePtr TwitchMessageBuilder::parse()
|
||||
this->emplace<TimestampElement>();
|
||||
}
|
||||
|
||||
this->parseMessageID();
|
||||
|
||||
this->parseRoomID();
|
||||
|
||||
// TIMESTAMP
|
||||
this->emplace<TwitchModerationElement>();
|
||||
|
||||
this->parseTwitchBadges();
|
||||
this->appendTwitchBadges();
|
||||
|
||||
this->addChatterinoBadges();
|
||||
|
||||
if (this->args.includeChannelName) {
|
||||
this->parseChannelName();
|
||||
}
|
||||
this->appendChatterinoBadges();
|
||||
|
||||
this->appendUsername();
|
||||
|
||||
@@ -219,7 +226,7 @@ void TwitchMessageBuilder::parseRoomID()
|
||||
}
|
||||
}
|
||||
|
||||
void TwitchMessageBuilder::parseChannelName()
|
||||
void TwitchMessageBuilder::appendChannelName()
|
||||
{
|
||||
QString channelName("#" + this->channel->name);
|
||||
Link link(Link::Url, this->channel->name + "\n" + this->messageID);
|
||||
@@ -450,39 +457,36 @@ bool TwitchMessageBuilder::tryAppendEmote(QString &emoteString)
|
||||
singletons::EmoteManager &emoteManager = singletons::EmoteManager::getInstance();
|
||||
util::EmoteData emoteData;
|
||||
|
||||
auto appendEmote = [&](MessageElement::Flags flags) {
|
||||
this->emplace<EmoteElement>(emoteData, flags);
|
||||
return true;
|
||||
};
|
||||
|
||||
if (emoteManager.bttvGlobalEmotes.tryGet(emoteString, emoteData)) {
|
||||
// BTTV Global Emote
|
||||
return this->appendEmote(emoteData);
|
||||
return appendEmote(MessageElement::BttvEmote);
|
||||
} else if (this->twitchChannel != nullptr &&
|
||||
this->twitchChannel->bttvChannelEmotes->tryGet(emoteString, emoteData)) {
|
||||
// BTTV Channel Emote
|
||||
return this->appendEmote(emoteData);
|
||||
return appendEmote(MessageElement::BttvEmote);
|
||||
} else if (emoteManager.ffzGlobalEmotes.tryGet(emoteString, emoteData)) {
|
||||
// FFZ Global Emote
|
||||
return this->appendEmote(emoteData);
|
||||
return appendEmote(MessageElement::FfzEmote);
|
||||
} else if (this->twitchChannel != nullptr &&
|
||||
this->twitchChannel->ffzChannelEmotes->tryGet(emoteString, emoteData)) {
|
||||
// FFZ Channel Emote
|
||||
return this->appendEmote(emoteData);
|
||||
return appendEmote(MessageElement::FfzEmote);
|
||||
} else if (emoteManager.getChatterinoEmotes().tryGet(emoteString, emoteData)) {
|
||||
// Chatterino Emote
|
||||
return this->appendEmote(emoteData);
|
||||
return appendEmote(MessageElement::Misc);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TwitchMessageBuilder::appendEmote(const util::EmoteData &emoteData)
|
||||
{
|
||||
this->emplace<EmoteElement>(emoteData, MessageElement::BttvEmote);
|
||||
|
||||
// Perhaps check for ignored emotes here?
|
||||
return true;
|
||||
}
|
||||
|
||||
// fourtf: this is ugly
|
||||
// maybe put the individual badges into a map instead of this mess
|
||||
void TwitchMessageBuilder::parseTwitchBadges()
|
||||
void TwitchMessageBuilder::appendTwitchBadges()
|
||||
{
|
||||
singletons::ResourceManager &resourceManager = singletons::ResourceManager::getInstance();
|
||||
const auto &channelResources = resourceManager.channels[this->roomID];
|
||||
@@ -639,7 +643,7 @@ void TwitchMessageBuilder::parseTwitchBadges()
|
||||
}
|
||||
}
|
||||
|
||||
void TwitchMessageBuilder::addChatterinoBadges()
|
||||
void TwitchMessageBuilder::appendChatterinoBadges()
|
||||
{
|
||||
auto &badges = singletons::ResourceManager::getInstance().chatterinoBadges;
|
||||
auto it = badges.find(this->userName.toStdString());
|
||||
|
||||
@@ -38,7 +38,8 @@ public:
|
||||
QString messageID;
|
||||
QString userName;
|
||||
|
||||
messages::MessagePtr parse();
|
||||
bool isIgnored() const;
|
||||
messages::MessagePtr build();
|
||||
|
||||
private:
|
||||
QString roomID;
|
||||
@@ -47,7 +48,7 @@ private:
|
||||
|
||||
void parseMessageID();
|
||||
void parseRoomID();
|
||||
void parseChannelName();
|
||||
void appendChannelName();
|
||||
void parseUsername();
|
||||
void appendUsername();
|
||||
void parseHighlights();
|
||||
@@ -55,10 +56,9 @@ private:
|
||||
void appendTwitchEmote(const Communi::IrcPrivateMessage *ircMessage, const QString &emote,
|
||||
std::vector<std::pair<long, util::EmoteData>> &vec);
|
||||
bool tryAppendEmote(QString &emoteString);
|
||||
bool appendEmote(const util::EmoteData &emoteData);
|
||||
|
||||
void parseTwitchBadges();
|
||||
void addChatterinoBadges();
|
||||
void appendTwitchBadges();
|
||||
void appendChatterinoBadges();
|
||||
bool tryParseCheermote(const QString &string);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user