refactor(notifications): remove platform specifier (#5914)
This commit is contained in:
+29
-43
@@ -126,11 +126,11 @@ QString Toasts::findStringFromReaction(
|
||||
|
||||
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
|
||||
void Toasts::sendChannelNotification(const QString &channelName,
|
||||
const QString &channelTitle, Platform p)
|
||||
const QString &channelTitle)
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
auto sendChannelNotification = [this, channelName, channelTitle, p] {
|
||||
this->sendWindowsNotification(channelName, channelTitle, p);
|
||||
auto sendChannelNotification = [this, channelName, channelTitle] {
|
||||
this->sendWindowsNotification(channelName, channelTitle);
|
||||
};
|
||||
#elif defined(CHATTERINO_WITH_LIBNOTIFY)
|
||||
auto sendChannelNotification = [this, channelName, channelTitle] {
|
||||
@@ -143,28 +143,25 @@ void Toasts::sendChannelNotification(const QString &channelName,
|
||||
};
|
||||
#endif
|
||||
// Fetch user profile avatar
|
||||
if (p == Platform::Twitch)
|
||||
if (hasAvatarForChannel(channelName))
|
||||
{
|
||||
if (hasAvatarForChannel(channelName))
|
||||
{
|
||||
sendChannelNotification();
|
||||
}
|
||||
else
|
||||
{
|
||||
getHelix()->getUserByName(
|
||||
channelName,
|
||||
[channelName, sendChannelNotification](const auto &user) {
|
||||
// gets deleted when finished
|
||||
auto *downloader =
|
||||
new AvatarDownloader(user.profileImageUrl, channelName);
|
||||
QObject::connect(downloader,
|
||||
&AvatarDownloader::downloadComplete,
|
||||
sendChannelNotification);
|
||||
},
|
||||
[] {
|
||||
// on failure
|
||||
});
|
||||
}
|
||||
sendChannelNotification();
|
||||
}
|
||||
else
|
||||
{
|
||||
getHelix()->getUserByName(
|
||||
channelName,
|
||||
[channelName, sendChannelNotification](const auto &user) {
|
||||
// gets deleted when finished
|
||||
auto *downloader =
|
||||
new AvatarDownloader(user.profileImageUrl, channelName);
|
||||
QObject::connect(downloader,
|
||||
&AvatarDownloader::downloadComplete,
|
||||
sendChannelNotification);
|
||||
},
|
||||
[] {
|
||||
// on failure
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,12 +171,10 @@ class CustomHandler : public WinToastLib::IWinToastHandler
|
||||
{
|
||||
private:
|
||||
QString channelName_;
|
||||
Platform platform_;
|
||||
|
||||
public:
|
||||
CustomHandler(QString channelName, Platform p)
|
||||
CustomHandler(QString channelName)
|
||||
: channelName_(std::move(channelName))
|
||||
, platform_(p)
|
||||
{
|
||||
}
|
||||
void toastActivated() const override
|
||||
@@ -190,18 +185,12 @@ public:
|
||||
switch (toastReaction)
|
||||
{
|
||||
case ToastReaction::OpenInBrowser:
|
||||
if (platform_ == Platform::Twitch)
|
||||
{
|
||||
QDesktopServices::openUrl(
|
||||
QUrl(u"https://www.twitch.tv/" % channelName_));
|
||||
}
|
||||
QDesktopServices::openUrl(
|
||||
QUrl(u"https://www.twitch.tv/" % channelName_));
|
||||
break;
|
||||
case ToastReaction::OpenInPlayer:
|
||||
if (platform_ == Platform::Twitch)
|
||||
{
|
||||
QDesktopServices::openUrl(
|
||||
QUrl(TWITCH_PLAYER_URL.arg(channelName_)));
|
||||
}
|
||||
QDesktopServices::openUrl(
|
||||
QUrl(TWITCH_PLAYER_URL.arg(channelName_)));
|
||||
break;
|
||||
case ToastReaction::OpenInStreamlink: {
|
||||
openStreamlinkForChannel(channelName_);
|
||||
@@ -255,7 +244,7 @@ void Toasts::ensureInitialized()
|
||||
}
|
||||
|
||||
void Toasts::sendWindowsNotification(const QString &channelName,
|
||||
const QString &channelTitle, Platform p)
|
||||
const QString &channelTitle)
|
||||
{
|
||||
this->ensureInitialized();
|
||||
|
||||
@@ -276,10 +265,7 @@ void Toasts::sendWindowsNotification(const QString &channelName,
|
||||
}
|
||||
|
||||
QString avatarPath;
|
||||
if (p == Platform::Twitch)
|
||||
{
|
||||
avatarPath = avatarFilePath(channelName);
|
||||
}
|
||||
avatarPath = avatarFilePath(channelName);
|
||||
templ.setImagePath(avatarPath.toStdWString());
|
||||
if (getSettings()->notificationPlaySound)
|
||||
{
|
||||
@@ -287,7 +273,7 @@ void Toasts::sendWindowsNotification(const QString &channelName,
|
||||
}
|
||||
|
||||
WinToast::WinToastError error = WinToast::NoError;
|
||||
WinToast::instance()->showToast(templ, new CustomHandler(channelName, p),
|
||||
WinToast::instance()->showToast(templ, new CustomHandler(channelName),
|
||||
&error);
|
||||
if (error != WinToast::NoError)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user