diff --git a/src/notifications/managerwin.cpp b/src/notifications/managerwin.cpp index 094fe64..852d2dd 100644 --- a/src/notifications/managerwin.cpp +++ b/src/notifications/managerwin.cpp @@ -5,16 +5,23 @@ using namespace WinToastLib; class CustomHandler : public IWinToastHandler { public: - void toastActivated() const {} - void toastActivated(int) const {} - void toastFailed() const { + void toastActivated() { emit activated(notificationID); } + void toastActivated(int) { emit activated(notificationID); } + void toastFailed() { std::wcout << L"Error showing current toast" << std::endl; } - void toastDismissed(WinToastDismissalReason) const {} + void toastDismissed(WinToastDismissalReason) { emit dismissed(notificationID); } + + uint notificationID; + +signals: + void activated(uint id); + void dismissed(uint id); }; namespace { bool isInitialized = false; +uint count = 0; void init() { isInitialized = true; @@ -51,9 +58,27 @@ void NotificationsManager::postNotification( // TODO: implement room or user avatar // templ.setImagePath(L"C:/example.png"); - WinToast::instance()->showToast(templ, new CustomHandler()); + CustomHandler* customHandler = new CustomHandler(); + count++; + customHandler->notificationID = count; + notificationIds[count] = roomEventId{room_id, event_id}; + connect(customHandler, &CustomHandler::activated, this, [=](uint id) { + this->actionInvoked(id, ""); + }); + connect(customHandler, &CustomHandler::dismissed, this, [=](uint id) { + this->notificationClosed(id, 0); + }); + + WinToast::instance()->showToast(templ, customHandler); } -void NotificationsManager::actionInvoked(uint, QString) {} +void NotificationsManager::actionInvoked(uint id, QString action) { + if (notificationIds.contains(id)) { + roomEventId idEntry = notificationIds[id]; + emit notificationClicked(idEntry.roomId, idEntry.eventId); + } +} -void NotificationsManager::notificationClosed(uint, uint) {} +void NotificationsManager::notificationClosed(uint id, uint reason) { + notificationIds.remove(id); +} diff --git a/src/notifications/wintoastlib.h b/src/notifications/wintoastlib.h index e991d66..710d2db 100644 --- a/src/notifications/wintoastlib.h +++ b/src/notifications/wintoastlib.h @@ -36,10 +36,10 @@ namespace WinToastLib { TimedOut = ToastDismissalReason::ToastDismissalReason_TimedOut }; virtual ~IWinToastHandler() {} - virtual void toastActivated() const = 0; - virtual void toastActivated(int actionIndex) const = 0; - virtual void toastDismissed(WinToastDismissalReason state) const = 0; - virtual void toastFailed() const = 0; + virtual void toastActivated() = 0; + virtual void toastActivated(int actionIndex) = 0; + virtual void toastDismissed(WinToastDismissalReason state) = 0; + virtual void toastFailed() = 0; }; class WinToastTemplate { diff --git a/src/roomlistmodel.cpp b/src/roomlistmodel.cpp index 2d20532..1c1ec87 100644 --- a/src/roomlistmodel.cpp +++ b/src/roomlistmodel.cpp @@ -83,7 +83,7 @@ void RoomListModel::connectRoomSignals(SpectralRoom* room) { emit newMessage(room->id(), event->id(), room->displayName(), sender->displayname(), event->contentJson().value("body").toString(), - room->avatar(64)); + room->avatar(128)); }); }