2018-06-26 14:09:39 +02:00
|
|
|
#include "providers/twitch/TwitchChannel.hpp"
|
2018-04-28 15:48:40 +02:00
|
|
|
|
2022-12-31 15:41:01 +01:00
|
|
|
#include "Application.hpp"
|
2018-06-26 15:33:51 +02:00
|
|
|
#include "common/Common.hpp"
|
2024-01-15 21:28:44 +01:00
|
|
|
#include "common/network/NetworkRequest.hpp"
|
|
|
|
#include "common/network/NetworkResult.hpp"
|
2021-07-11 11:12:49 +02:00
|
|
|
#include "common/QLogging.hpp"
|
2018-07-07 13:08:57 +02:00
|
|
|
#include "controllers/accounts/AccountController.hpp"
|
2018-08-12 15:29:40 +02:00
|
|
|
#include "controllers/notifications/NotificationController.hpp"
|
2023-07-02 15:52:15 +02:00
|
|
|
#include "controllers/twitch/LiveController.hpp"
|
2022-12-18 15:36:39 +01:00
|
|
|
#include "messages/Emote.hpp"
|
2022-12-31 15:41:01 +01:00
|
|
|
#include "messages/Image.hpp"
|
|
|
|
#include "messages/Link.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "messages/Message.hpp"
|
2022-12-31 15:41:01 +01:00
|
|
|
#include "messages/MessageElement.hpp"
|
|
|
|
#include "messages/MessageThread.hpp"
|
2018-08-11 17:15:17 +02:00
|
|
|
#include "providers/bttv/BttvEmotes.hpp"
|
2023-01-21 15:06:55 +01:00
|
|
|
#include "providers/bttv/BttvLiveUpdates.hpp"
|
|
|
|
#include "providers/bttv/liveupdates/BttvLiveUpdateMessages.hpp"
|
2024-02-25 12:18:57 +01:00
|
|
|
#include "providers/ffz/FfzBadges.hpp"
|
2024-01-21 14:20:21 +01:00
|
|
|
#include "providers/ffz/FfzEmotes.hpp"
|
2023-08-12 13:34:59 +02:00
|
|
|
#include "providers/recentmessages/Api.hpp"
|
2023-02-04 13:42:52 +01:00
|
|
|
#include "providers/seventv/eventapi/Dispatch.hpp"
|
2023-07-29 11:49:44 +02:00
|
|
|
#include "providers/seventv/SeventvAPI.hpp"
|
2022-10-16 13:22:17 +02:00
|
|
|
#include "providers/seventv/SeventvEmotes.hpp"
|
2022-11-13 12:07:41 +01:00
|
|
|
#include "providers/seventv/SeventvEventAPI.hpp"
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include "providers/twitch/api/Helix.hpp"
|
2022-12-31 15:41:01 +01:00
|
|
|
#include "providers/twitch/ChannelPointReward.hpp"
|
2019-04-13 19:14:58 +02:00
|
|
|
#include "providers/twitch/IrcMessageHandler.hpp"
|
2022-05-07 17:22:39 +02:00
|
|
|
#include "providers/twitch/PubSubManager.hpp"
|
2022-12-18 15:36:39 +01:00
|
|
|
#include "providers/twitch/TwitchAccount.hpp"
|
2018-07-07 13:08:57 +02:00
|
|
|
#include "providers/twitch/TwitchCommon.hpp"
|
2022-05-07 17:22:39 +02:00
|
|
|
#include "providers/twitch/TwitchIrcServer.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "providers/twitch/TwitchMessageBuilder.hpp"
|
2018-06-28 19:46:45 +02:00
|
|
|
#include "singletons/Emotes.hpp"
|
|
|
|
#include "singletons/Settings.hpp"
|
2024-03-01 21:12:02 +01:00
|
|
|
#include "singletons/StreamerMode.hpp"
|
2018-08-12 15:29:40 +02:00
|
|
|
#include "singletons/Toasts.hpp"
|
2018-08-12 20:21:21 +02:00
|
|
|
#include "singletons/WindowManager.hpp"
|
2023-10-08 18:50:48 +02:00
|
|
|
#include "util/Helpers.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "util/PostToThread.hpp"
|
2021-07-11 11:12:49 +02:00
|
|
|
#include "util/QStringHash.hpp"
|
2018-08-29 19:25:37 +02:00
|
|
|
#include "widgets/Window.hpp"
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
#include <IrcConnection>
|
2018-07-08 11:42:48 +02:00
|
|
|
#include <QJsonArray>
|
2023-07-29 11:49:44 +02:00
|
|
|
#include <QJsonDocument>
|
2018-08-02 14:23:27 +02:00
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonValue>
|
2017-11-04 14:57:29 +01:00
|
|
|
#include <QThread>
|
|
|
|
#include <QTimer>
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include <rapidjson/document.h>
|
2017-09-16 00:05:06 +02:00
|
|
|
|
|
|
|
namespace chatterino {
|
2018-08-10 18:56:17 +02:00
|
|
|
namespace {
|
2022-12-24 12:56:11 +01:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 1, 0)
|
|
|
|
const QString MAGIC_MESSAGE_SUFFIX = QString((const char *)u8" \U000E0000");
|
|
|
|
#else
|
|
|
|
const QString MAGIC_MESSAGE_SUFFIX = QString::fromUtf8(u8" \U000E0000");
|
|
|
|
#endif
|
2021-01-17 14:47:34 +01:00
|
|
|
constexpr int CLIP_CREATION_COOLDOWN = 5000;
|
|
|
|
const QString CLIPS_LINK("https://clips.twitch.tv/%1");
|
|
|
|
const QString CLIPS_FAILURE_CLIPS_DISABLED_TEXT(
|
|
|
|
"Failed to create a clip - the streamer has clips disabled entirely or "
|
|
|
|
"requires a certain subscriber or follower status to create clips.");
|
|
|
|
const QString CLIPS_FAILURE_NOT_AUTHENTICATED_TEXT(
|
|
|
|
"Failed to create a clip - you need to re-authenticate.");
|
|
|
|
const QString CLIPS_FAILURE_UNKNOWN_ERROR_TEXT(
|
|
|
|
"Failed to create a clip - an unknown error occurred.");
|
|
|
|
const QString LOGIN_PROMPT_TEXT("Click here to add your account again.");
|
|
|
|
const Link ACCOUNTS_LINK(Link::OpenAccountsPage, QString());
|
2019-05-01 22:10:51 +02:00
|
|
|
|
2022-11-01 23:18:57 +01:00
|
|
|
// Maximum number of chatters to fetch when refreshing chatters
|
|
|
|
constexpr auto MAX_CHATTERS_TO_FETCH = 5000;
|
2024-02-25 18:19:20 +01:00
|
|
|
|
|
|
|
// From Twitch docs - expected size for a badge (1x)
|
|
|
|
constexpr QSize BASE_BADGE_SIZE(18, 18);
|
2018-08-10 18:56:17 +02:00
|
|
|
} // namespace
|
2018-03-24 12:02:07 +01:00
|
|
|
|
2021-07-13 13:23:50 +02:00
|
|
|
TwitchChannel::TwitchChannel(const QString &name)
|
2018-08-02 14:23:27 +02:00
|
|
|
: Channel(name, Channel::Type::Twitch)
|
2019-09-17 12:10:38 +02:00
|
|
|
, ChannelChatters(*static_cast<Channel *>(this))
|
2023-07-23 12:11:57 +02:00
|
|
|
, nameOptions{name, name, name}
|
2018-07-15 20:28:54 +02:00
|
|
|
, subscriptionUrl_("https://www.twitch.tv/subs/" + name)
|
|
|
|
, channelUrl_("https://twitch.tv/" + name)
|
2024-04-18 17:49:50 +02:00
|
|
|
, popoutPlayerUrl_(TWITCH_PLAYER_URL.arg(name))
|
2018-08-12 00:01:37 +02:00
|
|
|
, bttvEmotes_(std::make_shared<EmoteMap>())
|
|
|
|
, ffzEmotes_(std::make_shared<EmoteMap>())
|
2022-10-16 13:22:17 +02:00
|
|
|
, seventvEmotes_(std::make_shared<EmoteMap>())
|
2017-09-16 00:05:06 +02:00
|
|
|
{
|
2020-11-21 16:20:10 +01:00
|
|
|
qCDebug(chatterinoTwitch) << "[TwitchChannel" << name << "] Opened";
|
2018-06-11 11:51:46 +02:00
|
|
|
|
2022-05-07 17:22:39 +02:00
|
|
|
this->bSignals_.emplace_back(
|
2024-07-21 15:09:59 +02:00
|
|
|
getApp()->getAccounts()->twitch.currentUserChanged.connect([this] {
|
2021-12-19 15:57:56 +01:00
|
|
|
this->setMod(false);
|
2022-05-07 17:22:39 +02:00
|
|
|
this->refreshPubSub();
|
|
|
|
}));
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2022-05-07 17:22:39 +02:00
|
|
|
this->refreshPubSub();
|
2023-09-16 13:52:51 +02:00
|
|
|
// We can safely ignore this signal connection since it's a private signal, meaning
|
|
|
|
// it will only ever be invoked by TwitchChannel itself
|
|
|
|
std::ignore = this->userStateChanged.connect([this] {
|
2022-05-07 17:22:39 +02:00
|
|
|
this->refreshPubSub();
|
2020-11-08 12:02:19 +01:00
|
|
|
});
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2023-09-16 13:52:51 +02:00
|
|
|
// We can safely ignore this signal connection this has no external dependencies - once the signal
|
|
|
|
// is destroyed, it will no longer be able to fire
|
2023-12-09 19:46:30 +01:00
|
|
|
std::ignore = this->joined.connect([this]() {
|
2023-12-16 13:38:35 +01:00
|
|
|
if (this->disconnected_)
|
2022-08-06 18:18:34 +02:00
|
|
|
{
|
2023-12-09 19:46:30 +01:00
|
|
|
this->loadRecentMessagesReconnect();
|
2023-12-16 13:38:35 +01:00
|
|
|
this->lastConnectedAt_ = std::chrono::system_clock::now();
|
|
|
|
this->disconnected_ = false;
|
2022-08-06 18:18:34 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-07-14 14:24:18 +02:00
|
|
|
// timers
|
2022-12-24 12:56:11 +01:00
|
|
|
QObject::connect(&this->chattersListTimer_, &QTimer::timeout, [this] {
|
2020-11-08 12:02:19 +01:00
|
|
|
this->refreshChatters();
|
|
|
|
});
|
2022-11-01 23:18:57 +01:00
|
|
|
|
2018-07-14 14:24:18 +02:00
|
|
|
this->chattersListTimer_.start(5 * 60 * 1000);
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2022-12-24 12:56:11 +01:00
|
|
|
QObject::connect(&this->threadClearTimer_, &QTimer::timeout, [this] {
|
2022-07-31 12:45:25 +02:00
|
|
|
// We periodically check for any dangling reply threads that missed
|
|
|
|
// being cleaned up on messageRemovedFromStart. This could occur if
|
|
|
|
// some other part of the program, like a user card, held a reference
|
|
|
|
// to the message.
|
|
|
|
//
|
|
|
|
// It seems difficult to actually replicate a situation where things
|
|
|
|
// are actually cleaned up, but I've verified that cleanups DO happen.
|
|
|
|
this->cleanUpReplyThreads();
|
|
|
|
});
|
|
|
|
this->threadClearTimer_.start(5 * 60 * 1000);
|
|
|
|
|
2018-07-14 14:24:18 +02:00
|
|
|
// debugging
|
2018-06-19 20:34:50 +02:00
|
|
|
#if 0
|
|
|
|
for (int i = 0; i < 1000; i++) {
|
2024-07-07 22:03:05 +02:00
|
|
|
this->addSystemMessage("asef");
|
2018-06-19 20:34:50 +02:00
|
|
|
}
|
|
|
|
#endif
|
2017-09-16 00:05:06 +02:00
|
|
|
}
|
|
|
|
|
2023-02-04 13:42:52 +01:00
|
|
|
TwitchChannel::~TwitchChannel()
|
|
|
|
{
|
2024-07-21 15:09:59 +02:00
|
|
|
getApp()->getTwitch()->dropSeventvChannel(this->seventvUserID_,
|
|
|
|
this->seventvEmoteSetID_);
|
2023-02-04 13:42:52 +01:00
|
|
|
|
2024-07-21 15:09:59 +02:00
|
|
|
if (getApp()->getTwitch()->getBTTVLiveUpdates())
|
2023-02-04 13:42:52 +01:00
|
|
|
{
|
2024-07-21 15:09:59 +02:00
|
|
|
getApp()->getTwitch()->getBTTVLiveUpdates()->partChannel(
|
2024-06-01 14:56:40 +02:00
|
|
|
this->roomId());
|
2023-02-04 13:42:52 +01:00
|
|
|
}
|
2023-07-29 11:49:44 +02:00
|
|
|
|
2024-07-21 15:09:59 +02:00
|
|
|
if (getApp()->getTwitch()->getSeventvEventAPI())
|
2023-07-29 11:49:44 +02:00
|
|
|
{
|
2024-07-21 15:09:59 +02:00
|
|
|
getApp()->getTwitch()->getSeventvEventAPI()->unsubscribeTwitchChannel(
|
2023-07-29 11:49:44 +02:00
|
|
|
this->roomId());
|
|
|
|
}
|
2023-02-04 13:42:52 +01:00
|
|
|
}
|
|
|
|
|
2018-08-13 13:54:39 +02:00
|
|
|
void TwitchChannel::initialize()
|
|
|
|
{
|
|
|
|
this->refreshChatters();
|
2018-10-26 00:34:48 +02:00
|
|
|
this->refreshBadges();
|
2018-08-13 13:54:39 +02:00
|
|
|
}
|
|
|
|
|
2017-11-04 14:57:29 +01:00
|
|
|
bool TwitchChannel::isEmpty() const
|
2017-09-16 00:05:06 +02:00
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
return this->getName().isEmpty();
|
2017-09-16 00:05:06 +02:00
|
|
|
}
|
|
|
|
|
2017-11-04 14:57:29 +01:00
|
|
|
bool TwitchChannel::canSendMessage() const
|
2017-09-16 00:05:06 +02:00
|
|
|
{
|
2017-12-31 00:50:07 +01:00
|
|
|
return !this->isEmpty();
|
2017-09-16 00:05:06 +02:00
|
|
|
}
|
|
|
|
|
2020-12-06 14:07:33 +01:00
|
|
|
const QString &TwitchChannel::getDisplayName() const
|
|
|
|
{
|
|
|
|
return this->nameOptions.displayName;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::setDisplayName(const QString &name)
|
|
|
|
{
|
|
|
|
this->nameOptions.displayName = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &TwitchChannel::getLocalizedName() const
|
|
|
|
{
|
|
|
|
return this->nameOptions.localizedName;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::setLocalizedName(const QString &name)
|
|
|
|
{
|
|
|
|
this->nameOptions.localizedName = name;
|
|
|
|
}
|
|
|
|
|
2020-05-16 12:43:44 +02:00
|
|
|
void TwitchChannel::refreshBTTVChannelEmotes(bool manualRefresh)
|
2017-09-16 00:05:06 +02:00
|
|
|
{
|
2022-08-28 12:20:47 +02:00
|
|
|
if (!Settings::instance().enableBTTVChannelEmotes)
|
|
|
|
{
|
|
|
|
this->bttvEmotes_.set(EMPTY_EMOTE_MAP);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-11 17:15:17 +02:00
|
|
|
BttvEmotes::loadChannel(
|
2020-12-12 16:15:49 +01:00
|
|
|
weakOf<Channel>(this), this->roomId(), this->getLocalizedName(),
|
2020-05-16 12:43:44 +02:00
|
|
|
[this, weak = weakOf<Channel>(this)](auto &&emoteMap) {
|
2018-08-11 17:15:17 +02:00
|
|
|
if (auto shared = weak.lock())
|
2024-01-07 13:15:36 +01:00
|
|
|
{
|
|
|
|
this->setBttvEmotes(std::make_shared<const EmoteMap>(emoteMap));
|
|
|
|
}
|
2020-05-16 12:43:44 +02:00
|
|
|
},
|
|
|
|
manualRefresh);
|
2019-08-27 20:45:55 +02:00
|
|
|
}
|
|
|
|
|
2020-05-16 12:43:44 +02:00
|
|
|
void TwitchChannel::refreshFFZChannelEmotes(bool manualRefresh)
|
2019-08-27 20:45:55 +02:00
|
|
|
{
|
2022-08-28 12:20:47 +02:00
|
|
|
if (!Settings::instance().enableFFZChannelEmotes)
|
|
|
|
{
|
|
|
|
this->ffzEmotes_.set(EMPTY_EMOTE_MAP);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-11 17:15:17 +02:00
|
|
|
FfzEmotes::loadChannel(
|
2020-05-16 12:43:44 +02:00
|
|
|
weakOf<Channel>(this), this->roomId(),
|
2019-09-07 13:48:30 +02:00
|
|
|
[this, weak = weakOf<Channel>(this)](auto &&emoteMap) {
|
2018-08-02 14:23:27 +02:00
|
|
|
if (auto shared = weak.lock())
|
2024-01-07 13:15:36 +01:00
|
|
|
{
|
|
|
|
this->setFfzEmotes(std::make_shared<const EmoteMap>(emoteMap));
|
|
|
|
}
|
2019-09-07 13:48:30 +02:00
|
|
|
},
|
|
|
|
[this, weak = weakOf<Channel>(this)](auto &&modBadge) {
|
|
|
|
if (auto shared = weak.lock())
|
|
|
|
{
|
2024-01-17 21:05:44 +01:00
|
|
|
this->ffzCustomModBadge_.set(
|
|
|
|
std::forward<decltype(modBadge)>(modBadge));
|
2019-09-07 13:48:30 +02:00
|
|
|
}
|
2020-05-16 12:43:44 +02:00
|
|
|
},
|
2021-04-17 14:42:30 +02:00
|
|
|
[this, weak = weakOf<Channel>(this)](auto &&vipBadge) {
|
|
|
|
if (auto shared = weak.lock())
|
|
|
|
{
|
2024-01-17 21:05:44 +01:00
|
|
|
this->ffzCustomVipBadge_.set(
|
|
|
|
std::forward<decltype(vipBadge)>(vipBadge));
|
2021-04-17 14:42:30 +02:00
|
|
|
}
|
|
|
|
},
|
2024-02-25 12:18:57 +01:00
|
|
|
[this, weak = weakOf<Channel>(this)](auto &&channelBadges) {
|
|
|
|
if (auto shared = weak.lock())
|
|
|
|
{
|
|
|
|
this->tgFfzChannelBadges_.guard();
|
|
|
|
this->ffzChannelBadges_ =
|
|
|
|
std::forward<decltype(channelBadges)>(channelBadges);
|
|
|
|
}
|
|
|
|
},
|
2020-05-16 12:43:44 +02:00
|
|
|
manualRefresh);
|
2017-09-16 00:05:06 +02:00
|
|
|
}
|
|
|
|
|
2022-10-16 13:22:17 +02:00
|
|
|
void TwitchChannel::refreshSevenTVChannelEmotes(bool manualRefresh)
|
|
|
|
{
|
|
|
|
if (!Settings::instance().enableSevenTVChannelEmotes)
|
|
|
|
{
|
|
|
|
this->seventvEmotes_.set(EMPTY_EMOTE_MAP);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SeventvEmotes::loadChannelEmotes(
|
|
|
|
weakOf<Channel>(this), this->roomId(),
|
2022-11-13 12:07:41 +01:00
|
|
|
[this, weak = weakOf<Channel>(this)](auto &&emoteMap,
|
|
|
|
auto channelInfo) {
|
2022-10-16 13:22:17 +02:00
|
|
|
if (auto shared = weak.lock())
|
|
|
|
{
|
2024-01-07 13:15:36 +01:00
|
|
|
this->setSeventvEmotes(
|
|
|
|
std::make_shared<const EmoteMap>(emoteMap));
|
2022-11-13 12:07:41 +01:00
|
|
|
this->updateSeventvData(channelInfo.userID,
|
|
|
|
channelInfo.emoteSetID);
|
|
|
|
this->seventvUserTwitchConnectionIndex_ =
|
|
|
|
channelInfo.twitchConnectionIndex;
|
2022-10-16 13:22:17 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
manualRefresh);
|
|
|
|
}
|
|
|
|
|
2024-01-07 13:15:36 +01:00
|
|
|
void TwitchChannel::setBttvEmotes(std::shared_ptr<const EmoteMap> &&map)
|
|
|
|
{
|
|
|
|
this->bttvEmotes_.set(std::move(map));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::setFfzEmotes(std::shared_ptr<const EmoteMap> &&map)
|
|
|
|
{
|
|
|
|
this->ffzEmotes_.set(std::move(map));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::setSeventvEmotes(std::shared_ptr<const EmoteMap> &&map)
|
|
|
|
{
|
|
|
|
this->seventvEmotes_.set(std::move(map));
|
|
|
|
}
|
|
|
|
|
2023-11-08 18:14:48 +01:00
|
|
|
void TwitchChannel::addQueuedRedemption(const QString &rewardId,
|
|
|
|
const QString &originalContent,
|
|
|
|
Communi::IrcMessage *message)
|
|
|
|
{
|
|
|
|
this->waitingRedemptions_.push_back({
|
|
|
|
rewardId,
|
|
|
|
originalContent,
|
|
|
|
{message->clone(), {}},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-08 15:37:22 +02:00
|
|
|
void TwitchChannel::addChannelPointReward(const ChannelPointReward &reward)
|
|
|
|
{
|
2020-08-22 11:45:18 +02:00
|
|
|
assertInGuiThread();
|
|
|
|
|
2020-08-08 15:37:22 +02:00
|
|
|
if (!reward.isUserInputRequired)
|
|
|
|
{
|
|
|
|
MessageBuilder builder;
|
2021-08-01 15:44:04 +02:00
|
|
|
TwitchMessageBuilder::appendChannelPointRewardMessage(
|
|
|
|
reward, &builder, this->isMod(), this->isBroadcaster());
|
2024-07-13 13:15:11 +02:00
|
|
|
this->addMessage(builder.release(), MessageContext::Original);
|
2020-08-08 15:37:22 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-07 17:22:39 +02:00
|
|
|
bool result = false;
|
2020-08-08 15:37:22 +02:00
|
|
|
{
|
|
|
|
auto channelPointRewards = this->channelPointRewards_.access();
|
|
|
|
result = channelPointRewards->try_emplace(reward.id, reward).second;
|
|
|
|
}
|
|
|
|
if (result)
|
|
|
|
{
|
2023-11-08 18:14:48 +01:00
|
|
|
const auto &channelName = this->getName();
|
2022-11-12 00:49:44 +01:00
|
|
|
qCDebug(chatterinoTwitch)
|
2023-11-08 18:14:48 +01:00
|
|
|
<< "[TwitchChannel" << channelName
|
2022-11-12 00:49:44 +01:00
|
|
|
<< "] Channel point reward added:" << reward.id << ","
|
|
|
|
<< reward.title << "," << reward.isUserInputRequired;
|
2023-02-09 00:43:52 +01:00
|
|
|
|
2024-07-21 15:09:59 +02:00
|
|
|
auto *server = getApp()->getTwitch();
|
2023-11-08 18:14:48 +01:00
|
|
|
auto it = std::remove_if(
|
|
|
|
this->waitingRedemptions_.begin(), this->waitingRedemptions_.end(),
|
|
|
|
[&](const QueuedRedemption &msg) {
|
|
|
|
if (reward.id == msg.rewardID)
|
|
|
|
{
|
|
|
|
IrcMessageHandler::instance().addMessage(
|
|
|
|
msg.message.get(), shared_from_this(),
|
|
|
|
msg.originalContent, *server, false, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
this->waitingRedemptions_.erase(it, this->waitingRedemptions_.end());
|
2020-08-08 15:37:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TwitchChannel::isChannelPointRewardKnown(const QString &rewardId)
|
|
|
|
{
|
|
|
|
const auto &pointRewards = this->channelPointRewards_.accessConst();
|
|
|
|
const auto &it = pointRewards->find(rewardId);
|
|
|
|
return it != pointRewards->end();
|
|
|
|
}
|
|
|
|
|
2023-10-08 18:50:48 +02:00
|
|
|
std::optional<ChannelPointReward> TwitchChannel::channelPointReward(
|
2020-08-08 15:37:22 +02:00
|
|
|
const QString &rewardId) const
|
|
|
|
{
|
|
|
|
auto rewards = this->channelPointRewards_.accessConst();
|
|
|
|
auto it = rewards->find(rewardId);
|
|
|
|
|
|
|
|
if (it == rewards->end())
|
2024-01-14 17:54:52 +01:00
|
|
|
{
|
2023-10-08 18:50:48 +02:00
|
|
|
return std::nullopt;
|
2024-01-14 17:54:52 +01:00
|
|
|
}
|
2020-08-08 15:37:22 +02:00
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
2023-07-02 15:52:15 +02:00
|
|
|
void TwitchChannel::updateStreamStatus(
|
2024-07-20 14:19:27 +02:00
|
|
|
const std::optional<HelixStream> &helixStream, bool isInitialUpdate)
|
2023-07-02 15:52:15 +02:00
|
|
|
{
|
|
|
|
if (helixStream)
|
|
|
|
{
|
|
|
|
auto stream = *helixStream;
|
|
|
|
{
|
|
|
|
auto status = this->streamStatus_.access();
|
2024-07-14 11:45:21 +02:00
|
|
|
status->streamId = stream.id;
|
2023-07-02 15:52:15 +02:00
|
|
|
status->viewerCount = stream.viewerCount;
|
|
|
|
status->gameId = stream.gameId;
|
|
|
|
status->game = stream.gameName;
|
|
|
|
status->title = stream.title;
|
|
|
|
QDateTime since =
|
|
|
|
QDateTime::fromString(stream.startedAt, Qt::ISODate);
|
|
|
|
auto diff = since.secsTo(QDateTime::currentDateTime());
|
|
|
|
status->uptime = QString::number(diff / 3600) + "h " +
|
|
|
|
QString::number(diff % 3600 / 60) + "m";
|
2024-02-03 19:12:00 +01:00
|
|
|
status->uptimeSeconds = diff;
|
2023-07-02 15:52:15 +02:00
|
|
|
|
|
|
|
status->rerun = false;
|
|
|
|
status->streamType = stream.type;
|
2024-02-18 17:22:53 +01:00
|
|
|
for (const auto &tag : stream.tags)
|
|
|
|
{
|
|
|
|
if (QString::compare(tag, "Rerun", Qt::CaseInsensitive) == 0)
|
|
|
|
{
|
|
|
|
status->rerun = true;
|
|
|
|
status->streamType = "rerun";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-07-02 15:52:15 +02:00
|
|
|
}
|
|
|
|
if (this->setLive(true))
|
|
|
|
{
|
2024-07-20 14:19:27 +02:00
|
|
|
this->onLiveStatusChanged(true, isInitialUpdate);
|
2023-07-02 15:52:15 +02:00
|
|
|
}
|
|
|
|
this->streamStatusChanged.invoke();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (this->setLive(false))
|
|
|
|
{
|
2024-07-20 14:19:27 +02:00
|
|
|
this->onLiveStatusChanged(false, isInitialUpdate);
|
2023-07-02 15:52:15 +02:00
|
|
|
this->streamStatusChanged.invoke();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-20 14:19:27 +02:00
|
|
|
void TwitchChannel::onLiveStatusChanged(bool isLive, bool isInitialUpdate)
|
|
|
|
{
|
|
|
|
// Similar code exists in NotificationController::updateFakeChannel.
|
|
|
|
// Since we're a TwitchChannel, we also send a message here.
|
|
|
|
if (isLive)
|
|
|
|
{
|
|
|
|
qCDebug(chatterinoTwitch).nospace().noquote()
|
|
|
|
<< "[TwitchChannel " << this->getName() << "] Online";
|
|
|
|
|
2024-07-21 15:09:59 +02:00
|
|
|
getApp()->getNotifications()->notifyTwitchChannelLive({
|
2024-07-20 14:19:27 +02:00
|
|
|
.channelId = this->roomId(),
|
|
|
|
.channelName = this->getName(),
|
|
|
|
.displayName = this->getDisplayName(),
|
|
|
|
.title = this->accessStreamStatus()->title,
|
|
|
|
.isInitialUpdate = isInitialUpdate,
|
|
|
|
});
|
|
|
|
|
|
|
|
// Channel live message
|
|
|
|
MessageBuilder builder;
|
|
|
|
TwitchMessageBuilder::liveSystemMessage(this->getDisplayName(),
|
|
|
|
&builder);
|
|
|
|
builder.message().id = this->roomId();
|
|
|
|
this->addMessage(builder.release(), MessageContext::Original);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qCDebug(chatterinoTwitch).nospace().noquote()
|
|
|
|
<< "[TwitchChannel " << this->getName() << "] Offline";
|
|
|
|
|
|
|
|
// Channel offline message
|
|
|
|
MessageBuilder builder;
|
|
|
|
TwitchMessageBuilder::offlineSystemMessage(this->getDisplayName(),
|
|
|
|
&builder);
|
|
|
|
this->addMessage(builder.release(), MessageContext::Original);
|
|
|
|
|
2024-07-21 15:09:59 +02:00
|
|
|
getApp()->getNotifications()->notifyTwitchChannelOffline(
|
2024-07-20 14:19:27 +02:00
|
|
|
this->roomId());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-07-02 15:52:15 +02:00
|
|
|
void TwitchChannel::updateStreamTitle(const QString &title)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto status = this->streamStatus_.access();
|
|
|
|
if (status->title == title)
|
|
|
|
{
|
|
|
|
// Title has not changed
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
status->title = title;
|
|
|
|
}
|
|
|
|
this->streamStatusChanged.invoke();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::updateDisplayName(const QString &displayName)
|
|
|
|
{
|
2023-07-23 12:11:57 +02:00
|
|
|
if (displayName == this->nameOptions.actualDisplayName)
|
2023-07-02 15:52:15 +02:00
|
|
|
{
|
|
|
|
// Display name has not changed
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display name has changed
|
|
|
|
|
2023-07-23 12:11:57 +02:00
|
|
|
this->nameOptions.actualDisplayName = displayName;
|
|
|
|
|
2023-07-02 15:52:15 +02:00
|
|
|
if (QString::compare(displayName, this->getName(), Qt::CaseInsensitive) ==
|
|
|
|
0)
|
|
|
|
{
|
|
|
|
// Display name is only a case variation of the login name
|
|
|
|
this->setDisplayName(displayName);
|
|
|
|
|
|
|
|
this->setLocalizedName(displayName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Display name contains Chinese, Japanese, or Korean characters
|
|
|
|
this->setDisplayName(this->getName());
|
|
|
|
|
|
|
|
this->setLocalizedName(
|
|
|
|
QString("%1(%2)").arg(this->getName()).arg(displayName));
|
|
|
|
}
|
|
|
|
|
|
|
|
this->addRecentChatter(this->getDisplayName());
|
|
|
|
|
|
|
|
this->displayNameChanged.invoke();
|
|
|
|
}
|
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
void TwitchChannel::showLoginMessage()
|
2017-09-16 00:05:06 +02:00
|
|
|
{
|
2022-07-31 12:45:25 +02:00
|
|
|
const auto linkColor = MessageColor(MessageColor::Link);
|
|
|
|
const auto accountsLink = Link(Link::OpenAccountsPage, QString());
|
2024-07-21 15:09:59 +02:00
|
|
|
const auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
|
2022-07-31 12:45:25 +02:00
|
|
|
const auto expirationText =
|
|
|
|
QStringLiteral("You need to log in to send messages. You can link your "
|
|
|
|
"Twitch account");
|
|
|
|
const auto loginPromptText = QStringLiteral("in the settings.");
|
|
|
|
|
|
|
|
auto builder = MessageBuilder();
|
|
|
|
builder.message().flags.set(MessageFlag::System);
|
|
|
|
builder.message().flags.set(MessageFlag::DoNotTriggerNotification);
|
|
|
|
|
|
|
|
builder.emplace<TimestampElement>();
|
|
|
|
builder.emplace<TextElement>(expirationText, MessageElementFlag::Text,
|
|
|
|
MessageColor::System);
|
|
|
|
builder
|
|
|
|
.emplace<TextElement>(loginPromptText, MessageElementFlag::Text,
|
|
|
|
linkColor)
|
|
|
|
->setLink(accountsLink);
|
|
|
|
|
2024-07-13 13:15:11 +02:00
|
|
|
this->addMessage(builder.release(), MessageContext::Original);
|
2022-07-31 12:45:25 +02:00
|
|
|
}
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2023-09-16 13:52:51 +02:00
|
|
|
void TwitchChannel::roomIdChanged()
|
|
|
|
{
|
2024-07-21 15:09:59 +02:00
|
|
|
if (getApp()->isTest())
|
2024-06-16 12:22:51 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2023-09-16 13:52:51 +02:00
|
|
|
this->refreshPubSub();
|
|
|
|
this->refreshBadges();
|
|
|
|
this->refreshCheerEmotes();
|
|
|
|
this->refreshFFZChannelEmotes(false);
|
|
|
|
this->refreshBTTVChannelEmotes(false);
|
|
|
|
this->refreshSevenTVChannelEmotes(false);
|
|
|
|
this->joinBttvChannel();
|
|
|
|
this->listenSevenTVCosmetics();
|
2024-07-21 15:09:59 +02:00
|
|
|
getApp()->getTwitchLiveController()->add(
|
2023-09-16 13:52:51 +02:00
|
|
|
std::dynamic_pointer_cast<TwitchChannel>(shared_from_this()));
|
|
|
|
}
|
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
QString TwitchChannel::prepareMessage(const QString &message) const
|
|
|
|
{
|
2024-01-14 17:54:52 +01:00
|
|
|
auto *app = getApp();
|
2024-01-20 11:49:32 +01:00
|
|
|
QString parsedMessage =
|
|
|
|
app->getEmotes()->getEmojis()->replaceShortCodes(message);
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2021-10-30 14:49:41 +02:00
|
|
|
parsedMessage = parsedMessage.simplified();
|
2018-01-22 15:24:39 +01:00
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
if (parsedMessage.isEmpty())
|
|
|
|
{
|
2022-07-31 12:45:25 +02:00
|
|
|
return "";
|
2018-02-05 15:11:50 +01:00
|
|
|
}
|
2018-01-22 15:24:39 +01:00
|
|
|
|
2019-04-13 15:26:47 +02:00
|
|
|
if (!this->hasHighRateLimit())
|
2018-06-24 17:20:15 +02:00
|
|
|
{
|
2018-07-15 20:28:54 +02:00
|
|
|
if (getSettings()->allowDuplicateMessages)
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
if (parsedMessage == this->lastSentMessage_)
|
|
|
|
{
|
2021-08-01 14:38:07 +02:00
|
|
|
auto spaceIndex = parsedMessage.indexOf(' ');
|
2021-08-15 11:52:32 +02:00
|
|
|
// If the message starts with either '/' or '.' Twitch will treat it as a command, omitting
|
|
|
|
// first space and only rest of the arguments treated as actual message content
|
|
|
|
// In cases when user sends a message like ". .a b" first character and first space are omitted as well
|
|
|
|
bool ignoreFirstSpace =
|
|
|
|
parsedMessage.at(0) == '/' || parsedMessage.at(0) == '.';
|
|
|
|
if (ignoreFirstSpace)
|
|
|
|
{
|
|
|
|
spaceIndex = parsedMessage.indexOf(' ', spaceIndex + 1);
|
|
|
|
}
|
|
|
|
|
2021-08-01 14:38:07 +02:00
|
|
|
if (spaceIndex == -1)
|
|
|
|
{
|
|
|
|
// no spaces found, fall back to old magic character
|
|
|
|
parsedMessage.append(MAGIC_MESSAGE_SUFFIX);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// replace the space we found in spaceIndex with two spaces
|
|
|
|
parsedMessage.replace(spaceIndex, 1, " ");
|
|
|
|
}
|
2018-06-24 17:20:15 +02:00
|
|
|
}
|
2018-03-24 12:02:07 +01:00
|
|
|
}
|
2018-01-22 15:24:39 +01:00
|
|
|
}
|
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
return parsedMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::sendMessage(const QString &message)
|
|
|
|
{
|
2024-01-14 17:54:52 +01:00
|
|
|
auto *app = getApp();
|
2024-01-19 17:59:55 +01:00
|
|
|
if (!app->getAccounts()->twitch.isLoggedIn())
|
2022-07-31 12:45:25 +02:00
|
|
|
{
|
|
|
|
if (!message.isEmpty())
|
|
|
|
{
|
|
|
|
this->showLoginMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qCDebug(chatterinoTwitch)
|
|
|
|
<< "[TwitchChannel" << this->getName() << "] Send message:" << message;
|
|
|
|
|
|
|
|
// Do last message processing
|
|
|
|
QString parsedMessage = this->prepareMessage(message);
|
|
|
|
if (parsedMessage.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-06 18:57:22 +02:00
|
|
|
bool messageSent = false;
|
2018-08-02 14:23:27 +02:00
|
|
|
this->sendMessageSignal.invoke(this->getName(), parsedMessage, messageSent);
|
2023-07-29 11:49:44 +02:00
|
|
|
this->updateSevenTVActivity();
|
2018-02-11 21:13:23 +01:00
|
|
|
|
2018-06-06 18:57:22 +02:00
|
|
|
if (messageSent)
|
|
|
|
{
|
2020-11-21 16:20:10 +01:00
|
|
|
qCDebug(chatterinoTwitch) << "sent";
|
2018-07-06 19:23:47 +02:00
|
|
|
this->lastSentMessage_ = parsedMessage;
|
2018-06-06 18:57:22 +02:00
|
|
|
}
|
2017-09-16 00:05:06 +02:00
|
|
|
}
|
2017-11-04 14:57:29 +01:00
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
void TwitchChannel::sendReply(const QString &message, const QString &replyId)
|
|
|
|
{
|
2024-01-14 17:54:52 +01:00
|
|
|
auto *app = getApp();
|
2024-01-19 17:59:55 +01:00
|
|
|
if (!app->getAccounts()->twitch.isLoggedIn())
|
2022-07-31 12:45:25 +02:00
|
|
|
{
|
|
|
|
if (!message.isEmpty())
|
|
|
|
{
|
|
|
|
this->showLoginMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qCDebug(chatterinoTwitch) << "[TwitchChannel" << this->getName()
|
|
|
|
<< "] Send reply message:" << message;
|
|
|
|
|
|
|
|
// Do last message processing
|
|
|
|
QString parsedMessage = this->prepareMessage(message);
|
|
|
|
if (parsedMessage.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool messageSent = false;
|
|
|
|
this->sendReplySignal.invoke(this->getName(), parsedMessage, replyId,
|
|
|
|
messageSent);
|
|
|
|
|
|
|
|
if (messageSent)
|
|
|
|
{
|
|
|
|
qCDebug(chatterinoTwitch) << "sent";
|
|
|
|
this->lastSentMessage_ = parsedMessage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-18 18:17:48 +01:00
|
|
|
bool TwitchChannel::isMod() const
|
2018-01-17 17:17:26 +01:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->mod_;
|
2018-01-17 17:17:26 +01:00
|
|
|
}
|
|
|
|
|
2019-10-07 20:31:34 +02:00
|
|
|
bool TwitchChannel::isVip() const
|
2019-04-13 15:26:47 +02:00
|
|
|
{
|
|
|
|
return this->vip_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TwitchChannel::isStaff() const
|
|
|
|
{
|
|
|
|
return this->staff_;
|
|
|
|
}
|
|
|
|
|
2018-01-17 18:36:12 +01:00
|
|
|
void TwitchChannel::setMod(bool value)
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
if (this->mod_ != value)
|
|
|
|
{
|
|
|
|
this->mod_ = value;
|
2018-01-17 18:36:12 +01:00
|
|
|
|
2018-04-03 02:55:32 +02:00
|
|
|
this->userStateChanged.invoke();
|
2018-01-17 18:36:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-13 15:26:47 +02:00
|
|
|
void TwitchChannel::setVIP(bool value)
|
|
|
|
{
|
|
|
|
if (this->vip_ != value)
|
|
|
|
{
|
|
|
|
this->vip_ = value;
|
|
|
|
|
|
|
|
this->userStateChanged.invoke();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::setStaff(bool value)
|
|
|
|
{
|
|
|
|
if (this->staff_ != value)
|
|
|
|
{
|
|
|
|
this->staff_ = value;
|
|
|
|
|
|
|
|
this->userStateChanged.invoke();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-22 23:19:52 +02:00
|
|
|
bool TwitchChannel::isBroadcaster() const
|
2018-01-17 17:17:26 +01:00
|
|
|
{
|
2024-07-21 15:09:59 +02:00
|
|
|
auto *app = getApp();
|
2018-04-27 22:11:19 +02:00
|
|
|
|
2024-01-07 13:15:36 +01:00
|
|
|
return this->getName() ==
|
|
|
|
app->getAccounts()->twitch.getCurrent()->getUserName();
|
2018-01-17 17:17:26 +01:00
|
|
|
}
|
|
|
|
|
2019-04-13 15:26:47 +02:00
|
|
|
bool TwitchChannel::hasHighRateLimit() const
|
|
|
|
{
|
2019-10-07 20:31:34 +02:00
|
|
|
return this->isMod() || this->isBroadcaster() || this->isVip();
|
2019-04-13 15:26:47 +02:00
|
|
|
}
|
|
|
|
|
2019-09-18 08:05:51 +02:00
|
|
|
bool TwitchChannel::canReconnect() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::reconnect()
|
|
|
|
{
|
2024-07-21 15:09:59 +02:00
|
|
|
getApp()->getTwitchAbstract()->connect();
|
2019-09-18 08:05:51 +02:00
|
|
|
}
|
|
|
|
|
2024-07-14 11:45:21 +02:00
|
|
|
QString TwitchChannel::getCurrentStreamID() const
|
|
|
|
{
|
|
|
|
auto streamStatus = this->accessStreamStatus();
|
|
|
|
if (streamStatus->live)
|
|
|
|
{
|
|
|
|
return streamStatus->streamId;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2018-08-11 17:15:17 +02:00
|
|
|
QString TwitchChannel::roomId() const
|
2018-07-14 14:24:18 +02:00
|
|
|
{
|
2018-08-10 19:00:14 +02:00
|
|
|
return *this->roomID_.access();
|
2018-07-14 14:24:18 +02:00
|
|
|
}
|
|
|
|
|
2018-07-15 20:28:54 +02:00
|
|
|
void TwitchChannel::setRoomId(const QString &id)
|
2018-07-14 14:24:18 +02:00
|
|
|
{
|
2018-09-29 21:53:54 +02:00
|
|
|
if (*this->roomID_.accessConst() != id)
|
|
|
|
{
|
|
|
|
*this->roomID_.access() = id;
|
2024-01-07 13:15:36 +01:00
|
|
|
// This is intended for tests and benchmarks. See comment in constructor.
|
2024-07-21 15:09:59 +02:00
|
|
|
if (!getApp()->isTest())
|
2024-01-07 13:15:36 +01:00
|
|
|
{
|
|
|
|
this->roomIdChanged();
|
|
|
|
this->loadRecentMessages();
|
|
|
|
}
|
2023-12-16 13:38:35 +01:00
|
|
|
this->disconnected_ = false;
|
|
|
|
this->lastConnectedAt_ = std::chrono::system_clock::now();
|
2018-09-29 21:53:54 +02:00
|
|
|
}
|
2018-07-14 14:24:18 +02:00
|
|
|
}
|
|
|
|
|
2021-05-01 17:19:41 +02:00
|
|
|
SharedAccessGuard<const TwitchChannel::RoomModes>
|
|
|
|
TwitchChannel::accessRoomModes() const
|
2018-05-24 08:58:34 +02:00
|
|
|
{
|
2024-01-17 21:05:44 +01:00
|
|
|
return this->roomModes.accessConst();
|
2018-05-24 08:58:34 +02:00
|
|
|
}
|
|
|
|
|
2024-01-17 21:05:44 +01:00
|
|
|
void TwitchChannel::setRoomModes(const RoomModes &newRoomModes)
|
2018-05-24 08:58:34 +02:00
|
|
|
{
|
2024-01-17 21:05:44 +01:00
|
|
|
this->roomModes = newRoomModes;
|
2018-05-24 08:58:34 +02:00
|
|
|
|
|
|
|
this->roomModesChanged.invoke();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TwitchChannel::isLive() const
|
|
|
|
{
|
2023-04-10 12:08:15 +02:00
|
|
|
return this->streamStatus_.accessConst()->live;
|
2018-07-15 20:28:54 +02:00
|
|
|
}
|
|
|
|
|
2024-02-18 17:22:53 +01:00
|
|
|
bool TwitchChannel::isRerun() const
|
|
|
|
{
|
|
|
|
return this->streamStatus_.accessConst()->rerun;
|
|
|
|
}
|
|
|
|
|
2021-05-01 17:19:41 +02:00
|
|
|
SharedAccessGuard<const TwitchChannel::StreamStatus>
|
2018-08-15 22:46:20 +02:00
|
|
|
TwitchChannel::accessStreamStatus() const
|
2018-07-15 20:28:54 +02:00
|
|
|
{
|
2018-08-06 18:25:47 +02:00
|
|
|
return this->streamStatus_.accessConst();
|
2018-07-15 20:28:54 +02:00
|
|
|
}
|
|
|
|
|
2023-10-08 18:50:48 +02:00
|
|
|
std::optional<EmotePtr> TwitchChannel::bttvEmote(const EmoteName &name) const
|
2018-08-02 14:23:27 +02:00
|
|
|
{
|
2018-08-11 17:15:17 +02:00
|
|
|
auto emotes = this->bttvEmotes_.get();
|
2018-08-02 14:23:27 +02:00
|
|
|
auto it = emotes->find(name);
|
|
|
|
|
|
|
|
if (it == emotes->end())
|
2024-01-14 17:54:52 +01:00
|
|
|
{
|
2023-10-08 18:50:48 +02:00
|
|
|
return std::nullopt;
|
2024-01-14 17:54:52 +01:00
|
|
|
}
|
2018-08-02 14:23:27 +02:00
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
2023-10-08 18:50:48 +02:00
|
|
|
std::optional<EmotePtr> TwitchChannel::ffzEmote(const EmoteName &name) const
|
2018-07-15 20:28:54 +02:00
|
|
|
{
|
2018-08-13 13:54:39 +02:00
|
|
|
auto emotes = this->ffzEmotes_.get();
|
2018-08-02 14:23:27 +02:00
|
|
|
auto it = emotes->find(name);
|
|
|
|
|
|
|
|
if (it == emotes->end())
|
2024-01-14 17:54:52 +01:00
|
|
|
{
|
2023-10-08 18:50:48 +02:00
|
|
|
return std::nullopt;
|
2024-01-14 17:54:52 +01:00
|
|
|
}
|
2018-08-02 14:23:27 +02:00
|
|
|
return it->second;
|
2018-07-15 20:28:54 +02:00
|
|
|
}
|
|
|
|
|
2023-10-08 18:50:48 +02:00
|
|
|
std::optional<EmotePtr> TwitchChannel::seventvEmote(const EmoteName &name) const
|
2022-10-16 13:22:17 +02:00
|
|
|
{
|
|
|
|
auto emotes = this->seventvEmotes_.get();
|
|
|
|
auto it = emotes->find(name);
|
|
|
|
|
|
|
|
if (it == emotes->end())
|
|
|
|
{
|
2023-10-08 18:50:48 +02:00
|
|
|
return std::nullopt;
|
2022-10-16 13:22:17 +02:00
|
|
|
}
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
2018-08-11 17:15:17 +02:00
|
|
|
std::shared_ptr<const EmoteMap> TwitchChannel::bttvEmotes() const
|
2018-07-15 20:28:54 +02:00
|
|
|
{
|
2018-08-11 17:15:17 +02:00
|
|
|
return this->bttvEmotes_.get();
|
2018-05-24 08:58:34 +02:00
|
|
|
}
|
|
|
|
|
2018-08-11 17:15:17 +02:00
|
|
|
std::shared_ptr<const EmoteMap> TwitchChannel::ffzEmotes() const
|
2018-05-24 08:58:34 +02:00
|
|
|
{
|
2018-08-11 17:15:17 +02:00
|
|
|
return this->ffzEmotes_.get();
|
2018-07-15 20:28:54 +02:00
|
|
|
}
|
|
|
|
|
2022-10-16 13:22:17 +02:00
|
|
|
std::shared_ptr<const EmoteMap> TwitchChannel::seventvEmotes() const
|
|
|
|
{
|
|
|
|
return this->seventvEmotes_.get();
|
|
|
|
}
|
|
|
|
|
2022-11-13 12:07:41 +01:00
|
|
|
const QString &TwitchChannel::seventvUserID() const
|
|
|
|
{
|
|
|
|
return this->seventvUserID_;
|
|
|
|
}
|
|
|
|
const QString &TwitchChannel::seventvEmoteSetID() const
|
|
|
|
{
|
|
|
|
return this->seventvEmoteSetID_;
|
|
|
|
}
|
|
|
|
|
2023-01-21 15:06:55 +01:00
|
|
|
void TwitchChannel::joinBttvChannel() const
|
|
|
|
{
|
2024-07-21 15:09:59 +02:00
|
|
|
if (getApp()->getTwitch()->getBTTVLiveUpdates())
|
2023-01-21 15:06:55 +01:00
|
|
|
{
|
2024-01-19 17:59:55 +01:00
|
|
|
const auto currentAccount =
|
2024-07-21 15:09:59 +02:00
|
|
|
getApp()->getAccounts()->twitch.getCurrent();
|
2023-01-21 15:06:55 +01:00
|
|
|
QString userName;
|
|
|
|
if (currentAccount && !currentAccount->isAnon())
|
|
|
|
{
|
|
|
|
userName = currentAccount->getUserName();
|
|
|
|
}
|
2024-07-21 15:09:59 +02:00
|
|
|
getApp()->getTwitch()->getBTTVLiveUpdates()->joinChannel(this->roomId(),
|
|
|
|
userName);
|
2023-01-21 15:06:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2024-07-13 13:15:11 +02:00
|
|
|
this->addMessage(builder.release(), MessageContext::Original);
|
2023-01-21 15:06:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::removeBttvEmote(
|
|
|
|
const BttvLiveUpdateEmoteRemoveMessage &message)
|
|
|
|
{
|
|
|
|
auto removed = BttvEmotes::removeEmote(this->bttvEmotes_, message);
|
|
|
|
if (!removed)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->addOrReplaceLiveUpdatesAddRemove(false, "BTTV", QString() /*actor*/,
|
2023-10-08 18:50:48 +02:00
|
|
|
(*removed)->name.string);
|
2023-01-21 15:06:55 +01:00
|
|
|
}
|
|
|
|
|
2022-11-13 12:07:41 +01:00
|
|
|
void TwitchChannel::addSeventvEmote(
|
2023-02-04 13:42:52 +01:00
|
|
|
const seventv::eventapi::EmoteAddDispatch &dispatch)
|
2022-11-13 12:07:41 +01:00
|
|
|
{
|
|
|
|
if (!SeventvEmotes::addEmote(this->seventvEmotes_, dispatch))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->addOrReplaceLiveUpdatesAddRemove(
|
|
|
|
true, "7TV", dispatch.actorName, dispatch.emoteJson["name"].toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::updateSeventvEmote(
|
2023-02-04 13:42:52 +01:00
|
|
|
const seventv::eventapi::EmoteUpdateDispatch &dispatch)
|
2022-11-13 12:07:41 +01:00
|
|
|
{
|
|
|
|
if (!SeventvEmotes::updateEmote(this->seventvEmotes_, dispatch))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto builder =
|
|
|
|
MessageBuilder(liveUpdatesUpdateEmoteMessage, "7TV", dispatch.actorName,
|
|
|
|
dispatch.emoteName, dispatch.oldEmoteName);
|
2024-07-13 13:15:11 +02:00
|
|
|
this->addMessage(builder.release(), MessageContext::Original);
|
2022-11-13 12:07:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::removeSeventvEmote(
|
2023-02-04 13:42:52 +01:00
|
|
|
const seventv::eventapi::EmoteRemoveDispatch &dispatch)
|
2022-11-13 12:07:41 +01:00
|
|
|
{
|
|
|
|
auto removed = SeventvEmotes::removeEmote(this->seventvEmotes_, dispatch);
|
|
|
|
if (!removed)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->addOrReplaceLiveUpdatesAddRemove(false, "7TV", dispatch.actorName,
|
2023-10-08 18:50:48 +02:00
|
|
|
(*removed)->name.string);
|
2022-11-13 12:07:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::updateSeventvUser(
|
2023-02-04 13:42:52 +01:00
|
|
|
const seventv::eventapi::UserConnectionUpdateDispatch &dispatch)
|
2022-11-13 12:07:41 +01:00
|
|
|
{
|
|
|
|
if (dispatch.connectionIndex != this->seventvUserTwitchConnectionIndex_)
|
|
|
|
{
|
|
|
|
// A different connection was updated
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSeventvData(this->seventvUserID_, dispatch.emoteSetID);
|
|
|
|
SeventvEmotes::getEmoteSet(
|
|
|
|
dispatch.emoteSetID,
|
|
|
|
[this, weak = weakOf<Channel>(this), dispatch](auto &&emotes,
|
|
|
|
const auto &name) {
|
|
|
|
postToThread([this, weak, dispatch, emotes, name]() {
|
|
|
|
if (auto shared = weak.lock())
|
|
|
|
{
|
|
|
|
this->seventvEmotes_.set(
|
|
|
|
std::make_shared<EmoteMap>(emotes));
|
|
|
|
auto builder =
|
|
|
|
MessageBuilder(liveUpdatesUpdateEmoteSetMessage, "7TV",
|
|
|
|
dispatch.actorName, name);
|
2024-07-13 13:15:11 +02:00
|
|
|
this->addMessage(builder.release(),
|
|
|
|
MessageContext::Original);
|
2022-11-13 12:07:41 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
[this, weak = weakOf<Channel>(this)](const auto &reason) {
|
|
|
|
postToThread([this, weak, reason]() {
|
|
|
|
if (auto shared = weak.lock())
|
|
|
|
{
|
|
|
|
this->seventvEmotes_.set(EMPTY_EMOTE_MAP);
|
2024-07-07 22:03:05 +02:00
|
|
|
this->addSystemMessage(
|
2022-11-13 12:07:41 +01:00
|
|
|
QString("Failed updating 7TV emote set (%1).")
|
2024-07-07 22:03:05 +02:00
|
|
|
.arg(reason));
|
2022-11-13 12:07:41 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::updateSeventvData(const QString &newUserID,
|
|
|
|
const QString &newEmoteSetID)
|
|
|
|
{
|
|
|
|
if (this->seventvUserID_ == newUserID &&
|
|
|
|
this->seventvEmoteSetID_ == newEmoteSetID)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-08 18:50:48 +02:00
|
|
|
const auto oldUserID = makeConditionedOptional(
|
2022-11-13 12:07:41 +01:00
|
|
|
!this->seventvUserID_.isEmpty() && this->seventvUserID_ != newUserID,
|
|
|
|
this->seventvUserID_);
|
2023-10-08 18:50:48 +02:00
|
|
|
const auto oldEmoteSetID =
|
|
|
|
makeConditionedOptional(!this->seventvEmoteSetID_.isEmpty() &&
|
|
|
|
this->seventvEmoteSetID_ != newEmoteSetID,
|
|
|
|
this->seventvEmoteSetID_);
|
2022-11-13 12:07:41 +01:00
|
|
|
|
|
|
|
this->seventvUserID_ = newUserID;
|
|
|
|
this->seventvEmoteSetID_ = newEmoteSetID;
|
|
|
|
runInGuiThread([this, oldUserID, oldEmoteSetID]() {
|
2024-07-21 15:09:59 +02:00
|
|
|
if (getApp()->getTwitch()->getSeventvEventAPI())
|
2022-11-13 12:07:41 +01:00
|
|
|
{
|
2024-07-21 15:09:59 +02:00
|
|
|
getApp()->getTwitch()->getSeventvEventAPI()->subscribeUser(
|
2022-11-13 12:07:41 +01:00
|
|
|
this->seventvUserID_, this->seventvEmoteSetID_);
|
|
|
|
|
|
|
|
if (oldUserID || oldEmoteSetID)
|
|
|
|
{
|
2024-07-21 15:09:59 +02:00
|
|
|
getApp()->getTwitch()->dropSeventvChannel(
|
2023-10-08 18:50:48 +02:00
|
|
|
oldUserID.value_or(QString()),
|
|
|
|
oldEmoteSetID.value_or(QString()));
|
2022-11-13 12:07:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::addOrReplaceLiveUpdatesAddRemove(bool isEmoteAdd,
|
|
|
|
const QString &platform,
|
|
|
|
const QString &actor,
|
|
|
|
const QString &emoteName)
|
|
|
|
{
|
|
|
|
if (this->tryReplaceLastLiveUpdateAddOrRemove(
|
|
|
|
isEmoteAdd ? MessageFlag::LiveUpdatesAdd
|
|
|
|
: MessageFlag::LiveUpdatesRemove,
|
|
|
|
platform, actor, emoteName))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->lastLiveUpdateEmoteNames_ = {emoteName};
|
|
|
|
|
|
|
|
MessagePtr msg;
|
|
|
|
if (isEmoteAdd)
|
|
|
|
{
|
|
|
|
msg = MessageBuilder(liveUpdatesAddEmoteMessage, platform, actor,
|
|
|
|
this->lastLiveUpdateEmoteNames_)
|
|
|
|
.release();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg = MessageBuilder(liveUpdatesRemoveEmoteMessage, platform, actor,
|
|
|
|
this->lastLiveUpdateEmoteNames_)
|
|
|
|
.release();
|
|
|
|
}
|
|
|
|
this->lastLiveUpdateEmotePlatform_ = platform;
|
|
|
|
this->lastLiveUpdateMessage_ = msg;
|
|
|
|
this->lastLiveUpdateEmoteActor_ = actor;
|
2024-07-13 13:15:11 +02:00
|
|
|
this->addMessage(msg, MessageContext::Original);
|
2022-11-13 12:07:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TwitchChannel::tryReplaceLastLiveUpdateAddOrRemove(
|
|
|
|
MessageFlag op, const QString &platform, const QString &actor,
|
|
|
|
const QString &emoteName)
|
|
|
|
{
|
|
|
|
if (this->lastLiveUpdateEmotePlatform_ != platform)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto last = this->lastLiveUpdateMessage_.lock();
|
|
|
|
if (!last || !last->flags.has(op) ||
|
|
|
|
last->parseTime < QTime::currentTime().addSecs(-5) ||
|
|
|
|
last->loginName != actor)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Update the message
|
|
|
|
this->lastLiveUpdateEmoteNames_.push_back(emoteName);
|
|
|
|
|
|
|
|
MessageBuilder replacement;
|
|
|
|
if (op == MessageFlag::LiveUpdatesAdd)
|
|
|
|
{
|
|
|
|
replacement =
|
|
|
|
MessageBuilder(liveUpdatesAddEmoteMessage, platform,
|
|
|
|
last->loginName, this->lastLiveUpdateEmoteNames_);
|
|
|
|
}
|
|
|
|
else // op == RemoveEmoteMessage
|
|
|
|
{
|
|
|
|
replacement =
|
|
|
|
MessageBuilder(liveUpdatesRemoveEmoteMessage, platform,
|
|
|
|
last->loginName, this->lastLiveUpdateEmoteNames_);
|
|
|
|
}
|
|
|
|
|
|
|
|
replacement->flags = last->flags;
|
|
|
|
|
|
|
|
auto msg = replacement.release();
|
|
|
|
this->lastLiveUpdateMessage_ = msg;
|
|
|
|
this->replaceMessage(last, msg);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-09-16 13:52:51 +02:00
|
|
|
void TwitchChannel::messageRemovedFromStart(const MessagePtr &msg)
|
|
|
|
{
|
|
|
|
if (msg->replyThread)
|
|
|
|
{
|
|
|
|
if (msg->replyThread->liveCount(msg) == 0)
|
|
|
|
{
|
|
|
|
this->threads_.erase(msg->replyThread->rootId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-11 17:15:17 +02:00
|
|
|
const QString &TwitchChannel::subscriptionUrl()
|
2018-07-15 20:28:54 +02:00
|
|
|
{
|
|
|
|
return this->subscriptionUrl_;
|
|
|
|
}
|
|
|
|
|
2018-08-11 17:15:17 +02:00
|
|
|
const QString &TwitchChannel::channelUrl()
|
2018-07-15 20:28:54 +02:00
|
|
|
{
|
|
|
|
return this->channelUrl_;
|
|
|
|
}
|
|
|
|
|
2018-08-11 17:15:17 +02:00
|
|
|
const QString &TwitchChannel::popoutPlayerUrl()
|
2018-07-15 20:28:54 +02:00
|
|
|
{
|
|
|
|
return this->popoutPlayerUrl_;
|
2018-05-24 08:58:34 +02:00
|
|
|
}
|
|
|
|
|
2024-01-17 21:05:44 +01:00
|
|
|
int TwitchChannel::chatterCount() const
|
2021-01-16 13:58:11 +01:00
|
|
|
{
|
|
|
|
return this->chatterCount_;
|
|
|
|
}
|
|
|
|
|
2023-07-02 15:52:15 +02:00
|
|
|
bool TwitchChannel::setLive(bool newLiveStatus)
|
2017-11-04 14:57:29 +01:00
|
|
|
{
|
2023-07-02 15:52:15 +02:00
|
|
|
auto guard = this->streamStatus_.access();
|
|
|
|
if (guard->live == newLiveStatus)
|
2018-03-30 15:05:33 +02:00
|
|
|
{
|
2023-07-02 15:52:15 +02:00
|
|
|
return false;
|
2020-03-14 12:13:57 +01:00
|
|
|
}
|
2023-07-02 15:52:15 +02:00
|
|
|
guard->live = newLiveStatus;
|
2024-03-09 11:22:23 +01:00
|
|
|
if (!newLiveStatus)
|
|
|
|
{
|
|
|
|
// A rerun is just a fancy livestream
|
|
|
|
guard->rerun = false;
|
|
|
|
}
|
2018-04-08 15:14:14 +02:00
|
|
|
|
2023-07-02 15:52:15 +02:00
|
|
|
return true;
|
2017-09-16 00:05:06 +02:00
|
|
|
}
|
2017-11-04 14:57:29 +01:00
|
|
|
|
2023-12-16 13:38:35 +01:00
|
|
|
void TwitchChannel::markConnected()
|
2023-12-09 19:46:30 +01:00
|
|
|
{
|
2023-12-16 13:38:35 +01:00
|
|
|
if (this->lastConnectedAt_.has_value() && !this->disconnected_)
|
2023-12-09 19:46:30 +01:00
|
|
|
{
|
2023-12-16 13:38:35 +01:00
|
|
|
this->lastConnectedAt_ = std::chrono::system_clock::now();
|
2023-12-09 19:46:30 +01:00
|
|
|
}
|
2023-12-16 13:38:35 +01:00
|
|
|
}
|
2023-12-09 19:46:30 +01:00
|
|
|
|
2023-12-16 13:38:35 +01:00
|
|
|
void TwitchChannel::markDisconnected()
|
|
|
|
{
|
|
|
|
if (this->roomId().isEmpty())
|
2023-12-09 19:46:30 +01:00
|
|
|
{
|
2023-12-16 13:38:35 +01:00
|
|
|
// we were never joined in the first place
|
2023-12-09 19:46:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-12-16 13:38:35 +01:00
|
|
|
this->disconnected_ = true;
|
2023-12-09 19:46:30 +01:00
|
|
|
}
|
|
|
|
|
2018-07-14 14:24:18 +02:00
|
|
|
void TwitchChannel::loadRecentMessages()
|
2017-12-28 00:03:52 +01:00
|
|
|
{
|
2019-05-25 11:24:10 +02:00
|
|
|
if (!getSettings()->loadTwitchMessageHistoryOnConnect)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-06 18:18:34 +02:00
|
|
|
if (this->loadingRecentMessages_.test_and_set())
|
2021-07-18 15:21:09 +02:00
|
|
|
{
|
2022-08-06 18:18:34 +02:00
|
|
|
return; // already loading
|
2021-07-18 15:21:09 +02:00
|
|
|
}
|
2020-12-06 13:04:49 +01:00
|
|
|
|
2021-07-18 14:15:38 +02:00
|
|
|
auto weak = weakOf<Channel>(this);
|
2023-08-12 13:34:59 +02:00
|
|
|
recentmessages::load(
|
2022-08-06 18:18:34 +02:00
|
|
|
this->getName(), weak,
|
|
|
|
[weak](const auto &messages) {
|
2019-08-20 21:50:36 +02:00
|
|
|
auto shared = weak.lock();
|
|
|
|
if (!shared)
|
2024-01-14 17:54:52 +01:00
|
|
|
{
|
2022-08-06 18:18:34 +02:00
|
|
|
return;
|
2024-01-14 17:54:52 +01:00
|
|
|
}
|
2018-07-14 14:24:18 +02:00
|
|
|
|
2024-01-14 17:54:52 +01:00
|
|
|
auto *tc = dynamic_cast<TwitchChannel *>(shared.get());
|
2022-08-06 18:18:34 +02:00
|
|
|
if (!tc)
|
2024-01-14 17:54:52 +01:00
|
|
|
{
|
2022-08-06 18:18:34 +02:00
|
|
|
return;
|
2024-01-14 17:54:52 +01:00
|
|
|
}
|
2018-10-13 14:45:51 +02:00
|
|
|
|
2022-08-06 18:18:34 +02:00
|
|
|
tc->addMessagesAtStart(messages);
|
|
|
|
tc->loadingRecentMessages_.clear();
|
2023-08-05 16:23:40 +02:00
|
|
|
|
|
|
|
std::vector<MessagePtr> msgs;
|
2024-01-17 21:05:44 +01:00
|
|
|
for (const auto &msg : messages)
|
2023-08-05 16:23:40 +02:00
|
|
|
{
|
|
|
|
const auto highlighted =
|
|
|
|
msg->flags.has(MessageFlag::Highlighted);
|
|
|
|
const auto showInMentions =
|
|
|
|
msg->flags.has(MessageFlag::ShowInMentions);
|
|
|
|
if (highlighted && showInMentions)
|
|
|
|
{
|
|
|
|
msgs.push_back(msg);
|
|
|
|
}
|
2024-01-21 11:57:14 +01:00
|
|
|
|
|
|
|
tc->addRecentChatter(msg->displayName);
|
2023-08-05 16:23:40 +02:00
|
|
|
}
|
|
|
|
|
2024-07-21 15:09:59 +02:00
|
|
|
getApp()->getTwitch()->getMentionsChannel()->fillInMissingMessages(
|
2024-06-01 14:56:40 +02:00
|
|
|
msgs);
|
2022-08-06 18:18:34 +02:00
|
|
|
},
|
|
|
|
[weak]() {
|
|
|
|
auto shared = weak.lock();
|
|
|
|
if (!shared)
|
2024-01-14 17:54:52 +01:00
|
|
|
{
|
2022-08-06 18:18:34 +02:00
|
|
|
return;
|
2024-01-14 17:54:52 +01:00
|
|
|
}
|
2019-04-13 19:14:58 +02:00
|
|
|
|
2024-01-14 17:54:52 +01:00
|
|
|
auto *tc = dynamic_cast<TwitchChannel *>(shared.get());
|
2022-08-06 18:18:34 +02:00
|
|
|
if (!tc)
|
2024-01-14 17:54:52 +01:00
|
|
|
{
|
2022-08-06 18:18:34 +02:00
|
|
|
return;
|
2024-01-14 17:54:52 +01:00
|
|
|
}
|
2019-04-13 19:14:58 +02:00
|
|
|
|
2022-08-06 18:18:34 +02:00
|
|
|
tc->loadingRecentMessages_.clear();
|
2023-12-09 19:46:30 +01:00
|
|
|
},
|
|
|
|
getSettings()->twitchMessageHistoryLimit.getValue(), std::nullopt,
|
|
|
|
std::nullopt, false);
|
2022-08-06 18:18:34 +02:00
|
|
|
}
|
2021-05-09 18:44:57 +02:00
|
|
|
|
2022-08-06 18:18:34 +02:00
|
|
|
void TwitchChannel::loadRecentMessagesReconnect()
|
|
|
|
{
|
|
|
|
if (!getSettings()->loadTwitchMessageHistoryOnConnect)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2022-07-31 12:45:25 +02:00
|
|
|
|
2022-08-06 18:18:34 +02:00
|
|
|
if (this->loadingRecentMessages_.test_and_set())
|
|
|
|
{
|
|
|
|
return; // already loading
|
|
|
|
}
|
2019-04-13 19:14:58 +02:00
|
|
|
|
2023-12-09 19:46:30 +01:00
|
|
|
const auto now = std::chrono::system_clock::now();
|
|
|
|
int limit = getSettings()->twitchMessageHistoryLimit.getValue();
|
2023-12-16 13:38:35 +01:00
|
|
|
if (this->lastConnectedAt_.has_value())
|
2023-12-09 19:46:30 +01:00
|
|
|
{
|
|
|
|
// calculate how many messages could have occured
|
|
|
|
// while we were not connected to the channel
|
|
|
|
// assuming a maximum of 10 messages per second
|
|
|
|
const auto secondsSinceDisconnect =
|
|
|
|
std::chrono::duration_cast<std::chrono::seconds>(
|
2023-12-16 13:38:35 +01:00
|
|
|
now - this->lastConnectedAt_.value())
|
2023-12-09 19:46:30 +01:00
|
|
|
.count();
|
|
|
|
limit =
|
|
|
|
std::min(static_cast<int>(secondsSinceDisconnect + 1) * 10, limit);
|
|
|
|
}
|
|
|
|
|
2022-08-06 18:18:34 +02:00
|
|
|
auto weak = weakOf<Channel>(this);
|
2023-08-12 13:34:59 +02:00
|
|
|
recentmessages::load(
|
2022-08-06 18:18:34 +02:00
|
|
|
this->getName(), weak,
|
|
|
|
[weak](const auto &messages) {
|
|
|
|
auto shared = weak.lock();
|
|
|
|
if (!shared)
|
2024-01-14 17:54:52 +01:00
|
|
|
{
|
2022-08-06 18:18:34 +02:00
|
|
|
return;
|
2024-01-14 17:54:52 +01:00
|
|
|
}
|
2021-07-18 14:15:38 +02:00
|
|
|
|
2024-01-14 17:54:52 +01:00
|
|
|
auto *tc = dynamic_cast<TwitchChannel *>(shared.get());
|
2022-08-06 18:18:34 +02:00
|
|
|
if (!tc)
|
2024-01-14 17:54:52 +01:00
|
|
|
{
|
2022-08-06 18:18:34 +02:00
|
|
|
return;
|
2024-01-14 17:54:52 +01:00
|
|
|
}
|
2018-07-14 14:24:18 +02:00
|
|
|
|
2022-08-06 18:18:34 +02:00
|
|
|
tc->fillInMissingMessages(messages);
|
|
|
|
tc->loadingRecentMessages_.clear();
|
|
|
|
},
|
|
|
|
[weak]() {
|
2021-07-18 14:15:38 +02:00
|
|
|
auto shared = weak.lock();
|
|
|
|
if (!shared)
|
2024-01-14 17:54:52 +01:00
|
|
|
{
|
2021-07-18 14:15:38 +02:00
|
|
|
return;
|
2024-01-14 17:54:52 +01:00
|
|
|
}
|
2021-07-18 14:15:38 +02:00
|
|
|
|
2024-01-14 17:54:52 +01:00
|
|
|
auto *tc = dynamic_cast<TwitchChannel *>(shared.get());
|
2022-08-06 18:18:34 +02:00
|
|
|
if (!tc)
|
2024-01-14 17:54:52 +01:00
|
|
|
{
|
2022-08-06 18:18:34 +02:00
|
|
|
return;
|
2024-01-14 17:54:52 +01:00
|
|
|
}
|
2022-08-06 18:18:34 +02:00
|
|
|
|
|
|
|
tc->loadingRecentMessages_.clear();
|
2023-12-09 19:46:30 +01:00
|
|
|
},
|
2023-12-16 13:38:35 +01:00
|
|
|
limit, this->lastConnectedAt_, now, true);
|
2018-07-14 14:24:18 +02:00
|
|
|
}
|
2018-01-01 22:29:21 +01:00
|
|
|
|
2022-05-07 17:22:39 +02:00
|
|
|
void TwitchChannel::refreshPubSub()
|
2018-07-14 14:24:18 +02:00
|
|
|
{
|
2024-07-21 15:09:59 +02:00
|
|
|
if (getApp()->isTest())
|
2024-06-16 12:22:51 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-11 17:15:17 +02:00
|
|
|
auto roomId = this->roomId();
|
2018-07-14 14:24:18 +02:00
|
|
|
if (roomId.isEmpty())
|
2022-05-07 17:22:39 +02:00
|
|
|
{
|
2018-07-14 14:24:18 +02:00
|
|
|
return;
|
2022-05-07 17:22:39 +02:00
|
|
|
}
|
|
|
|
|
2024-07-21 15:09:59 +02:00
|
|
|
auto currentAccount = getApp()->getAccounts()->twitch.getCurrent();
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2024-07-21 15:09:59 +02:00
|
|
|
getApp()->getTwitchPubSub()->setAccount(currentAccount);
|
2018-07-14 14:24:18 +02:00
|
|
|
|
2024-07-21 15:09:59 +02:00
|
|
|
getApp()->getTwitchPubSub()->listenToChannelModerationActions(roomId);
|
2023-12-31 11:44:55 +01:00
|
|
|
if (this->hasModRights())
|
|
|
|
{
|
2024-07-21 15:09:59 +02:00
|
|
|
getApp()->getTwitchPubSub()->listenToAutomod(roomId);
|
|
|
|
getApp()->getTwitchPubSub()->listenToLowTrustUsers(roomId);
|
2023-12-31 11:44:55 +01:00
|
|
|
}
|
2024-07-21 15:09:59 +02:00
|
|
|
getApp()->getTwitchPubSub()->listenToChannelPointRewards(roomId);
|
2018-07-14 14:24:18 +02:00
|
|
|
}
|
|
|
|
|
2018-08-13 13:54:39 +02:00
|
|
|
void TwitchChannel::refreshChatters()
|
2018-07-14 14:24:18 +02:00
|
|
|
{
|
2022-11-01 23:18:57 +01:00
|
|
|
// helix endpoint only works for mods
|
|
|
|
if (!this->hasModRights())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-14 14:24:18 +02:00
|
|
|
// setting?
|
2018-07-15 20:28:54 +02:00
|
|
|
const auto streamStatus = this->accessStreamStatus();
|
2019-05-08 08:51:14 +02:00
|
|
|
const auto viewerCount = static_cast<int>(streamStatus->viewerCount);
|
2018-07-14 14:24:18 +02:00
|
|
|
if (getSettings()->onlyFetchChattersForSmallerStreamers)
|
|
|
|
{
|
2018-07-15 20:28:54 +02:00
|
|
|
if (streamStatus->live &&
|
2019-05-08 08:51:14 +02:00
|
|
|
viewerCount > getSettings()->smallStreamerLimit)
|
2018-07-15 20:28:54 +02:00
|
|
|
{
|
2018-07-14 14:24:18 +02:00
|
|
|
return;
|
2018-01-01 22:29:21 +01:00
|
|
|
}
|
2018-07-14 14:24:18 +02:00
|
|
|
}
|
2018-07-07 13:08:57 +02:00
|
|
|
|
2022-11-01 23:18:57 +01:00
|
|
|
// Get chatter list via helix api
|
|
|
|
getHelix()->getChatters(
|
2024-01-19 17:59:55 +01:00
|
|
|
this->roomId(),
|
2024-07-21 15:09:59 +02:00
|
|
|
getApp()->getAccounts()->twitch.getCurrent()->getUserId(),
|
2022-11-01 23:18:57 +01:00
|
|
|
MAX_CHATTERS_TO_FETCH,
|
|
|
|
[this, weak = weakOf<Channel>(this)](auto result) {
|
|
|
|
if (auto shared = weak.lock())
|
|
|
|
{
|
|
|
|
this->updateOnlineChatters(result.chatters);
|
|
|
|
this->chatterCount_ = result.total;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// Refresh chatters should only be used when failing silently is an option
|
2024-01-17 21:05:44 +01:00
|
|
|
[](auto error, auto message) {
|
|
|
|
(void)error;
|
|
|
|
(void)message;
|
|
|
|
});
|
2017-12-28 00:03:52 +01:00
|
|
|
}
|
2018-02-05 21:20:38 +01:00
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
void TwitchChannel::addReplyThread(const std::shared_ptr<MessageThread> &thread)
|
|
|
|
{
|
|
|
|
this->threads_[thread->rootId()] = thread;
|
|
|
|
}
|
|
|
|
|
2023-10-31 18:24:47 +01:00
|
|
|
const std::unordered_map<QString, std::weak_ptr<MessageThread>> &
|
|
|
|
TwitchChannel::threads() const
|
2022-07-31 12:45:25 +02:00
|
|
|
{
|
|
|
|
return this->threads_;
|
|
|
|
}
|
|
|
|
|
2023-10-31 14:54:14 +01:00
|
|
|
std::shared_ptr<MessageThread> TwitchChannel::getOrCreateThread(
|
|
|
|
const MessagePtr &message)
|
|
|
|
{
|
|
|
|
assert(message != nullptr);
|
|
|
|
|
|
|
|
auto threadIt = this->threads_.find(message->id);
|
|
|
|
if (threadIt != this->threads_.end() && !threadIt->second.expired())
|
|
|
|
{
|
|
|
|
return threadIt->second.lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto thread = std::make_shared<MessageThread>(message);
|
|
|
|
this->addReplyThread(thread);
|
|
|
|
return thread;
|
|
|
|
}
|
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
void TwitchChannel::cleanUpReplyThreads()
|
|
|
|
{
|
|
|
|
for (auto it = this->threads_.begin(), last = this->threads_.end();
|
|
|
|
it != last;)
|
|
|
|
{
|
|
|
|
bool doErase = true;
|
|
|
|
if (auto thread = it->second.lock())
|
|
|
|
{
|
|
|
|
doErase = thread->liveCount() == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doErase)
|
|
|
|
{
|
|
|
|
it = this->threads_.erase(it);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:54:39 +02:00
|
|
|
void TwitchChannel::refreshBadges()
|
2018-08-02 14:23:27 +02:00
|
|
|
{
|
2023-04-16 11:58:45 +02:00
|
|
|
if (this->roomId().isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2019-08-20 23:30:39 +02:00
|
|
|
|
2023-04-16 11:58:45 +02:00
|
|
|
getHelix()->getChannelBadges(
|
|
|
|
this->roomId(),
|
|
|
|
// successCallback
|
|
|
|
[this, weak = weakOf<Channel>(this)](auto channelBadges) {
|
2019-08-20 21:50:36 +02:00
|
|
|
auto shared = weak.lock();
|
|
|
|
if (!shared)
|
2023-04-16 11:58:45 +02:00
|
|
|
{
|
|
|
|
// The channel has been closed inbetween us making the request and the request finishing
|
|
|
|
return;
|
|
|
|
}
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
auto badgeSets = this->badgeSets_.access();
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2023-04-16 11:58:45 +02:00
|
|
|
for (const auto &badgeSet : channelBadges.badgeSets)
|
2018-08-02 14:23:27 +02:00
|
|
|
{
|
2023-04-16 11:58:45 +02:00
|
|
|
const auto &setID = badgeSet.setID;
|
|
|
|
for (const auto &version : badgeSet.versions)
|
2019-08-20 21:50:36 +02:00
|
|
|
{
|
2023-04-16 11:58:45 +02:00
|
|
|
auto emote = Emote{
|
2024-01-17 21:05:44 +01:00
|
|
|
.name = EmoteName{},
|
|
|
|
.images =
|
|
|
|
ImageSet{
|
2024-02-25 18:19:20 +01:00
|
|
|
Image::fromUrl(version.imageURL1x, 1,
|
|
|
|
BASE_BADGE_SIZE),
|
|
|
|
Image::fromUrl(version.imageURL2x, .5,
|
|
|
|
BASE_BADGE_SIZE * 2),
|
|
|
|
Image::fromUrl(version.imageURL4x, .25,
|
|
|
|
BASE_BADGE_SIZE * 4),
|
2024-01-17 21:05:44 +01:00
|
|
|
},
|
|
|
|
.tooltip = Tooltip{version.title},
|
|
|
|
.homePage = version.clickURL,
|
2023-04-16 11:58:45 +02:00
|
|
|
};
|
|
|
|
(*badgeSets)[setID][version.id] =
|
|
|
|
std::make_shared<Emote>(emote);
|
|
|
|
}
|
2019-08-20 21:50:36 +02:00
|
|
|
}
|
2023-04-16 11:58:45 +02:00
|
|
|
},
|
|
|
|
// failureCallback
|
|
|
|
[this, weak = weakOf<Channel>(this)](auto error, auto message) {
|
|
|
|
auto shared = weak.lock();
|
|
|
|
if (!shared)
|
|
|
|
{
|
|
|
|
// The channel has been closed inbetween us making the request and the request finishing
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString errorMessage("Failed to load channel badges - ");
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2023-04-16 11:58:45 +02:00
|
|
|
switch (error)
|
|
|
|
{
|
|
|
|
case HelixGetChannelBadgesError::Forwarded: {
|
|
|
|
errorMessage += message;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// This would most likely happen if the service is down, or if the JSON payload returned has changed format
|
|
|
|
case HelixGetChannelBadgesError::Unknown: {
|
|
|
|
errorMessage += "An unknown error has occurred.";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-07-07 22:03:05 +02:00
|
|
|
this->addSystemMessage(errorMessage);
|
2023-04-16 11:58:45 +02:00
|
|
|
});
|
2018-08-02 14:23:27 +02:00
|
|
|
}
|
|
|
|
|
2018-08-13 13:54:39 +02:00
|
|
|
void TwitchChannel::refreshCheerEmotes()
|
2018-08-02 14:23:27 +02:00
|
|
|
{
|
2021-05-15 19:02:47 +02:00
|
|
|
getHelix()->getCheermotes(
|
|
|
|
this->roomId(),
|
|
|
|
[this, weak = weakOf<Channel>(this)](
|
2023-11-12 14:51:51 +01:00
|
|
|
const std::vector<HelixCheermoteSet> &cheermoteSets) {
|
2020-01-12 10:06:01 +01:00
|
|
|
auto shared = weak.lock();
|
|
|
|
if (!shared)
|
|
|
|
{
|
2023-11-12 14:51:51 +01:00
|
|
|
return;
|
2020-01-12 10:06:01 +01:00
|
|
|
}
|
|
|
|
|
2018-08-10 18:56:17 +02:00
|
|
|
std::vector<CheerEmoteSet> emoteSets;
|
2018-08-06 21:17:03 +02:00
|
|
|
|
2021-05-15 19:02:47 +02:00
|
|
|
for (const auto &set : cheermoteSets)
|
2019-09-08 12:45:25 +02:00
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
auto cheerEmoteSet = CheerEmoteSet();
|
|
|
|
cheerEmoteSet.regex = QRegularExpression(
|
2019-09-08 18:01:38 +02:00
|
|
|
"^" + set.prefix + "([1-9][0-9]*)$",
|
|
|
|
QRegularExpression::CaseInsensitiveOption);
|
2018-08-06 21:17:03 +02:00
|
|
|
|
2021-05-15 19:02:47 +02:00
|
|
|
for (const auto &tier : set.tiers)
|
2019-09-08 12:45:25 +02:00
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
CheerEmote cheerEmote;
|
2018-08-06 21:17:03 +02:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
cheerEmote.color = QColor(tier.color);
|
|
|
|
cheerEmote.minBits = tier.minBits;
|
2019-12-19 21:36:02 +01:00
|
|
|
cheerEmote.regex = cheerEmoteSet.regex;
|
2018-08-06 21:17:03 +02:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
// TODO(pajlada): We currently hardcode dark here :|
|
|
|
|
// We will continue to do so for now since we haven't had to
|
|
|
|
// solve that anywhere else
|
2018-08-06 21:17:03 +02:00
|
|
|
|
2021-03-13 14:16:32 +01:00
|
|
|
// Combine the prefix (e.g. BibleThump) with the tier (1, 100 etc.)
|
|
|
|
auto emoteTooltip =
|
|
|
|
set.prefix + tier.id + "<br>Twitch Cheer Emote";
|
2024-02-25 18:19:20 +01:00
|
|
|
auto makeImageSet = [](const HelixCheermoteImage &image) {
|
|
|
|
return ImageSet{
|
|
|
|
Image::fromUrl(image.imageURL1x, 1.0,
|
|
|
|
BASE_BADGE_SIZE),
|
|
|
|
Image::fromUrl(image.imageURL2x, 0.5,
|
|
|
|
BASE_BADGE_SIZE * 2),
|
|
|
|
Image::fromUrl(image.imageURL4x, 0.25,
|
|
|
|
BASE_BADGE_SIZE * 4),
|
|
|
|
};
|
|
|
|
};
|
2024-01-17 21:05:44 +01:00
|
|
|
cheerEmote.animatedEmote = std::make_shared<Emote>(Emote{
|
|
|
|
.name = EmoteName{"cheer emote"},
|
2024-02-25 18:19:20 +01:00
|
|
|
.images = makeImageSet(tier.darkAnimated),
|
2024-01-17 21:05:44 +01:00
|
|
|
.tooltip = Tooltip{emoteTooltip},
|
|
|
|
.homePage = Url{},
|
|
|
|
});
|
|
|
|
cheerEmote.staticEmote = std::make_shared<Emote>(Emote{
|
|
|
|
.name = EmoteName{"cheer emote"},
|
2024-02-25 18:19:20 +01:00
|
|
|
.images = makeImageSet(tier.darkStatic),
|
2024-01-17 21:05:44 +01:00
|
|
|
.tooltip = Tooltip{emoteTooltip},
|
|
|
|
.homePage = Url{},
|
|
|
|
});
|
2018-08-06 21:17:03 +02:00
|
|
|
|
2021-05-15 19:02:47 +02:00
|
|
|
cheerEmoteSet.cheerEmotes.emplace_back(
|
|
|
|
std::move(cheerEmote));
|
2018-08-02 14:23:27 +02:00
|
|
|
}
|
|
|
|
|
2021-05-15 19:02:47 +02:00
|
|
|
// Sort cheermotes by cost
|
2018-08-02 14:23:27 +02:00
|
|
|
std::sort(cheerEmoteSet.cheerEmotes.begin(),
|
|
|
|
cheerEmoteSet.cheerEmotes.end(),
|
|
|
|
[](const auto &lhs, const auto &rhs) {
|
2019-09-08 13:40:11 +02:00
|
|
|
return lhs.minBits > rhs.minBits;
|
2018-08-02 14:23:27 +02:00
|
|
|
});
|
|
|
|
|
2021-05-15 19:02:47 +02:00
|
|
|
emoteSets.emplace_back(std::move(cheerEmoteSet));
|
2018-08-02 14:23:27 +02:00
|
|
|
}
|
2021-05-15 19:02:47 +02:00
|
|
|
|
2018-08-10 18:56:17 +02:00
|
|
|
*this->cheerEmoteSets_.access() = std::move(emoteSets);
|
2021-05-15 19:02:47 +02:00
|
|
|
},
|
|
|
|
[] {
|
|
|
|
// Failure
|
|
|
|
});
|
2018-08-02 14:23:27 +02:00
|
|
|
}
|
|
|
|
|
2021-01-17 14:47:34 +01:00
|
|
|
void TwitchChannel::createClip()
|
|
|
|
{
|
|
|
|
if (!this->isLive())
|
|
|
|
{
|
2024-07-07 22:03:05 +02:00
|
|
|
this->addSystemMessage(
|
|
|
|
"Cannot create clip while the channel is offline!");
|
2021-01-17 14:47:34 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-13 17:54:34 +01:00
|
|
|
// timer has never started, proceed and start it
|
|
|
|
if (!this->clipCreationTimer_.isValid())
|
|
|
|
{
|
|
|
|
this->clipCreationTimer_.start();
|
|
|
|
}
|
|
|
|
else if (this->clipCreationTimer_.elapsed() < CLIP_CREATION_COOLDOWN ||
|
|
|
|
this->isClipCreationInProgress)
|
2021-01-17 14:47:34 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-07-07 22:03:05 +02:00
|
|
|
this->addSystemMessage("Creating clip...");
|
2021-01-17 14:47:34 +01:00
|
|
|
this->isClipCreationInProgress = true;
|
|
|
|
|
|
|
|
getHelix()->createClip(
|
|
|
|
this->roomId(),
|
|
|
|
// successCallback
|
|
|
|
[this](const HelixClip &clip) {
|
|
|
|
MessageBuilder builder;
|
2021-07-11 12:19:35 +02:00
|
|
|
QString text(
|
|
|
|
"Clip created! Copy link to clipboard or edit it in browser.");
|
|
|
|
builder.message().messageText = text;
|
|
|
|
builder.message().searchText = text;
|
2021-01-17 14:47:34 +01:00
|
|
|
builder.message().flags.set(MessageFlag::System);
|
|
|
|
|
|
|
|
builder.emplace<TimestampElement>();
|
|
|
|
// text
|
|
|
|
builder.emplace<TextElement>("Clip created!",
|
|
|
|
MessageElementFlag::Text,
|
|
|
|
MessageColor::System);
|
|
|
|
// clip link
|
|
|
|
builder
|
|
|
|
.emplace<TextElement>("Copy link to clipboard",
|
|
|
|
MessageElementFlag::Text,
|
|
|
|
MessageColor::Link)
|
|
|
|
->setLink(Link(Link::CopyToClipboard, CLIPS_LINK.arg(clip.id)));
|
|
|
|
// separator text
|
|
|
|
builder.emplace<TextElement>("or", MessageElementFlag::Text,
|
|
|
|
MessageColor::System);
|
|
|
|
// edit link
|
|
|
|
builder
|
|
|
|
.emplace<TextElement>("edit it in browser.",
|
|
|
|
MessageElementFlag::Text,
|
|
|
|
MessageColor::Link)
|
|
|
|
->setLink(Link(Link::Url, clip.editUrl));
|
|
|
|
|
2024-07-13 13:15:11 +02:00
|
|
|
this->addMessage(builder.release(), MessageContext::Original);
|
2021-01-17 14:47:34 +01:00
|
|
|
},
|
|
|
|
// failureCallback
|
|
|
|
[this](auto error) {
|
|
|
|
MessageBuilder builder;
|
2021-07-11 12:19:35 +02:00
|
|
|
QString text;
|
2021-01-17 14:47:34 +01:00
|
|
|
builder.message().flags.set(MessageFlag::System);
|
|
|
|
|
|
|
|
builder.emplace<TimestampElement>();
|
|
|
|
|
|
|
|
switch (error)
|
|
|
|
{
|
|
|
|
case HelixClipError::ClipsDisabled: {
|
|
|
|
builder.emplace<TextElement>(
|
|
|
|
CLIPS_FAILURE_CLIPS_DISABLED_TEXT,
|
|
|
|
MessageElementFlag::Text, MessageColor::System);
|
2021-07-11 12:19:35 +02:00
|
|
|
text = CLIPS_FAILURE_CLIPS_DISABLED_TEXT;
|
2021-01-17 14:47:34 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HelixClipError::UserNotAuthenticated: {
|
|
|
|
builder.emplace<TextElement>(
|
|
|
|
CLIPS_FAILURE_NOT_AUTHENTICATED_TEXT,
|
|
|
|
MessageElementFlag::Text, MessageColor::System);
|
|
|
|
builder
|
|
|
|
.emplace<TextElement>(LOGIN_PROMPT_TEXT,
|
|
|
|
MessageElementFlag::Text,
|
|
|
|
MessageColor::Link)
|
|
|
|
->setLink(ACCOUNTS_LINK);
|
2021-07-11 12:19:35 +02:00
|
|
|
text = QString("%1 %2").arg(
|
|
|
|
CLIPS_FAILURE_NOT_AUTHENTICATED_TEXT,
|
|
|
|
LOGIN_PROMPT_TEXT);
|
2021-01-17 14:47:34 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// This would most likely happen if the service is down, or if the JSON payload returned has changed format
|
|
|
|
case HelixClipError::Unknown:
|
|
|
|
default: {
|
|
|
|
builder.emplace<TextElement>(
|
|
|
|
CLIPS_FAILURE_UNKNOWN_ERROR_TEXT,
|
|
|
|
MessageElementFlag::Text, MessageColor::System);
|
2021-07-11 12:19:35 +02:00
|
|
|
text = CLIPS_FAILURE_UNKNOWN_ERROR_TEXT;
|
2021-01-17 14:47:34 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-07-11 12:19:35 +02:00
|
|
|
builder.message().messageText = text;
|
|
|
|
builder.message().searchText = text;
|
|
|
|
|
2024-07-13 13:15:11 +02:00
|
|
|
this->addMessage(builder.release(), MessageContext::Original);
|
2021-01-17 14:47:34 +01:00
|
|
|
},
|
|
|
|
// finallyCallback - this will always execute, so clip creation won't ever be stuck
|
|
|
|
[this] {
|
2021-03-13 17:54:34 +01:00
|
|
|
this->clipCreationTimer_.restart();
|
2021-01-17 14:47:34 +01:00
|
|
|
this->isClipCreationInProgress = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-10-08 18:50:48 +02:00
|
|
|
std::optional<EmotePtr> TwitchChannel::twitchBadge(const QString &set,
|
|
|
|
const QString &version) const
|
2018-08-02 14:23:27 +02:00
|
|
|
{
|
|
|
|
auto badgeSets = this->badgeSets_.access();
|
|
|
|
auto it = badgeSets->find(set);
|
|
|
|
if (it != badgeSets->end())
|
|
|
|
{
|
|
|
|
auto it2 = it->second.find(version);
|
|
|
|
if (it2 != it->second.end())
|
|
|
|
{
|
|
|
|
return it2->second;
|
|
|
|
}
|
|
|
|
}
|
2023-10-08 18:50:48 +02:00
|
|
|
return std::nullopt;
|
2018-07-14 14:24:18 +02:00
|
|
|
}
|
|
|
|
|
2024-02-25 12:18:57 +01:00
|
|
|
std::vector<FfzBadges::Badge> TwitchChannel::ffzChannelBadges(
|
|
|
|
const QString &userID) const
|
|
|
|
{
|
|
|
|
this->tgFfzChannelBadges_.guard();
|
|
|
|
|
|
|
|
auto it = this->ffzChannelBadges_.find(userID);
|
|
|
|
if (it == this->ffzChannelBadges_.end())
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<FfzBadges::Badge> badges;
|
|
|
|
|
2024-07-21 15:09:59 +02:00
|
|
|
const auto *ffzBadges = getApp()->getFfzBadges();
|
2024-02-25 12:18:57 +01:00
|
|
|
|
|
|
|
for (const auto &badgeID : it->second)
|
|
|
|
{
|
|
|
|
auto badge = ffzBadges->getBadge(badgeID);
|
|
|
|
if (badge.has_value())
|
|
|
|
{
|
|
|
|
badges.emplace_back(*badge);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return badges;
|
|
|
|
}
|
|
|
|
|
2023-10-08 18:50:48 +02:00
|
|
|
std::optional<EmotePtr> TwitchChannel::ffzCustomModBadge() const
|
2018-10-25 21:53:03 +02:00
|
|
|
{
|
2019-09-08 11:36:35 +02:00
|
|
|
return this->ffzCustomModBadge_.get();
|
2018-10-25 21:53:03 +02:00
|
|
|
}
|
|
|
|
|
2023-10-08 18:50:48 +02:00
|
|
|
std::optional<EmotePtr> TwitchChannel::ffzCustomVipBadge() const
|
2021-04-17 14:42:30 +02:00
|
|
|
{
|
|
|
|
return this->ffzCustomVipBadge_.get();
|
|
|
|
}
|
|
|
|
|
2023-10-08 18:50:48 +02:00
|
|
|
std::optional<CheerEmote> TwitchChannel::cheerEmote(const QString &string)
|
2019-09-08 12:45:25 +02:00
|
|
|
{
|
|
|
|
auto sets = this->cheerEmoteSets_.access();
|
|
|
|
for (const auto &set : *sets)
|
|
|
|
{
|
2019-09-08 18:01:38 +02:00
|
|
|
auto match = set.regex.match(string);
|
2019-09-08 12:45:25 +02:00
|
|
|
if (!match.hasMatch())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
QString amount = match.captured(1);
|
|
|
|
bool ok = false;
|
|
|
|
int bitAmount = amount.toInt(&ok);
|
|
|
|
if (!ok)
|
|
|
|
{
|
2020-11-21 16:20:10 +01:00
|
|
|
qCDebug(chatterinoTwitch)
|
|
|
|
<< "Error parsing bit amount in cheerEmote";
|
2019-09-08 12:45:25 +02:00
|
|
|
}
|
|
|
|
for (const auto &emote : set.cheerEmotes)
|
|
|
|
{
|
2019-09-08 13:40:11 +02:00
|
|
|
if (bitAmount >= emote.minBits)
|
2019-09-08 12:45:25 +02:00
|
|
|
{
|
2019-09-08 18:01:38 +02:00
|
|
|
return emote;
|
2019-09-08 12:45:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-10-08 18:50:48 +02:00
|
|
|
return std::nullopt;
|
2018-10-25 21:53:03 +02:00
|
|
|
}
|
|
|
|
|
2023-07-29 11:49:44 +02:00
|
|
|
void TwitchChannel::updateSevenTVActivity()
|
|
|
|
{
|
|
|
|
static const QString seventvActivityUrl =
|
|
|
|
QStringLiteral("https://7tv.io/v3/users/%1/presences");
|
|
|
|
|
|
|
|
const auto currentSeventvUserID =
|
2024-07-21 15:09:59 +02:00
|
|
|
getApp()->getAccounts()->twitch.getCurrent()->getSeventvUserID();
|
2023-07-29 11:49:44 +02:00
|
|
|
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();
|
|
|
|
|
2024-07-21 15:09:59 +02:00
|
|
|
getApp()->getSeventvAPI()->updatePresence(
|
2023-07-29 11:49:44 +02:00
|
|
|
this->roomId(), currentSeventvUserID,
|
|
|
|
[chan = weakOf<Channel>(this)]() {
|
|
|
|
const auto self =
|
|
|
|
std::dynamic_pointer_cast<TwitchChannel>(chan.lock());
|
|
|
|
if (!self)
|
|
|
|
{
|
2023-11-12 14:51:51 +01:00
|
|
|
return;
|
2023-07-29 11:49:44 +02:00
|
|
|
}
|
|
|
|
self->nextSeventvActivity_ =
|
|
|
|
QDateTime::currentDateTimeUtc().addSecs(60);
|
|
|
|
},
|
|
|
|
[](const auto &result) {
|
|
|
|
qCDebug(chatterinoSeventv)
|
|
|
|
<< "Failed to update 7TV activity:" << result.formatError();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-01-17 21:05:44 +01:00
|
|
|
void TwitchChannel::listenSevenTVCosmetics() const
|
2023-07-29 11:49:44 +02:00
|
|
|
{
|
2024-07-21 15:09:59 +02:00
|
|
|
if (getApp()->getTwitch()->getSeventvEventAPI())
|
2023-07-29 11:49:44 +02:00
|
|
|
{
|
2024-07-21 15:09:59 +02:00
|
|
|
getApp()->getTwitch()->getSeventvEventAPI()->subscribeTwitchChannel(
|
2023-07-29 11:49:44 +02:00
|
|
|
this->roomId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-04 14:57:29 +01:00
|
|
|
} // namespace chatterino
|