Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Personal Emotes #192

Merged
merged 13 commits into from
Mar 11, 2023
75 changes: 57 additions & 18 deletions src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "providers/seventv/SeventvBadges.hpp"
#include "providers/seventv/SeventvEventAPI.hpp"
#include "providers/seventv/SeventvPaints.hpp"
#include "providers/seventv/SeventvPersonalEmotes.hpp"
#include "providers/twitch/ChannelPointReward.hpp"
#include "providers/twitch/PubSubActions.hpp"
#include "providers/twitch/PubSubManager.hpp"
Expand Down Expand Up @@ -85,6 +86,7 @@ Application::Application(Settings &_settings, Paths &_paths)
, ffzBadges(&this->emplace<FfzBadges>())
, seventvBadges(&this->emplace<SeventvBadges>())
, seventvPaints(&this->emplace<SeventvPaints>())
, seventvPersonalEmotes(&this->emplace<SeventvPersonalEmotes>())
, userData(&this->emplace<UserDataController>())
, sound(&this->emplace<SoundController>())
, logging(&this->emplace<Logging>())
Expand Down Expand Up @@ -639,30 +641,54 @@ void Application::initSeventvEventAPI()

this->twitch->seventvEventAPI->signals_.emoteAdded.connect(
[&](const auto &data) {
postToThread([this, data] {
this->twitch->forEachSeventvEmoteSet(
data.emoteSetID, [data](TwitchChannel &chan) {
chan.addSeventvEmote(data);
});
});
if (this->seventvPersonalEmotes->hasEmoteSet(data.emoteSetID))
{
this->seventvPersonalEmotes->updateEmoteSet(data.emoteSetID,
data);
}
else
{
postToThread([this, data] {
this->twitch->forEachSeventvEmoteSet(
data.emoteSetID, [data](TwitchChannel &chan) {
chan.addSeventvEmote(data);
});
});
}
});
this->twitch->seventvEventAPI->signals_.emoteUpdated.connect(
[&](const auto &data) {
postToThread([this, data] {
this->twitch->forEachSeventvEmoteSet(
data.emoteSetID, [data](TwitchChannel &chan) {
chan.updateSeventvEmote(data);
});
});
if (this->seventvPersonalEmotes->hasEmoteSet(data.emoteSetID))
{
this->seventvPersonalEmotes->updateEmoteSet(data.emoteSetID,
data);
}
else
{
postToThread([this, data] {
this->twitch->forEachSeventvEmoteSet(
data.emoteSetID, [data](TwitchChannel &chan) {
chan.updateSeventvEmote(data);
});
});
}
});
this->twitch->seventvEventAPI->signals_.emoteRemoved.connect(
[&](const auto &data) {
postToThread([this, data] {
this->twitch->forEachSeventvEmoteSet(
data.emoteSetID, [data](TwitchChannel &chan) {
chan.removeSeventvEmote(data);
});
});
if (this->seventvPersonalEmotes->hasEmoteSet(data.emoteSetID))
{
this->seventvPersonalEmotes->updateEmoteSet(data.emoteSetID,
data);
}
else
{
postToThread([this, data] {
this->twitch->forEachSeventvEmoteSet(
data.emoteSetID, [data](TwitchChannel &chan) {
chan.removeSeventvEmote(data);
});
});
}
});
this->twitch->seventvEventAPI->signals_.userUpdated.connect(
[&](const auto &data) {
Expand All @@ -671,6 +697,19 @@ void Application::initSeventvEventAPI()
chan.updateSeventvUser(data);
});
});
this->twitch->seventvEventAPI->signals_.personalEmoteSetAdded.connect(
[&](const auto &data) {
postToThread([this, data]() {
this->twitch->forEachChannelAndSpecialChannels([=](auto chan) {
if (auto *twitchChannel =
dynamic_cast<TwitchChannel *>(chan.get()))
{
twitchChannel->upsertPersonalSeventvEmotes(data.first,
data.second);
}
});
});
});

this->twitch->seventvEventAPI->start();
}
Expand Down
2 changes: 2 additions & 0 deletions src/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SeventvBadges;
class SeventvPaints;
class FfzBadges;
class SeventvBadges;
class SeventvPersonalEmotes;

