Initial work to add push rule support

This commit adds the ability to set the master push rule and set push rules for individual rooms as per the matrix spec. See https://spec.matrix.org/v1.3/client-server-api/#push-rules.

The master push rule is just on/off and uses the existing notification setting in general setting to enable/disable the server default master push rule .m.rule.master.

For each room there is now a page in the room setting that allows the following to be set:
- Default
- All messages
- @mentions and keywords
- off

New room or override rules are added/removed to achieve this.

There is also functionality to check the master/room notification state whenever the setting menu is entered. This allows the status to be updated if changed in another client or get the initial state for a room as it isn't stored.

Note - There is currently no menu items in the room list for setting the room push rule settings. This will be added in a later commit, the aim is to focus on making sure the technical implementation is good for now.
This commit is contained in:
James Graham
2022-09-09 16:41:03 +00:00
parent c2fc4e44a7
commit 4bba505da6
11 changed files with 353 additions and 5 deletions

View File

@@ -23,6 +23,21 @@
using namespace Quotient;
class PushNotificationState : public QObject
{
Q_OBJECT
public:
enum State {
Unknown,
Default,
Mute,
MentionKeyword,
All,
};
Q_ENUM(State);
};
class NeoChatRoom : public Room
{
Q_OBJECT
@@ -36,6 +51,8 @@ class NeoChatRoom : public Room
Q_PROPERTY(bool isInvite READ isInvite NOTIFY isInviteChanged)
Q_PROPERTY(QString joinRule READ joinRule CONSTANT)
Q_PROPERTY(QString htmlSafeDisplayName READ htmlSafeDisplayName NOTIFY displayNameChanged)
Q_PROPERTY(PushNotificationState::State pushNotificationState MEMBER m_currentPushNotificationState WRITE setPushNotificationState NOTIFY
pushNotificationStateChanged)
public:
explicit NeoChatRoom(Connection *connection, QString roomId, JoinState joinState = {});
@@ -131,6 +148,8 @@ public:
Q_INVOKABLE QString htmlSafeDisplayName() const;
Q_INVOKABLE void clearInvitationNotification();
Q_INVOKABLE void setPushNotificationState(PushNotificationState::State state);
#ifndef QUOTIENT_07
Q_INVOKABLE QString htmlSafeMemberName(const QString &userId) const
{
@@ -145,6 +164,9 @@ private:
bool m_hasFileUploading = false;
int m_fileUploadingProgress = 0;
PushNotificationState::State m_currentPushNotificationState = PushNotificationState::State::Unknown;
bool m_pushNotificationStateUpdating = false;
void checkForHighlights(const Quotient::TimelineItem &ti);
void onAddNewTimelineEvents(timeline_iter_t from) override;
@@ -157,6 +179,7 @@ private:
private Q_SLOTS:
void countChanged();
void updatePushNotificationState(QString type);
Q_SIGNALS:
void cachedInputChanged();
@@ -168,6 +191,7 @@ Q_SIGNALS:
void lastActiveTimeChanged();
void isInviteChanged();
void displayNameChanged();
void pushNotificationStateChanged(PushNotificationState::State state);
public Q_SLOTS:
void uploadFile(const QUrl &url, const QString &body = QString());