refactor(notifications): remove platform specifier (#5914)
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
- Bugfix: Fixed suspicious user treatment update messages not being searchable. (#5865)
|
||||
- Bugfix: Ensure miniaudio backend exits even if it doesn't exit cleanly. (#5896)
|
||||
- Dev: Add initial experimental EventSub support. (#5837, #5895, #5897, #5904, #5910, #5903, #5915, #5916, #5930, #5935, #5932)
|
||||
- Dev: Remove unneeded platform specifier for toasts. (#5914)
|
||||
- Dev: Highlight checks now use non-capturing groups for the boundaries. (#5784)
|
||||
- Dev: Removed unused PubSub whisper code. (#5898)
|
||||
- Dev: Updated Conan dependencies. (#5776)
|
||||
|
||||
@@ -187,7 +187,7 @@ QString debugTest(const CommandContext &ctx)
|
||||
auto title = ctx.twitchChannel->accessStreamStatus()->title;
|
||||
|
||||
getApp()->getToasts()->sendChannelNotification(
|
||||
ctx.twitchChannel->getName(), title, Platform::Twitch);
|
||||
ctx.twitchChannel->getName(), title);
|
||||
ctx.channel->addSystemMessage(
|
||||
QString("debug-test sent desktop notification"));
|
||||
}
|
||||
|
||||
@@ -122,8 +122,8 @@ void NotificationController::notifyTwitchChannelLive(
|
||||
{
|
||||
if (Toasts::isEnabled())
|
||||
{
|
||||
getApp()->getToasts()->sendChannelNotification(
|
||||
payload.channelName, payload.title, Platform::Twitch);
|
||||
getApp()->getToasts()->sendChannelNotification(payload.channelName,
|
||||
payload.title);
|
||||
}
|
||||
if (getSettings()->notificationPlaySound)
|
||||
{
|
||||
|
||||
+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)
|
||||
{
|
||||
|
||||
@@ -3,12 +3,8 @@
|
||||
#include <pajlada/settings/setting.hpp>
|
||||
#include <QString>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
enum class Platform : uint8_t;
|
||||
|
||||
enum class ToastReaction {
|
||||
OpenInBrowser = 0,
|
||||
OpenInPlayer = 1,
|
||||
@@ -22,7 +18,7 @@ public:
|
||||
~Toasts();
|
||||
|
||||
void sendChannelNotification(const QString &channelName,
|
||||
const QString &channelTitle, Platform p);
|
||||
const QString &channelTitle);
|
||||
static QString findStringFromReaction(const ToastReaction &reaction);
|
||||
static QString findStringFromReaction(
|
||||
const pajlada::Settings::Setting<int> &reaction);
|
||||
@@ -33,7 +29,7 @@ private:
|
||||
#ifdef Q_OS_WIN
|
||||
void ensureInitialized();
|
||||
void sendWindowsNotification(const QString &channelName,
|
||||
const QString &channelTitle, Platform p);
|
||||
const QString &channelTitle);
|
||||
|
||||
bool initialized_ = false;
|
||||
#elif defined(CHATTERINO_WITH_LIBNOTIFY)
|
||||
|
||||
Reference in New Issue
Block a user