class IApplication
{
Expand Down Expand Up @@ -95,6 +96,7 @@ class Application : public IApplication
FfzBadges *const ffzBadges{};
SeventvBadges *const seventvBadges{};
SeventvPaints *const seventvPaints{};
SeventvPersonalEmotes *const seventvPersonalEmotes{};
UserDataController *const userData{};
SoundController *const sound{};

Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ set(SOURCE_FILES
providers/seventv/SeventvEmotes.hpp
providers/seventv/SeventvEventAPI.cpp
providers/seventv/SeventvEventAPI.hpp
providers/seventv/SeventvPersonalEmotes.cpp
providers/seventv/SeventvPersonalEmotes.hpp

providers/seventv/eventapi/Client.cpp
providers/seventv/eventapi/Client.hpp
Expand Down
12 changes: 12 additions & 0 deletions src/common/CompletionModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "controllers/commands/Command.hpp"
#include "controllers/commands/CommandController.hpp"
#include "messages/Emote.hpp"
#include "providers/seventv/SeventvPersonalEmotes.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchCommon.hpp"
Expand Down Expand Up @@ -214,6 +215,17 @@ void CompletionModel::refresh(const QString &prefix, bool isFirstWord)
}
}

// 7TV Personal
if (const auto map = getApp()->seventvPersonalEmotes->getEmoteSetForUser(
getApp()->accounts->twitch.getCurrent()->getUserId()))
{
for (const auto &emote : *map.get())
{
addString(emote.first.string,
TaggedString::Type::SeventvPersonalEmote);
}
}

// 7TV Channel
for (const auto &emote : *tc->seventvEmotes())
{
Expand Down
1 change: 1 addition & 0 deletions src/common/CompletionModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class CompletionModel : public QAbstractListModel
BTTVChannelEmote,
SeventvGlobalEmote,
SeventvChannelEmote,
SeventvPersonalEmote,
TwitchGlobalEmote,
TwitchLocalEmote,
TwitchSubscriberEmote,
Expand Down
33 changes: 33 additions & 0 deletions src/messages/Message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include "util/IrcHelpers.hpp"
#include "widgets/helper/ScrollbarHighlight.hpp"

#include <algorithm>
#include <iterator>

using SBHighlight = chatterino::ScrollbarHighlight;

namespace chatterino {
Expand Down Expand Up @@ -62,6 +65,36 @@ SBHighlight Message::getScrollBarHighlight() const
return SBHighlight();
}

std::shared_ptr<const Message> Message::cloneWith(
const std::function<void(Message &)> &fn) const
Nerixyz marked this conversation as resolved.
Show resolved Hide resolved
Nerixyz marked this conversation as resolved.
Show resolved Hide resolved
{
auto cloned = std::make_shared<Message>();
cloned->flags = this->flags;
cloned->parseTime = this->parseTime;
cloned->id = this->id;
cloned->searchText = this->searchText;
cloned->messageText = this->messageText;
cloned->loginName = this->loginName;
cloned->displayName = this->displayName;
cloned->localizedName = this->localizedName;
cloned->timeoutUser = this->timeoutUser;
cloned->channelName = this->channelName;
cloned->usernameColor = this->usernameColor;
cloned->serverReceivedTime = this->serverReceivedTime;
cloned->badges = this->badges;
cloned->badgeInfos = this->badgeInfos;
cloned->highlightColor = this->highlightColor;
cloned->replyThread = this->replyThread;
cloned->count = this->count;
std::transform(this->elements.cbegin(), this->elements.cend(),
std::back_inserter(cloned->elements),
[](const auto &element) {
return element->clone();
});
fn(*cloned);
return std::move(cloned);
}

// Static
namespace {

Expand Down
10 changes: 10 additions & 0 deletions src/messages/Message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QTime>

#include <cinttypes>
#include <functional>
#include <memory>
#include <unordered_map>
#include <vector>
Expand Down Expand Up @@ -88,6 +89,15 @@ struct Message : boost::noncopyable {
std::vector<QString> seventvEventTargetEmotes;

ScrollbarHighlight getScrollBarHighlight() const;

/**
* Clones this message. Before contructing the shared pointer,
* `fn` is called with a reference to the new message.
*
* @return An identical message, independent from this one.
*/
std::shared_ptr<const Message> cloneWith(
const std::function<void(Message &)> &fn) const;
};

using MessagePtr = std::shared_ptr<const Message>;
Expand Down
Loading