Use New 7TV Cosmetics System (#4512)
* feat(seventv): use new cosmetics system * chore: add changelog entry * fix: old `clang-format` * fix: small suggestions pt1 * refactor: add 7tv api wrapper * fix: small clang-tidy things * fix: remove unused constants * fix: old clangtidy * refactor: rename * fix: increase interval to 60s * fix: newline * fix: Twitch * docs: add comment * fix: remove v2 badges endpoint * fix: deadlock This is actually really sad. * fix: remove api entry * fix: old clang-format * Sort functions in SeventvBadges.hpp/cpp * Remove unused vector include * Add comments to SeventvBadges.hpp functions * Rename `addBadge` to `registerBadge` * fix: cleanup eventloop * ci(test): add timeout --------- Co-authored-by: Felanbird <41973452+Felanbird@users.noreply.github.com> Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include "providers/bttv/liveupdates/BttvLiveUpdateMessages.hpp"
|
||||
#include "providers/RecentMessagesApi.hpp"
|
||||
#include "providers/seventv/eventapi/Dispatch.hpp"
|
||||
#include "providers/seventv/SeventvAPI.hpp"
|
||||
#include "providers/seventv/SeventvEmotes.hpp"
|
||||
#include "providers/seventv/SeventvEventAPI.hpp"
|
||||
#include "providers/twitch/api/Helix.hpp"
|
||||
@@ -40,6 +41,7 @@
|
||||
|
||||
#include <IrcConnection>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QThread>
|
||||
@@ -105,6 +107,7 @@ TwitchChannel::TwitchChannel(const QString &name)
|
||||
this->refreshBTTVChannelEmotes(false);
|
||||
this->refreshSevenTVChannelEmotes(false);
|
||||
this->joinBttvChannel();
|
||||
this->listenSevenTVCosmetics();
|
||||
getIApp()->getTwitchLiveController()->add(
|
||||
std::dynamic_pointer_cast<TwitchChannel>(shared_from_this()));
|
||||
});
|
||||
@@ -248,6 +251,12 @@ TwitchChannel::~TwitchChannel()
|
||||
{
|
||||
getApp()->twitch->bttvLiveUpdates->partChannel(this->roomId());
|
||||
}
|
||||
|
||||
if (getApp()->twitch->seventvEventAPI)
|
||||
{
|
||||
getApp()->twitch->seventvEventAPI->unsubscribeTwitchChannel(
|
||||
this->roomId());
|
||||
}
|
||||
}
|
||||
|
||||
void TwitchChannel::initialize()
|
||||
@@ -600,6 +609,7 @@ void TwitchChannel::sendMessage(const QString &message)
|
||||
|
||||
bool messageSent = false;
|
||||
this->sendMessageSignal.invoke(this->getName(), parsedMessage, messageSent);
|
||||
this->updateSevenTVActivity();
|
||||
|
||||
if (messageSent)
|
||||
{
|
||||
@@ -1564,4 +1574,60 @@ boost::optional<CheerEmote> TwitchChannel::cheerEmote(const QString &string)
|
||||
return boost::none;
|
||||
}
|
||||
|
||||
void TwitchChannel::updateSevenTVActivity()
|
||||
{
|
||||
static const QString seventvActivityUrl =
|
||||
QStringLiteral("https://7tv.io/v3/users/%1/presences");
|
||||
|
||||
const auto currentSeventvUserID =
|
||||
getApp()->accounts->twitch.getCurrent()->getSeventvUserID();
|
||||
if (currentSeventvUserID.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!getSettings()->enableSevenTVEventAPI ||
|
||||
!getSettings()->sendSevenTVActivity)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->nextSeventvActivity_.isValid() &&
|
||||
QDateTime::currentDateTimeUtc() < this->nextSeventvActivity_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Make sure to not send activity again before receiving the response
|
||||
this->nextSeventvActivity_ = this->nextSeventvActivity_.addSecs(300);
|
||||
|
||||
qCDebug(chatterinoSeventv) << "Sending activity in" << this->getName();
|
||||
|
||||
getSeventvAPI().updatePresence(
|
||||
this->roomId(), currentSeventvUserID,
|
||||
[chan = weakOf<Channel>(this)]() {
|
||||
const auto self =
|
||||
std::dynamic_pointer_cast<TwitchChannel>(chan.lock());
|
||||
if (!self)
|
||||
{
|
||||
return Success;
|
||||
}
|
||||
self->nextSeventvActivity_ =
|
||||
QDateTime::currentDateTimeUtc().addSecs(60);
|
||||
return Success;
|
||||
},
|
||||
[](const auto &result) {
|
||||
qCDebug(chatterinoSeventv)
|
||||
<< "Failed to update 7TV activity:" << result.formatError();
|
||||
});
|
||||
}
|
||||
|
||||
void TwitchChannel::listenSevenTVCosmetics()
|
||||
{
|
||||
if (getApp()->twitch->seventvEventAPI)
|
||||
{
|
||||
getApp()->twitch->seventvEventAPI->subscribeTwitchChannel(
|
||||
this->roomId());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
Reference in New Issue
Block a user