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

Zerowidth Emotes (7TV) #36

Merged
merged 5 commits into from
Aug 6, 2021
Merged
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 src/messages/Emote.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct Emote {
ImageSet images;
Tooltip tooltip;
Url homePage;
bool zeroWidth;

// FOURTF: no solution yet, to be refactored later
const QString &getCopyString() const
Expand Down
2 changes: 1 addition & 1 deletion src/messages/MessageElement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ enum class MessageElementFlag : int64_t {
OriginalLink = (1LL << 30),

// ZeroWidthEmotes are emotes that are supposed to overlay over any pre-existing emotes
// e.g. BTTV's SoSnowy during christmas season
// e.g. BTTV's SoSnowy during christmas season or zerowidth 7TV emotes
ZeroWidthEmote = (1LL << 31),

// (1LL << 32) is used by SeventvEmoteImage, it is next to FfzEmote
Expand Down
7 changes: 6 additions & 1 deletion src/providers/seventv/SeventvEmotes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ namespace {
.toObject()
.value("display_name")
.toString()};
int64_t visibility = jsonEmote.toObject().value("visibility").toInt();
auto visibilityFlags =
SeventvEmoteVisibilityFlags(SeventvEmoteVisibilityFlag(visibility));
bool zeroWidth =
visibilityFlags.has(SeventvEmoteVisibilityFlag::ZeroWidth);

auto emote = Emote(
{name,
Expand All @@ -64,7 +69,7 @@ namespace {
Tooltip{QString("%1<br>%2 7TV Emote<br>By: %3")
.arg(name.string, (isGlobal ? "Global" : "Channel"),
author.string)},
Url{emoteLinkFormat.arg(id.string)}});
Url{emoteLinkFormat.arg(id.string)}, zeroWidth});

auto result = CreateEmoteResult({id, name, emote});
return result;
Expand Down
18 changes: 18 additions & 0 deletions src/providers/seventv/SeventvEmotes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@

namespace chatterino {

// https://github.com/SevenTV/ServerGo/blob/dfe867f991e8cfd7a79d93b9bec681216c32abdb/src/mongo/datastructure/datastructure.go#L56-L67
enum class SeventvEmoteVisibilityFlag : int64_t {
None = 0LL,

Private = (1LL << 0),
Global = (1LL << 1),
Unlisted = (1LL << 2),

OverrideBttv = (1LL << 3),
OverrideFfz = (1LL << 4),
OverrideTwitchGlobal = (1LL << 5),
OverrideTwitchSubscriber = (1LL << 6),

ZeroWidth = (1LL << 7),
};

using SeventvEmoteVisibilityFlags = FlagsEnum<SeventvEmoteVisibilityFlag>;

struct Emote;
using EmotePtr = std::shared_ptr<const Emote>;
class EmoteMap;
Expand Down
8 changes: 8 additions & 0 deletions src/providers/twitch/TwitchMessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,10 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
(emote = this->twitchChannel->seventvEmote(name)))
{
flags = MessageElementFlag::SeventvEmote;
if (emote.value()->zeroWidth)
{
flags.set(MessageElementFlag::ZeroWidthEmote);
}
}
else if (this->twitchChannel &&
(emote = this->twitchChannel->bttvEmote(name)))
Expand All @@ -1020,6 +1024,10 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
else if ((emote = globalSeventvEmotes.emote(name)))
{
flags = MessageElementFlag::SeventvEmote;
if (emote.value()->zeroWidth)
{
flags.set(MessageElementFlag::ZeroWidthEmote);
}
}
else if ((emote = globalFfzEmotes.emote(name)))
{
Expand Down