Sending simple text notifications, yeah!
This commit is contained in:
parent
8809372b67
commit
239af6e6e7
2 changed files with 53 additions and 26 deletions
|
@ -51,28 +51,37 @@ void NotificationManager::handleUpdateNotificationGroup(const QVariantMap notifi
|
||||||
qDebug() << "[NotificationManager] Received notification group update, group ID:" << notificationGroupId;
|
qDebug() << "[NotificationManager] Received notification group update, group ID:" << notificationGroupId;
|
||||||
QVariantMap notificationGroup = this->notificationGroups.value(notificationGroupId).toMap();
|
QVariantMap notificationGroup = this->notificationGroups.value(notificationGroupId).toMap();
|
||||||
|
|
||||||
|
QString chatId = notificationGroupUpdate.value("chat_id").toString();
|
||||||
notificationGroup.insert("type", notificationGroupUpdate.value("type"));
|
notificationGroup.insert("type", notificationGroupUpdate.value("type"));
|
||||||
notificationGroup.insert("chat_id", notificationGroupUpdate.value("chat_id"));
|
notificationGroup.insert("chat_id", chatId);
|
||||||
|
notificationGroup.insert("notification_group_id", notificationGroupId);
|
||||||
notificationGroup.insert("notification_settings_chat_id", notificationGroupUpdate.value("notification_settings_chat_id"));
|
notificationGroup.insert("notification_settings_chat_id", notificationGroupUpdate.value("notification_settings_chat_id"));
|
||||||
notificationGroup.insert("is_silent", notificationGroupUpdate.value("is_silent"));
|
notificationGroup.insert("is_silent", notificationGroupUpdate.value("is_silent"));
|
||||||
notificationGroup.insert("total_count", notificationGroupUpdate.value("total_count"));
|
notificationGroup.insert("total_count", notificationGroupUpdate.value("total_count"));
|
||||||
|
|
||||||
QVariantMap notifications = notificationGroup.value("notifications").toMap();
|
QVariantMap activeNotifications = notificationGroup.value("notifications").toMap();
|
||||||
|
|
||||||
|
QVariantList removedNotificationIds = notificationGroupUpdate.value("removed_notification_ids").toList();
|
||||||
|
QListIterator<QVariant> removedNotificationsIterator(removedNotificationIds);
|
||||||
|
while (removedNotificationsIterator.hasNext()) {
|
||||||
|
QString removedNotificationId = removedNotificationsIterator.next().toString();
|
||||||
|
QVariantMap notificationInformation = activeNotifications.value(removedNotificationId).toMap();
|
||||||
|
if (!notificationInformation.isEmpty()) {
|
||||||
|
this->removeNotification(notificationInformation);
|
||||||
|
activeNotifications.remove(removedNotificationId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QVariantList addedNotifications = notificationGroupUpdate.value("added_notifications").toList();
|
QVariantList addedNotifications = notificationGroupUpdate.value("added_notifications").toList();
|
||||||
QListIterator<QVariant> addedNotificationIterator(addedNotifications);
|
QListIterator<QVariant> addedNotificationIterator(addedNotifications);
|
||||||
while (addedNotificationIterator.hasNext()) {
|
while (addedNotificationIterator.hasNext()) {
|
||||||
QVariantMap addedNotification = addedNotificationIterator.next().toMap();
|
QVariantMap addedNotification = addedNotificationIterator.next().toMap();
|
||||||
notifications.insert(addedNotification.value("id").toString(), addedNotification);
|
QVariantMap activeNotification = this->sendNotification(chatId, addedNotification);
|
||||||
|
activeNotifications.insert(activeNotification.value("id").toString(), activeNotification);
|
||||||
}
|
}
|
||||||
QVariantList removedNotifications = notificationGroupUpdate.value("removed_notification_ids").toList();
|
|
||||||
QListIterator<QVariant> removedNotificationIterator(removedNotifications);
|
notificationGroup.insert("notifications", activeNotifications);
|
||||||
while (removedNotificationIterator.hasNext()) {
|
|
||||||
QString removedNotificationId = removedNotificationIterator.next().toString();
|
|
||||||
notifications.remove(removedNotificationId);
|
|
||||||
}
|
|
||||||
notificationGroup.insert("notifications", notifications);
|
|
||||||
this->notificationGroups.insert(notificationGroupId, notificationGroup);
|
this->notificationGroups.insert(notificationGroupId, notificationGroup);
|
||||||
// this->sendNotifications();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationManager::handleUpdateNotification(const QVariantMap updatedNotification)
|
void NotificationManager::handleUpdateNotification(const QVariantMap updatedNotification)
|
||||||
|
@ -88,20 +97,36 @@ void NotificationManager::handleChatDiscovered(const QString &chatId, const QVar
|
||||||
this->chatListMutex.unlock();
|
this->chatListMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationManager::sendNotifications()
|
QVariantMap NotificationManager::sendNotification(const QString &chatId, const QVariantMap ¬ificationInformation)
|
||||||
{
|
{
|
||||||
QVariantList notificationGroupList = this->notificationGroups.values();
|
qDebug() << "[NotificationManager] Sending notification" << notificationInformation.value("id").toString();
|
||||||
QListIterator<QVariant> notificationGroupIterator(notificationGroupList);
|
|
||||||
|
QVariantMap chatInformation = this->chatMap.value(chatId).toMap();
|
||||||
|
|
||||||
|
QVariantMap updatedNotificationInformation = notificationInformation;
|
||||||
QUrl appIconUrl = SailfishApp::pathTo("images/fernschreiber-notification.png");
|
QUrl appIconUrl = SailfishApp::pathTo("images/fernschreiber-notification.png");
|
||||||
while (notificationGroupIterator.hasNext()) {
|
Notification nemoNotification;
|
||||||
QVariantMap notificationGroup = notificationGroupIterator.next().toMap();
|
nemoNotification.setAppName("Fernschreiber");
|
||||||
Notification nemoNotification;
|
nemoNotification.setAppIcon(appIconUrl.toLocalFile());
|
||||||
nemoNotification.setAppName("Fernschreiber");
|
nemoNotification.setSummary(chatInformation.value("title").toString());
|
||||||
nemoNotification.setAppIcon(appIconUrl.toLocalFile());
|
nemoNotification.setCategory("x-nemo.messaging.im");
|
||||||
nemoNotification.setBody("This is the body");
|
nemoNotification.setBody(this->getNotificationText(notificationInformation.value("type").toMap().value("message").toMap().value("content").toMap()));
|
||||||
nemoNotification.setSummary("This is the summary");
|
|
||||||
nemoNotification.setPreviewSummary("This is the preview summary");
|
nemoNotification.publish();
|
||||||
nemoNotification.setPreviewBody("This is the preview body");
|
updatedNotificationInformation.insert("replaces_id", nemoNotification.replacesId());
|
||||||
nemoNotification.publish();
|
return updatedNotificationInformation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NotificationManager::removeNotification(const QVariantMap ¬ificationInformation)
|
||||||
|
{
|
||||||
|
qDebug() << "[NotificationManager] Removing notification" << notificationInformation.value("id").toString();
|
||||||
|
Notification nemoNotification;
|
||||||
|
nemoNotification.setReplacesId(notificationInformation.value("replaces_id").toUInt());
|
||||||
|
nemoNotification.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString NotificationManager::getNotificationText(const QVariantMap ¬ificationContent)
|
||||||
|
{
|
||||||
|
qDebug() << "[NotificationManager] Getting notification text from content" << notificationContent;
|
||||||
|
return notificationContent.value("text").toMap().value("text").toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,9 @@ private:
|
||||||
QVariantMap notificationGroups;
|
QVariantMap notificationGroups;
|
||||||
QMutex chatListMutex;
|
QMutex chatListMutex;
|
||||||
|
|
||||||
void sendNotifications();
|
QVariantMap sendNotification(const QString &chatId, const QVariantMap ¬ificationInformation);
|
||||||
|
void removeNotification(const QVariantMap ¬ificationInformation);
|
||||||
|
QString getNotificationText(const QVariantMap ¬ificationContent);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue