diff --git a/harbour-fernschreiber.pro b/harbour-fernschreiber.pro index 990d921..ebc9869 100644 --- a/harbour-fernschreiber.pro +++ b/harbour-fernschreiber.pro @@ -14,6 +14,8 @@ TARGET = harbour-fernschreiber CONFIG += sailfishapp sailfishapp_i18n +PKGCONFIG += nemonotifications-qt5 + QT += core dbus SOURCES += src/harbour-fernschreiber.cpp \ diff --git a/images/fernschreiber-notification.png b/images/fernschreiber-notification.png new file mode 100644 index 0000000..bc4e29c Binary files /dev/null and b/images/fernschreiber-notification.png differ diff --git a/src/notificationmanager.cpp b/src/notificationmanager.cpp index bb8fa2f..812ce68 100644 --- a/src/notificationmanager.cpp +++ b/src/notificationmanager.cpp @@ -18,6 +18,11 @@ */ #include "notificationmanager.h" +#include +#include +#include +#include +#include NotificationManager::NotificationManager(TDLibWrapper *tdLibWrapper, QObject *parent) : QObject(parent) { @@ -42,7 +47,32 @@ void NotificationManager::handleUpdateActiveNotifications(const QVariantList not void NotificationManager::handleUpdateNotificationGroup(const QVariantMap notificationGroupUpdate) { - qDebug() << "[NotificationManager] Received notification group update, group ID:" << notificationGroupUpdate.value("notification_group_id").toInt(); + QString notificationGroupId = notificationGroupUpdate.value("notification_group_id").toString(); + qDebug() << "[NotificationManager] Received notification group update, group ID:" << notificationGroupId; + QVariantMap notificationGroup = this->notificationGroups.value(notificationGroupId).toMap(); + + notificationGroup.insert("type", notificationGroupUpdate.value("type")); + notificationGroup.insert("chat_id", notificationGroupUpdate.value("chat_id")); + notificationGroup.insert("notification_settings_chat_id", notificationGroupUpdate.value("notification_settings_chat_id")); + notificationGroup.insert("is_silent", notificationGroupUpdate.value("is_silent")); + notificationGroup.insert("total_count", notificationGroupUpdate.value("total_count")); + + QVariantMap notifications = notificationGroup.value("notifications").toMap(); + QVariantList addedNotifications = notificationGroupUpdate.value("added_notifications").toList(); + QListIterator addedNotificationIterator(addedNotifications); + while (addedNotificationIterator.hasNext()) { + QVariantMap addedNotification = addedNotificationIterator.next().toMap(); + notifications.insert(addedNotification.value("id").toString(), addedNotification); + } + QVariantList removedNotifications = notificationGroupUpdate.value("removed_notification_ids").toList(); + QListIterator removedNotificationIterator(removedNotifications); + while (removedNotificationIterator.hasNext()) { + QString removedNotificationId = removedNotificationIterator.next().toString(); + notifications.remove(removedNotificationId); + } + notificationGroup.insert("notifications", notifications); + this->notificationGroups.insert(notificationGroupId, notificationGroup); + // this->sendNotifications(); } void NotificationManager::handleUpdateNotification(const QVariantMap updatedNotification) @@ -57,3 +87,21 @@ void NotificationManager::handleChatDiscovered(const QString &chatId, const QVar this->chatMap.insert(chatId, chatInformation); this->chatListMutex.unlock(); } + +void NotificationManager::sendNotifications() +{ + QVariantList notificationGroupList = this->notificationGroups.values(); + QListIterator notificationGroupIterator(notificationGroupList); + QUrl appIconUrl = SailfishApp::pathTo("images/fernschreiber-notification.png"); + while (notificationGroupIterator.hasNext()) { + QVariantMap notificationGroup = notificationGroupIterator.next().toMap(); + Notification nemoNotification; + nemoNotification.setAppName("Fernschreiber"); + nemoNotification.setAppIcon(appIconUrl.toLocalFile()); + nemoNotification.setBody("This is the body"); + nemoNotification.setSummary("This is the summary"); + nemoNotification.setPreviewSummary("This is the preview summary"); + nemoNotification.setPreviewBody("This is the preview body"); + nemoNotification.publish(); + } +} diff --git a/src/notificationmanager.h b/src/notificationmanager.h index c28d0c7..3117372 100644 --- a/src/notificationmanager.h +++ b/src/notificationmanager.h @@ -45,8 +45,11 @@ private: TDLibWrapper *tdLibWrapper; QVariantMap chatMap; + QVariantMap notificationGroups; QMutex chatListMutex; + void sendNotifications(); + }; #endif // NOTIFICATIONMANAGER_H