mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-24 03:58:49 +03:00
Enable sending notifications via the systemNotification signal on macOS
This commit is contained in:
parent
d25515e676
commit
5ee60d0f2e
3 changed files with 36 additions and 43 deletions
|
@ -81,11 +81,12 @@ private:
|
||||||
const QString &subtitle,
|
const QString &subtitle,
|
||||||
const QString &informativeText,
|
const QString &informativeText,
|
||||||
const QString &bodyImagePath,
|
const QString &bodyImagePath,
|
||||||
const QString &respondStr,
|
|
||||||
const QString &sendStr,
|
|
||||||
const QString &placeholder,
|
|
||||||
const bool playSound);
|
const bool playSound);
|
||||||
|
|
||||||
|
QString respondStr;
|
||||||
|
QString sendStr;
|
||||||
|
QString placeholder;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void attachToMacNotifCenter();
|
static void attachToMacNotifCenter();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -22,6 +22,35 @@ formatNotification(const mtx::responses::Notification ¬ification)
|
||||||
return utils::stripReplyFallbacks(notification.event, {}, {}).quoted_body;
|
return utils::stripReplyFallbacks(notification.event, {}, {}).quoted_body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NotificationsManager::NotificationsManager(QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
// Putting these here to pass along since I'm not sure how
|
||||||
|
// our translate step interacts with .mm files
|
||||||
|
respondStr = QObject::tr("Respond");
|
||||||
|
sendStr = QObject::tr("Send");
|
||||||
|
placeholder = QObject::tr("Write a message...");
|
||||||
|
|
||||||
|
connect(
|
||||||
|
this,
|
||||||
|
&NotificationsManager::systemPostNotificationCb,
|
||||||
|
this,
|
||||||
|
[this](const QString &room_id,
|
||||||
|
const QString &event_id,
|
||||||
|
const QString &roomName,
|
||||||
|
const QString &text,
|
||||||
|
const QImage &) {
|
||||||
|
objCxxPostNotification(roomName,
|
||||||
|
room_id,
|
||||||
|
event_id,
|
||||||
|
text,
|
||||||
|
/*const QString &informativeText*/ "",
|
||||||
|
"",
|
||||||
|
true);
|
||||||
|
},
|
||||||
|
Qt::QueuedConnection);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
NotificationsManager::postNotification(const mtx::responses::Notification ¬ification,
|
NotificationsManager::postNotification(const mtx::responses::Notification ¬ification,
|
||||||
const QImage &icon)
|
const QImage &icon)
|
||||||
|
@ -40,12 +69,6 @@ NotificationsManager::postNotification(const mtx::responses::Notification ¬if
|
||||||
¬ification.event) != nullptr;
|
¬ification.event) != nullptr;
|
||||||
const auto isReply = utils::isReply(notification.event);
|
const auto isReply = utils::isReply(notification.event);
|
||||||
|
|
||||||
// Putting these here to pass along since I'm not sure how
|
|
||||||
// our translate step interacts with .mm files
|
|
||||||
const auto respondStr = QObject::tr("Respond");
|
|
||||||
const auto sendStr = QObject::tr("Send");
|
|
||||||
const auto placeholder = QObject::tr("Write a message...");
|
|
||||||
|
|
||||||
auto playSound = false;
|
auto playSound = false;
|
||||||
|
|
||||||
if (std::find(notification.actions.begin(),
|
if (std::find(notification.actions.begin(),
|
||||||
|
@ -59,16 +82,7 @@ NotificationsManager::postNotification(const mtx::responses::Notification ¬if
|
||||||
const QString messageInfo = (isReply ? tr("%1 replied with an encrypted message")
|
const QString messageInfo = (isReply ? tr("%1 replied with an encrypted message")
|
||||||
: tr("%1 sent an encrypted message"))
|
: tr("%1 sent an encrypted message"))
|
||||||
.arg(sender);
|
.arg(sender);
|
||||||
objCxxPostNotification(room_name,
|
objCxxPostNotification(room_name, room_id, event_id, messageInfo, "", "", playSound);
|
||||||
room_id,
|
|
||||||
event_id,
|
|
||||||
messageInfo,
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
respondStr,
|
|
||||||
sendStr,
|
|
||||||
placeholder,
|
|
||||||
playSound);
|
|
||||||
} else {
|
} else {
|
||||||
const QString messageInfo =
|
const QString messageInfo =
|
||||||
(isReply ? tr("%1 replied to a message") : tr("%1 sent a message")).arg(sender);
|
(isReply ? tr("%1 replied to a message") : tr("%1 sent a message")).arg(sender);
|
||||||
|
@ -76,25 +90,14 @@ NotificationsManager::postNotification(const mtx::responses::Notification ¬if
|
||||||
MxcImageProvider::download(
|
MxcImageProvider::download(
|
||||||
QString::fromStdString(mtx::accessors::url(notification.event)).remove("mxc://"),
|
QString::fromStdString(mtx::accessors::url(notification.event)).remove("mxc://"),
|
||||||
QSize(200, 80),
|
QSize(200, 80),
|
||||||
[this,
|
[this, notification, room_name, room_id, event_id, messageInfo, playSound](
|
||||||
notification,
|
QString, QSize, QImage, QString imgPath) {
|
||||||
room_name,
|
|
||||||
room_id,
|
|
||||||
event_id,
|
|
||||||
messageInfo,
|
|
||||||
respondStr,
|
|
||||||
sendStr,
|
|
||||||
placeholder,
|
|
||||||
playSound](QString, QSize, QImage, QString imgPath) {
|
|
||||||
objCxxPostNotification(room_name,
|
objCxxPostNotification(room_name,
|
||||||
room_id,
|
room_id,
|
||||||
event_id,
|
event_id,
|
||||||
messageInfo,
|
messageInfo,
|
||||||
formatNotification(notification),
|
formatNotification(notification),
|
||||||
imgPath,
|
imgPath,
|
||||||
respondStr,
|
|
||||||
sendStr,
|
|
||||||
placeholder,
|
|
||||||
playSound);
|
playSound);
|
||||||
});
|
});
|
||||||
else
|
else
|
||||||
|
@ -104,9 +107,6 @@ NotificationsManager::postNotification(const mtx::responses::Notification ¬if
|
||||||
messageInfo,
|
messageInfo,
|
||||||
formatNotification(notification),
|
formatNotification(notification),
|
||||||
"",
|
"",
|
||||||
respondStr,
|
|
||||||
sendStr,
|
|
||||||
placeholder,
|
|
||||||
playSound);
|
playSound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,11 +61,6 @@
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NotificationsManager::NotificationsManager(QObject* parent)
|
|
||||||
: QObject(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void NotificationsManager::objCxxPostNotification(
|
void NotificationsManager::objCxxPostNotification(
|
||||||
const QString& room_name,
|
const QString& room_name,
|
||||||
const QString& room_id,
|
const QString& room_id,
|
||||||
|
@ -73,9 +68,6 @@ void NotificationsManager::objCxxPostNotification(
|
||||||
const QString& subtitle,
|
const QString& subtitle,
|
||||||
const QString& informativeText,
|
const QString& informativeText,
|
||||||
const QString& bodyImagePath,
|
const QString& bodyImagePath,
|
||||||
const QString& respondStr,
|
|
||||||
const QString& sendStr,
|
|
||||||
const QString& placeholder,
|
|
||||||
const bool enableSound)
|
const bool enableSound)
|
||||||
{
|
{
|
||||||
// Request permissions for alerts (the generic type of notification), sound playback,
|
// Request permissions for alerts (the generic type of notification), sound playback,
|
||||||
|
|
Loading…
Reference in a new issue