Improve the handling of notifications
The aim is to put some additional filtering in place to better stop floods of old notifications. This is achieved with a couple of new filters and better tracking of old notifications. - Make sure to paginate through all notification on initialization to ensure they are all added to old notifications. While we were not previously putting a limit on the number of returned notifications the server can and will do this when there are a very large amount. - Find the newest timestamp for each connection on initialization and don't post any notifications with an earlier timestamp. - Track old notifications on a per-connection basis. Closes network/neochat#358 and network/neochat#423
This commit is contained in:
@@ -4,11 +4,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <QImage>
|
||||
#include <QJsonObject>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
#include <QString>
|
||||
#include <QJsonObject>
|
||||
#include <csapi/notifications.h>
|
||||
#include <jobs/basejob.h>
|
||||
|
||||
namespace Quotient
|
||||
{
|
||||
class Connection;
|
||||
}
|
||||
|
||||
class KNotification;
|
||||
class NeoChatRoom;
|
||||
@@ -181,9 +188,23 @@ public:
|
||||
*/
|
||||
QVector<QVariant> getKeywordNotificationActions();
|
||||
|
||||
#ifdef QUOTIENT_07
|
||||
/**
|
||||
* @brief Handle the notifications for the given connection.
|
||||
*/
|
||||
void handleNotifications(QPointer<Quotient::Connection> connection);
|
||||
#endif
|
||||
|
||||
private:
|
||||
NotificationsManager(QObject *parent = nullptr);
|
||||
|
||||
QHash<QString, qint64> m_initialTimestamp;
|
||||
QHash<QString, QStringList> m_oldNotifications;
|
||||
|
||||
QStringList m_connActiveJob;
|
||||
|
||||
bool shouldPostNotification(QPointer<Quotient::Connection> connection, const QJsonValue ¬ification);
|
||||
|
||||
QHash<QString, KNotification *> m_notifications;
|
||||
QHash<QString, QPointer<KNotification>> m_invitations;
|
||||
|
||||
@@ -218,6 +239,8 @@ private:
|
||||
QVector<QVariant> toActions(PushNotificationAction::Action action, const QString &sound = "default");
|
||||
|
||||
private Q_SLOTS:
|
||||
void processNotificationJob(QPointer<Quotient::Connection> connection, Quotient::GetNotificationsJob *job, bool initialization);
|
||||
|
||||
void updateNotificationRules(const QString &type);
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
Reference in New Issue
Block a user