2021-03-05 02:35:15 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
2022-01-01 06:57:53 +03:00
|
|
|
// SPDX-FileCopyrightText: 2022 Nheko Contributors
|
2021-03-05 02:35:15 +03:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2018-05-05 22:40:24 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QImage>
|
2022-10-13 18:37:28 +03:00
|
|
|
#include <QMap>
|
2018-07-11 17:33:02 +03:00
|
|
|
#include <QObject>
|
2018-05-05 22:40:24 +03:00
|
|
|
#include <QString>
|
|
|
|
|
2021-02-13 20:59:50 +03:00
|
|
|
#include <mtx/responses/notifications.hpp>
|
2021-02-13 20:10:49 +03:00
|
|
|
|
2021-03-17 21:17:57 +03:00
|
|
|
#if defined(NHEKO_DBUS_SYS)
|
2018-07-11 17:33:02 +03:00
|
|
|
#include <QtDBus/QDBusArgument>
|
|
|
|
#include <QtDBus/QDBusInterface>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct roomEventId
|
2018-05-05 22:40:24 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
QString roomId;
|
|
|
|
QString eventId;
|
2018-07-11 17:33:02 +03:00
|
|
|
};
|
|
|
|
|
2020-04-09 21:52:50 +03:00
|
|
|
inline bool
|
|
|
|
operator==(const roomEventId &a, const roomEventId &b)
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
return a.roomId == b.roomId && a.eventId == b.eventId;
|
2020-04-09 21:52:50 +03:00
|
|
|
}
|
|
|
|
|
2022-10-10 15:38:29 +03:00
|
|
|
class NotificationsManager final : public QObject
|
2018-07-11 17:33:02 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
Q_OBJECT
|
2018-05-05 22:40:24 +03:00
|
|
|
public:
|
2021-09-18 01:22:33 +03:00
|
|
|
NotificationsManager(QObject *parent = nullptr);
|
2018-07-11 17:33:02 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
void postNotification(const mtx::responses::Notification ¬ification, const QImage &icon);
|
2018-07-11 17:33:02 +03:00
|
|
|
|
2022-10-13 18:19:54 +03:00
|
|
|
void removeNotification(const QString &roomId, const QString &eventId);
|
|
|
|
|
2018-07-11 17:33:02 +03:00
|
|
|
signals:
|
2021-09-18 01:22:33 +03:00
|
|
|
void notificationClicked(const QString roomId, const QString eventId);
|
|
|
|
void sendNotificationReply(const QString roomId, const QString eventId, const QString body);
|
|
|
|
void systemPostNotificationCb(const QString &room_id,
|
|
|
|
const QString &event_id,
|
|
|
|
const QString &roomName,
|
|
|
|
const QString &text,
|
|
|
|
const QImage &icon);
|
2018-07-11 17:33:02 +03:00
|
|
|
|
2020-04-09 21:52:50 +03:00
|
|
|
public slots:
|
2022-10-13 18:19:54 +03:00
|
|
|
void removeNotifications(const QString &roomId, const std::vector<QString> &eventId);
|
2020-04-09 21:52:50 +03:00
|
|
|
|
2021-03-17 21:17:57 +03:00
|
|
|
#if defined(NHEKO_DBUS_SYS)
|
2020-04-09 21:52:50 +03:00
|
|
|
public:
|
2021-09-18 01:22:33 +03:00
|
|
|
void closeNotifications(QString roomId);
|
2020-04-09 21:52:50 +03:00
|
|
|
|
2018-07-11 17:33:02 +03:00
|
|
|
private:
|
2021-09-18 01:22:33 +03:00
|
|
|
QDBusInterface dbus;
|
2021-03-17 21:17:57 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
void systemPostNotification(const QString &room_id,
|
|
|
|
const QString &event_id,
|
|
|
|
const QString &roomName,
|
|
|
|
const QString &text,
|
|
|
|
const QImage &icon);
|
|
|
|
void closeNotification(uint id);
|
2018-07-11 17:33:02 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
const bool hasMarkup_;
|
|
|
|
const bool hasImages_;
|
2021-03-17 21:17:57 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(Q_OS_MACOS)
|
|
|
|
private:
|
2021-09-18 01:22:33 +03:00
|
|
|
// Objective-C(++) doesn't like to do lots of regular C++, so the actual notification
|
|
|
|
// posting is split out
|
2021-11-02 03:48:51 +03:00
|
|
|
void objCxxPostNotification(const QString &room_name,
|
|
|
|
const QString &room_id,
|
|
|
|
const QString &event_id,
|
2021-09-18 01:22:33 +03:00
|
|
|
const QString &subtitle,
|
|
|
|
const QString &informativeText,
|
2022-11-04 19:42:09 +03:00
|
|
|
const QString &bodyImagePath,
|
|
|
|
const QString &respondStr,
|
|
|
|
const QString &sendStr,
|
|
|
|
const QString &placeholder);
|
|
|
|
|
|
|
|
public:
|
|
|
|
static void attachToMacNotifCenter();
|
2021-03-17 21:17:57 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(Q_OS_WINDOWS)
|
|
|
|
private:
|
2021-11-22 02:32:49 +03:00
|
|
|
void
|
|
|
|
systemPostNotification(const QString &line1, const QString &line2, const QString &iconPath);
|
2018-07-11 17:33:02 +03:00
|
|
|
#endif
|
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
// these slots are platform specific (D-Bus only)
|
|
|
|
// but Qt slot declarations can not be inside an ifdef!
|
2018-07-11 17:33:02 +03:00
|
|
|
private slots:
|
2021-09-18 01:22:33 +03:00
|
|
|
void actionInvoked(uint id, QString action);
|
|
|
|
void notificationClosed(uint id, uint reason);
|
|
|
|
void notificationReplied(uint id, QString reply);
|
2021-03-17 21:08:17 +03:00
|
|
|
|
|
|
|
private:
|
2021-09-18 01:22:33 +03:00
|
|
|
QString getMessageTemplate(const mtx::responses::Notification ¬ification);
|
2022-10-13 18:19:54 +03:00
|
|
|
|
|
|
|
// notification ID to (room ID, event ID)
|
|
|
|
// Only populated on Linux atm
|
|
|
|
QMap<uint, roomEventId> notificationIds;
|
2018-05-05 22:40:24 +03:00
|
|
|
};
|
2018-07-11 17:33:02 +03:00
|
|
|
|
2021-03-17 21:17:57 +03:00
|
|
|
#if defined(NHEKO_DBUS_SYS)
|
2018-07-11 17:33:02 +03:00
|
|
|
QDBusArgument &
|
|
|
|
operator<<(QDBusArgument &arg, const QImage &image);
|
|
|
|
const QDBusArgument &
|
|
|
|
operator>>(const QDBusArgument &arg, QImage &);
|
|
|
|
#endif
|