Skip to content

Commit

Permalink
Zerowidth Emotes (7TV) (#36)
Browse files Browse the repository at this point in the history
Co-authored-by: Tal Neoran <talneoran@gmail.com>
Co-authored-by: zneix <zneix@zneix.eu>
  • Loading branch information
3 people committed Aug 6, 2021
1 parent b251ac9 commit 2d3fe1f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
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

0 comments on commit 2d3fe1f

Please sign in to comment.