mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 19:08:58 +03:00
Fix notification not being cleared, when read event didn't cause a notification
This commit is contained in:
parent
2b24a978e1
commit
82ec022f9c
2 changed files with 17 additions and 34 deletions
|
@ -1,6 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QHash>
|
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
@ -16,27 +15,12 @@ struct roomEventId
|
||||||
QString eventId;
|
QString eventId;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool
|
|
||||||
operator<(const roomEventId &a, const roomEventId &b)
|
|
||||||
{
|
|
||||||
if (a.roomId == b.roomId)
|
|
||||||
return a.eventId < b.eventId;
|
|
||||||
else
|
|
||||||
return a.roomId < b.roomId;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
operator==(const roomEventId &a, const roomEventId &b)
|
operator==(const roomEventId &a, const roomEventId &b)
|
||||||
{
|
{
|
||||||
return a.roomId == b.roomId && a.eventId == b.eventId;
|
return a.roomId == b.roomId && a.eventId == b.eventId;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint
|
|
||||||
qHash(const roomEventId &v, uint seed)
|
|
||||||
{
|
|
||||||
return qHash(v.roomId, seed) ^ qHash(v.eventId, seed);
|
|
||||||
}
|
|
||||||
|
|
||||||
class NotificationsManager : public QObject
|
class NotificationsManager : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -67,7 +51,6 @@ private:
|
||||||
|
|
||||||
// notification ID to (room ID, event ID)
|
// notification ID to (room ID, event ID)
|
||||||
QMap<uint, roomEventId> notificationIds;
|
QMap<uint, roomEventId> notificationIds;
|
||||||
QHash<roomEventId, uint> eventToNotificationId;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// these slots are platform specific (D-Bus only)
|
// these slots are platform specific (D-Bus only)
|
||||||
|
|
|
@ -40,7 +40,6 @@ NotificationsManager::postNotification(const QString &roomid,
|
||||||
{
|
{
|
||||||
uint id = showNotification(roomname, sender + ": " + text, icon);
|
uint id = showNotification(roomname, sender + ": " + text, icon);
|
||||||
notificationIds[id] = roomEventId{roomid, eventid};
|
notificationIds[id] = roomEventId{roomid, eventid};
|
||||||
eventToNotificationId[roomEventId{roomid, eventid}] = id;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* This function is based on code from
|
* This function is based on code from
|
||||||
|
@ -98,23 +97,24 @@ NotificationsManager::closeNotification(uint id)
|
||||||
|
|
||||||
void
|
void
|
||||||
NotificationsManager::removeNotification(const QString &roomId, const QString &eventId)
|
NotificationsManager::removeNotification(const QString &roomId, const QString &eventId)
|
||||||
{
|
|
||||||
roomEventId reId = {roomId, eventId};
|
|
||||||
if (eventToNotificationId.contains(reId)) {
|
|
||||||
for (auto elem = notificationIds.begin(); elem != notificationIds.end(); ++elem) {
|
|
||||||
if (elem.value().roomId != roomId)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// close all notifications matching the eventId or having a lower
|
roomEventId reId = {roomId, eventId};
|
||||||
// notificationId
|
for (auto elem = notificationIds.begin(); elem != notificationIds.end(); ++elem) {
|
||||||
// This relies on the notificationId not wrapping around. This allows for
|
if (elem.value().roomId != roomId)
|
||||||
// approximately 2,147,483,647 notifications, so it is a bit unlikely.
|
continue;
|
||||||
// Otherwise we would need to store a 64bit counter instead.
|
|
||||||
closeNotification(elem.key());
|
|
||||||
|
|
||||||
if (elem.value() == reId)
|
// close all notifications matching the eventId or having a lower
|
||||||
break;
|
// notificationId
|
||||||
}
|
// This relies on the notificationId not wrapping around. This allows for
|
||||||
|
// approximately 2,147,483,647 notifications, so it is a bit unlikely.
|
||||||
|
// Otherwise we would need to store a 64bit counter instead.
|
||||||
|
closeNotification(elem.key());
|
||||||
|
|
||||||
|
// FIXME: compare index of event id of the read receipt and the notification instead of just
|
||||||
|
// the id to prevent read receipts of events without notification clearing all notifications
|
||||||
|
// in that room!
|
||||||
|
if (elem.value() == reId)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ void
|
||||||
NotificationsManager::notificationClosed(uint id, uint reason)
|
NotificationsManager::notificationClosed(uint id, uint reason)
|
||||||
{
|
{
|
||||||
Q_UNUSED(reason);
|
Q_UNUSED(reason);
|
||||||
eventToNotificationId.remove(notificationIds.take(id));
|
notificationIds.remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue