Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
- Dev: Compile time definitions for `Windows.h` are now conditional based on `WIN32` instead of `MSVC`. (#6534)
- Dev: Refactored split container nodes to use shared pointers. (#6435)
- Dev: Mock headers are now added as a header set if supported by CMake. (#6561)
- Dev: Refactored emotes. (#6570)
- Dev: Set settings directory to temporary one used in tests. (#6584)
- Dev: Check Lua unwinding and version in tests. (#6586)
- Dev: Added method to get the last N messages of a channel. (#6602, #6604)
Expand Down
1 change: 1 addition & 0 deletions mocks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
include/mocks/ChatterinoBadges.hpp
include/mocks/DisabledStreamerMode.hpp
include/mocks/EmoteController.hpp
include/mocks/EmoteProvider.hpp
include/mocks/EmptyApplication.hpp
include/mocks/Helix.hpp
include/mocks/LinkResolver.hpp
Expand Down
6 changes: 6 additions & 0 deletions mocks/include/mocks/EmoteController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ class EmoteController : public chatterino::EmoteController
this->getEmojis()->load();
}

void addProvider(EmoteProviderPtr provider)
{
this->providers_.emplace_back(std::move(provider));
this->sort();
}

void initialize() override
{
}
Expand Down
85 changes: 85 additions & 0 deletions mocks/include/mocks/EmoteProvider.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#pragma once

#include "common/Channel.hpp"
#include "controllers/emotes/EmoteProvider.hpp"

#include <QStringBuilder>

namespace chatterino::mock {

class EmoteProvider : public chatterino::EmoteProvider
{
public:
EmoteProvider(QString name, QString id, uint32_t priority)
: chatterino::EmoteProvider(std::move(name), std::move(id), priority)
{
}

void setGlobalEmotes(std::shared_ptr<const EmoteMap> map)
{
this->globalEmotes_ = std::move(map);
}

void setChannel(const QString &name, std::shared_ptr<const EmoteMap> map)
{
this->channels[name] = std::move(map);
}

void setChannelFallback(std::shared_ptr<const EmoteMap> map)
{
this->channelFallback = std::move(map);
}

void initialize() override
{
}

void reloadGlobalEmotes(
std::function<void(ExpectedStr<void>)> onDone) override
{
onDone({});
}

void loadChannelEmotes(
const std::shared_ptr<Channel> &channel,
std::function<void(ExpectedStr<EmoteLoadResult>)> onDone,
LoadChannelArgs /* args */) override
{
auto it = channels.find(channel->getName());
if (it == this->channels.end())
{
if (this->channelFallback)
{
onDone(EmoteLoadResult{.emotes = this->channelFallback});
}
else
{
onDone(makeUnexpected("No emotes for this channel"));
}
}
else
{
onDone(EmoteLoadResult{.emotes = it->second});
}
}

bool supportsChannel(Channel * /*channel*/) override
{
return true;
}

bool hasChannelEmotes() const override
{
return true;
}

bool hasGlobalEmotes() const override
{
return true;
}

std::unordered_map<QString, std::shared_ptr<const EmoteMap>> channels;
std::shared_ptr<const EmoteMap> channelFallback;
};

} // namespace chatterino::mock
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ set(SOURCE_FILES

controllers/emotes/EmoteController.cpp
controllers/emotes/EmoteController.hpp
controllers/emotes/ChannelEmotes.cpp
controllers/emotes/ChannelEmotes.hpp
controllers/emotes/EmoteProvider.cpp
controllers/emotes/EmoteProvider.hpp

controllers/filters/FilterModel.cpp
controllers/filters/FilterModel.hpp
Expand Down
1 change: 1 addition & 0 deletions src/common/QLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Q_LOGGING_CATEGORY(chatterinoCompletion, "chatterino.completion", logThreshold);
Q_LOGGING_CATEGORY(chatterinoCrashhandler, "chatterino.crashhandler",
logThreshold);
Q_LOGGING_CATEGORY(chatterinoEmoji, "chatterino.emoji", logThreshold);
Q_LOGGING_CATEGORY(chatterinoEmotes, "chatterino.emotes", logThreshold);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random thought unrelated to your change here: It would be nice if emote providers would have their own logging category, and if that didn't require us to define something here

Q_LOGGING_CATEGORY(chatterinoEnv, "chatterino.env", logThreshold);
Q_LOGGING_CATEGORY(chatterinoFfzemotes, "chatterino.ffzemotes", logThreshold);
Q_LOGGING_CATEGORY(chatterinoHelper, "chatterino.helper", logThreshold);
Expand Down
1 change: 1 addition & 0 deletions src/common/QLogging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Q_DECLARE_LOGGING_CATEGORY(chatterinoCommon);
Q_DECLARE_LOGGING_CATEGORY(chatterinoCompletion);
Q_DECLARE_LOGGING_CATEGORY(chatterinoCrashhandler);
Q_DECLARE_LOGGING_CATEGORY(chatterinoEmoji);
Q_DECLARE_LOGGING_CATEGORY(chatterinoEmotes);
Q_DECLARE_LOGGING_CATEGORY(chatterinoEnv);
Q_DECLARE_LOGGING_CATEGORY(chatterinoFfzemotes);
Q_DECLARE_LOGGING_CATEGORY(chatterinoHelper);
Expand Down
11 changes: 10 additions & 1 deletion src/controllers/commands/builtin/twitch/SendWhisper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ bool appendWhisperMessageWordsLocally(const QStringList &words)
const auto &accemotes = *acc->accessEmotes();
const auto *bttvemotes = app->getBttvEmotes();
const auto *ffzemotes = app->getFfzEmotes();
const auto *emoteController = app->getEmotes();
auto emote = std::optional<EmotePtr>{};
for (int i = 2; i < words.length(); i++)
{
Expand All @@ -121,6 +122,14 @@ bool appendWhisperMessageWordsLocally(const QStringList &words)
}
} // Twitch emote

{ // third party emotes
emote = emoteController->resolveGlobal(EmoteName{words[i]});
if (emote)
{
b.emplace<EmoteElement>(*emote, MessageElementFlag::Emote);
continue;
}
} // third party emotes
{ // bttv/ffz emote
emote = bttvemotes->emote({words[i]});
if (!emote)
Expand All @@ -135,7 +144,7 @@ bool appendWhisperMessageWordsLocally(const QStringList &words)
}
} // bttv/ffz emote
{ // emoji/text
for (auto &variant : app->getEmotes()->getEmojis()->parse(words[i]))
for (auto &variant : emoteController->getEmojis()->parse(words[i]))
{
constexpr const static struct {
void operator()(EmotePtr emote, MessageBuilder &b) const
Expand Down
21 changes: 21 additions & 0 deletions src/controllers/completion/sources/EmoteSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include "Application.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "controllers/completion/sources/Helpers.hpp"
#include "controllers/emotes/ChannelEmotes.hpp"
#include "controllers/emotes/EmoteController.hpp"
#include "controllers/emotes/EmoteProvider.hpp"
#include "providers/bttv/BttvEmotes.hpp"
#include "providers/emoji/Emojis.hpp"
#include "providers/ffz/FfzEmotes.hpp"
Expand All @@ -13,6 +15,8 @@
#include "providers/twitch/TwitchIrcServer.hpp"
#include "widgets/splits/InputCompletionItem.hpp"

#include <QStringBuilder>

namespace chatterino::completion {

namespace {
Expand Down Expand Up @@ -105,6 +109,17 @@ void EmoteSource::initializeFromChannel(const Channel *channel)
auto user = getApp()->getAccounts()->twitch.getCurrent();
addEmotes(emotes, **user->accessEmotes(), "Twitch Emote");

const auto &channelEmotes = tc->channelEmotes();
for (const auto &data : channelEmotes.providerData())
{
auto provider = data.provider.lock();
if (!provider)
{
continue;
}
addEmotes(emotes, *data.emotes, u"Channel " % provider->name());
}

// TODO extract "Channel {BetterTTV,7TV,FrankerFaceZ}" text into a #define.
if (auto bttv = tc->bttvEmotes())
{
Expand All @@ -120,6 +135,12 @@ void EmoteSource::initializeFromChannel(const Channel *channel)
}
}

for (const auto &provider : app->getEmotes()->getProviders())
{
addEmotes(emotes, *provider->globalEmotes(),
u"Global " % provider->name());
}

if (auto bttvG = app->getBttvEmotes()->emotes())
{
addEmotes(emotes, *bttvG, "Global BetterTTV");
Expand Down
Loading
Loading