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: Fixed suspicious user treatment update messages not being searchable. (#5865)
|
||||||
- Bugfix: Ensure miniaudio backend exits even if it doesn't exit cleanly. (#5896)
|
- 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: 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: Highlight checks now use non-capturing groups for the boundaries. (#5784)
|
||||||
- Dev: Removed unused PubSub whisper code. (#5898)
|
- Dev: Removed unused PubSub whisper code. (#5898)
|
||||||
- Dev: Updated Conan dependencies. (#5776)
|
- Dev: Updated Conan dependencies. (#5776)
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ QString debugTest(const CommandContext &ctx)
|
|||||||
auto title = ctx.twitchChannel->accessStreamStatus()->title;
|
auto title = ctx.twitchChannel->accessStreamStatus()->title;
|
||||||
|
|
||||||
getApp()->getToasts()->sendChannelNotification(
|
getApp()->getToasts()->sendChannelNotification(
|
||||||
ctx.twitchChannel->getName(), title, Platform::Twitch);
|
ctx.twitchChannel->getName(), title);
|
||||||
ctx.channel->addSystemMessage(
|
ctx.channel->addSystemMessage(
|
||||||
QString("debug-test sent desktop notification"));
|
QString("debug-test sent desktop notification"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,8 +122,8 @@ void NotificationController::notifyTwitchChannelLive(
|
|||||||
{
|
{
|
||||||
if (Toasts::isEnabled())
|
if (Toasts::isEnabled())
|
||||||
{
|
{
|
||||||
getApp()->getToasts()->sendChannelNotification(
|
getApp()->getToasts()->sendChannelNotification(payload.channelName,
|
||||||
payload.channelName, payload.title, Platform::Twitch);
|
payload.title);
|
||||||
}
|
}
|
||||||
if (getSettings()->notificationPlaySound)
|
if (getSettings()->notificationPlaySound)
|
||||||
{
|
{
|
||||||
|
|||||||
+29
-43
@@ -126,11 +126,11 @@ QString Toasts::findStringFromReaction(
|
|||||||
|
|
||||||
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
|
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
|
||||||
void Toasts::sendChannelNotification(const QString &channelName,
|
void Toasts::sendChannelNotification(const QString &channelName,
|
||||||
const QString &channelTitle, Platform p)
|
const QString &channelTitle)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
auto sendChannelNotification = [this, channelName, channelTitle, p] {
|
auto sendChannelNotification = [this, channelName, channelTitle] {
|
||||||
this->sendWindowsNotification(channelName, channelTitle, p);
|
this->sendWindowsNotification(channelName, channelTitle);
|
||||||
};
|
};
|
||||||
#elif defined(CHATTERINO_WITH_LIBNOTIFY)
|
#elif defined(CHATTERINO_WITH_LIBNOTIFY)
|
||||||
auto sendChannelNotification = [this, channelName, channelTitle] {
|
auto sendChannelNotification = [this, channelName, channelTitle] {
|
||||||
@@ -143,28 +143,25 @@ void Toasts::sendChannelNotification(const QString &channelName,
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
// Fetch user profile avatar
|
// Fetch user profile avatar
|
||||||
if (p == Platform::Twitch)
|
if (hasAvatarForChannel(channelName))
|
||||||
{
|
{
|
||||||
if (hasAvatarForChannel(channelName))
|
sendChannelNotification();
|
||||||
{
|
}
|
||||||
sendChannelNotification();
|
else
|
||||||
}
|
{
|
||||||
else
|
getHelix()->getUserByName(
|
||||||
{
|
channelName,
|
||||||
getHelix()->getUserByName(
|
[channelName, sendChannelNotification](const auto &user) {
|
||||||
channelName,
|
// gets deleted when finished
|
||||||
[channelName, sendChannelNotification](const auto &user) {
|
auto *downloader =
|
||||||
// gets deleted when finished
|
new AvatarDownloader(user.profileImageUrl, channelName);
|
||||||
auto *downloader =
|
QObject::connect(downloader,
|
||||||
new AvatarDownloader(user.profileImageUrl, channelName);
|
&AvatarDownloader::downloadComplete,
|
||||||
QObject::connect(downloader,
|
sendChannelNotification);
|
||||||
&AvatarDownloader::downloadComplete,
|
},
|
||||||
sendChannelNotification);
|
[] {
|
||||||
},
|
// on failure
|
||||||
[] {
|
});
|
||||||
// on failure
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,12 +171,10 @@ class CustomHandler : public WinToastLib::IWinToastHandler
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
QString channelName_;
|
QString channelName_;
|
||||||
Platform platform_;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CustomHandler(QString channelName, Platform p)
|
CustomHandler(QString channelName)
|
||||||
: channelName_(std::move(channelName))
|
: channelName_(std::move(channelName))
|
||||||
, platform_(p)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void toastActivated() const override
|
void toastActivated() const override
|
||||||
@@ -190,18 +185,12 @@ public:
|
|||||||
switch (toastReaction)
|
switch (toastReaction)
|
||||||
{
|
{
|
||||||
case ToastReaction::OpenInBrowser:
|
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;
|
break;
|
||||||
case ToastReaction::OpenInPlayer:
|
case ToastReaction::OpenInPlayer:
|
||||||
if (platform_ == Platform::Twitch)
|
QDesktopServices::openUrl(
|
||||||
{
|
QUrl(TWITCH_PLAYER_URL.arg(channelName_)));
|
||||||
QDesktopServices::openUrl(
|
|
||||||
QUrl(TWITCH_PLAYER_URL.arg(channelName_)));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case ToastReaction::OpenInStreamlink: {
|
case ToastReaction::OpenInStreamlink: {
|
||||||
openStreamlinkForChannel(channelName_);
|
openStreamlinkForChannel(channelName_);
|
||||||
@@ -255,7 +244,7 @@ void Toasts::ensureInitialized()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Toasts::sendWindowsNotification(const QString &channelName,
|
void Toasts::sendWindowsNotification(const QString &channelName,
|
||||||
const QString &channelTitle, Platform p)
|
const QString &channelTitle)
|
||||||
{
|
{
|
||||||
this->ensureInitialized();
|
this->ensureInitialized();
|
||||||
|
|
||||||
@@ -276,10 +265,7 @@ void Toasts::sendWindowsNotification(const QString &channelName,
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString avatarPath;
|
QString avatarPath;
|
||||||
if (p == Platform::Twitch)
|
avatarPath = avatarFilePath(channelName);
|
||||||
{
|
|
||||||
avatarPath = avatarFilePath(channelName);
|
|
||||||
}
|
|
||||||
templ.setImagePath(avatarPath.toStdWString());
|
templ.setImagePath(avatarPath.toStdWString());
|
||||||
if (getSettings()->notificationPlaySound)
|
if (getSettings()->notificationPlaySound)
|
||||||
{
|
{
|
||||||
@@ -287,7 +273,7 @@ void Toasts::sendWindowsNotification(const QString &channelName,
|
|||||||
}
|
}
|
||||||
|
|
||||||
WinToast::WinToastError error = WinToast::NoError;
|
WinToast::WinToastError error = WinToast::NoError;
|
||||||
WinToast::instance()->showToast(templ, new CustomHandler(channelName, p),
|
WinToast::instance()->showToast(templ, new CustomHandler(channelName),
|
||||||
&error);
|
&error);
|
||||||
if (error != WinToast::NoError)
|
if (error != WinToast::NoError)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,12 +3,8 @@
|
|||||||
#include <pajlada/settings/setting.hpp>
|
#include <pajlada/settings/setting.hpp>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
enum class Platform : uint8_t;
|
|
||||||
|
|
||||||
enum class ToastReaction {
|
enum class ToastReaction {
|
||||||
OpenInBrowser = 0,
|
OpenInBrowser = 0,
|
||||||
OpenInPlayer = 1,
|
OpenInPlayer = 1,
|
||||||
@@ -22,7 +18,7 @@ public:
|
|||||||
~Toasts();
|
~Toasts();
|
||||||
|
|
||||||
void sendChannelNotification(const QString &channelName,
|
void sendChannelNotification(const QString &channelName,
|
||||||
const QString &channelTitle, Platform p);
|
const QString &channelTitle);
|
||||||
static QString findStringFromReaction(const ToastReaction &reaction);
|
static QString findStringFromReaction(const ToastReaction &reaction);
|
||||||
static QString findStringFromReaction(
|
static QString findStringFromReaction(
|
||||||
const pajlada::Settings::Setting<int> &reaction);
|
const pajlada::Settings::Setting<int> &reaction);
|
||||||
@@ -33,7 +29,7 @@ private:
|
|||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
void ensureInitialized();
|
void ensureInitialized();
|
||||||
void sendWindowsNotification(const QString &channelName,
|
void sendWindowsNotification(const QString &channelName,
|
||||||
const QString &channelTitle, Platform p);
|
const QString &channelTitle);
|
||||||
|
|
||||||
bool initialized_ = false;
|
bool initialized_ = false;
|
||||||
#elif defined(CHATTERINO_WITH_LIBNOTIFY)
|
#elif defined(CHATTERINO_WITH_LIBNOTIFY)
|
||||||
|
|||||||
Reference in New Issue
Block a user