Consolidate messages belonging to the same chat
This commit is contained in:
parent
239af6e6e7
commit
7dd8e07a39
4 changed files with 40 additions and 4 deletions
|
@ -72,11 +72,28 @@ void NotificationManager::handleUpdateNotificationGroup(const QVariantMap notifi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we have deleted notifications, we need to update possibly existing ones
|
||||||
|
if (!removedNotificationIds.isEmpty() && !activeNotifications.isEmpty()) {
|
||||||
|
qDebug() << "[NotificationManager] Some removals happend, but we have " << activeNotifications.size() << "existing notifications.";
|
||||||
|
QVariantMap firstActiveNotification = activeNotifications.first().toMap();
|
||||||
|
activeNotifications.remove(firstActiveNotification.value("id").toString());
|
||||||
|
QVariantMap newFirstActiveNotification = this->sendNotification(chatId, firstActiveNotification, activeNotifications);
|
||||||
|
QVariantMap newActiveNotifications;
|
||||||
|
QListIterator<QVariant> activeNotificationsIterator(activeNotifications.values());
|
||||||
|
while (activeNotificationsIterator.hasNext()) {
|
||||||
|
QVariantMap newActiveNotification = activeNotificationsIterator.next().toMap();
|
||||||
|
newActiveNotification.insert("replaces_id", newFirstActiveNotification.value("replaces_id"));
|
||||||
|
newActiveNotifications.insert(newActiveNotification.value("id").toString(), newActiveNotification);
|
||||||
|
}
|
||||||
|
newActiveNotifications.insert(newFirstActiveNotification.value("id").toString(), newFirstActiveNotification);
|
||||||
|
activeNotifications = newActiveNotifications;
|
||||||
|
}
|
||||||
|
|
||||||
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();
|
||||||
QVariantMap activeNotification = this->sendNotification(chatId, addedNotification);
|
QVariantMap activeNotification = this->sendNotification(chatId, addedNotification, activeNotifications);
|
||||||
activeNotifications.insert(activeNotification.value("id").toString(), activeNotification);
|
activeNotifications.insert(activeNotification.value("id").toString(), activeNotification);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +114,7 @@ void NotificationManager::handleChatDiscovered(const QString &chatId, const QVar
|
||||||
this->chatListMutex.unlock();
|
this->chatListMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap NotificationManager::sendNotification(const QString &chatId, const QVariantMap ¬ificationInformation)
|
QVariantMap NotificationManager::sendNotification(const QString &chatId, const QVariantMap ¬ificationInformation, const QVariantMap &activeNotifications)
|
||||||
{
|
{
|
||||||
qDebug() << "[NotificationManager] Sending notification" << notificationInformation.value("id").toString();
|
qDebug() << "[NotificationManager] Sending notification" << notificationInformation.value("id").toString();
|
||||||
|
|
||||||
|
@ -110,7 +127,12 @@ QVariantMap NotificationManager::sendNotification(const QString &chatId, const Q
|
||||||
nemoNotification.setAppIcon(appIconUrl.toLocalFile());
|
nemoNotification.setAppIcon(appIconUrl.toLocalFile());
|
||||||
nemoNotification.setSummary(chatInformation.value("title").toString());
|
nemoNotification.setSummary(chatInformation.value("title").toString());
|
||||||
nemoNotification.setCategory("x-nemo.messaging.im");
|
nemoNotification.setCategory("x-nemo.messaging.im");
|
||||||
|
if (activeNotifications.isEmpty()) {
|
||||||
nemoNotification.setBody(this->getNotificationText(notificationInformation.value("type").toMap().value("message").toMap().value("content").toMap()));
|
nemoNotification.setBody(this->getNotificationText(notificationInformation.value("type").toMap().value("message").toMap().value("content").toMap()));
|
||||||
|
} else {
|
||||||
|
nemoNotification.setReplacesId(activeNotifications.first().toMap().value("replaces_id").toUInt());
|
||||||
|
nemoNotification.setBody(tr("%1 unread messages").arg(activeNotifications.size() + 1));
|
||||||
|
}
|
||||||
|
|
||||||
nemoNotification.publish();
|
nemoNotification.publish();
|
||||||
updatedNotificationInformation.insert("replaces_id", nemoNotification.replacesId());
|
updatedNotificationInformation.insert("replaces_id", nemoNotification.replacesId());
|
||||||
|
|
|
@ -48,7 +48,7 @@ private:
|
||||||
QVariantMap notificationGroups;
|
QVariantMap notificationGroups;
|
||||||
QMutex chatListMutex;
|
QMutex chatListMutex;
|
||||||
|
|
||||||
QVariantMap sendNotification(const QString &chatId, const QVariantMap ¬ificationInformation);
|
QVariantMap sendNotification(const QString &chatId, const QVariantMap ¬ificationInformation, const QVariantMap &activeNotifications);
|
||||||
void removeNotification(const QVariantMap ¬ificationInformation);
|
void removeNotification(const QVariantMap ¬ificationInformation);
|
||||||
QString getNotificationText(const QVariantMap ¬ificationContent);
|
QString getNotificationText(const QVariantMap ¬ificationContent);
|
||||||
|
|
||||||
|
|
|
@ -269,6 +269,13 @@
|
||||||
<translation>Authentifizierung neu starten</translation>
|
<translation>Authentifizierung neu starten</translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
|
<context>
|
||||||
|
<name>NotificationManager</name>
|
||||||
|
<message>
|
||||||
|
<source>%1 unread messages</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>OverviewPage</name>
|
<name>OverviewPage</name>
|
||||||
<message>
|
<message>
|
||||||
|
|
|
@ -269,6 +269,13 @@
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
|
<context>
|
||||||
|
<name>NotificationManager</name>
|
||||||
|
<message>
|
||||||
|
<source>%1 unread messages</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>OverviewPage</name>
|
<name>OverviewPage</name>
|
||||||
<message>
|
<message>
|
||||||
|
|
Loading…
Reference in a new issue