feat: Add Live Emote Updates for BTTV (#4147)
This feature is enabled by default and can be disabled in settings with the "Enable BTTV live emotes updates" setting. Co-authored-by: Felanbird <41973452+Felanbird@users.noreply.github.com> Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
#include "messages/MessageElement.hpp"
|
||||
#include "messages/MessageThread.hpp"
|
||||
#include "providers/bttv/BttvEmotes.hpp"
|
||||
#include "providers/bttv/BttvLiveUpdates.hpp"
|
||||
#include "providers/bttv/liveupdates/BttvLiveUpdateMessages.hpp"
|
||||
#include "providers/RecentMessagesApi.hpp"
|
||||
#include "providers/seventv/eventapi/SeventvEventAPIDispatch.hpp"
|
||||
#include "providers/seventv/SeventvEmotes.hpp"
|
||||
@@ -103,6 +105,7 @@ TwitchChannel::TwitchChannel(const QString &name)
|
||||
this->refreshFFZChannelEmotes(false);
|
||||
this->refreshBTTVChannelEmotes(false);
|
||||
this->refreshSevenTVChannelEmotes(false);
|
||||
this->joinBttvChannel();
|
||||
});
|
||||
|
||||
this->connected.connect([this]() {
|
||||
@@ -121,6 +124,11 @@ TwitchChannel::TwitchChannel(const QString &name)
|
||||
this->destroyed.connect([this]() {
|
||||
getApp()->twitch->dropSeventvChannel(this->seventvUserID_,
|
||||
this->seventvEmoteSetID_);
|
||||
|
||||
if (getApp()->twitch->bttvLiveUpdates)
|
||||
{
|
||||
getApp()->twitch->bttvLiveUpdates->partChannel(this->roomId());
|
||||
}
|
||||
});
|
||||
|
||||
this->messageRemovedFromStart.connect([this](MessagePtr &msg) {
|
||||
@@ -622,6 +630,66 @@ const QString &TwitchChannel::seventvEmoteSetID() const
|
||||
return this->seventvEmoteSetID_;
|
||||
}
|
||||
|
||||
void TwitchChannel::joinBttvChannel() const
|
||||
{
|
||||
if (getApp()->twitch->bttvLiveUpdates)
|
||||
{
|
||||
const auto currentAccount = getApp()->accounts->twitch.getCurrent();
|
||||
QString userName;
|
||||
if (currentAccount && !currentAccount->isAnon())
|
||||
{
|
||||
userName = currentAccount->getUserName();
|
||||
}
|
||||
getApp()->twitch->bttvLiveUpdates->joinChannel(this->roomId(),
|
||||
userName);
|
||||
}
|
||||
}
|
||||
|
||||
void TwitchChannel::addBttvEmote(
|
||||
const BttvLiveUpdateEmoteUpdateAddMessage &message)
|
||||
{
|
||||
auto emote = BttvEmotes::addEmote(this->getDisplayName(), this->bttvEmotes_,
|
||||
message);
|
||||
|
||||
this->addOrReplaceLiveUpdatesAddRemove(true, "BTTV", QString() /*actor*/,
|
||||
emote->name.string);
|
||||
}
|
||||
|
||||
void TwitchChannel::updateBttvEmote(
|
||||
const BttvLiveUpdateEmoteUpdateAddMessage &message)
|
||||
{
|
||||
auto updated = BttvEmotes::updateEmote(this->getDisplayName(),
|
||||
this->bttvEmotes_, message);
|
||||
if (!updated)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const auto [oldEmote, newEmote] = *updated;
|
||||
if (oldEmote->name == newEmote->name)
|
||||
{
|
||||
return; // only the creator changed
|
||||
}
|
||||
|
||||
auto builder = MessageBuilder(liveUpdatesUpdateEmoteMessage, "BTTV",
|
||||
QString() /* actor */, newEmote->name.string,
|
||||
oldEmote->name.string);
|
||||
this->addMessage(builder.release());
|
||||
}
|
||||
|
||||
void TwitchChannel::removeBttvEmote(
|
||||
const BttvLiveUpdateEmoteRemoveMessage &message)
|
||||
{
|
||||
auto removed = BttvEmotes::removeEmote(this->bttvEmotes_, message);
|
||||
if (!removed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this->addOrReplaceLiveUpdatesAddRemove(false, "BTTV", QString() /*actor*/,
|
||||
removed.get()->name.string);
|
||||
}
|
||||
|
||||
void TwitchChannel::addSeventvEmote(
|
||||
const SeventvEventAPIEmoteAddDispatch &dispatch)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user