File indexing completed on 2024-12-08 07:33:43

0001 // SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com>
0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0003 
0004 #pragma once
0005 
0006 #include <QObject>
0007 #include <QQmlEngine>
0008 
0009 /**
0010  * @class PushRuleKind
0011  *
0012  * A class with the Kind enum for push notifications and helper functions.
0013  *
0014  * The kind relates to the kinds of push rule defined in the matrix spec, see
0015  * https://spec.matrix.org/v1.7/client-server-api/#push-rules for full details.
0016  */
0017 class PushRuleKind : public QObject
0018 {
0019     Q_OBJECT
0020     QML_ELEMENT
0021     QML_UNCREATABLE("")
0022 
0023 public:
0024     /**
0025      * @brief Defines the different kinds of push rule.
0026      */
0027     enum Kind {
0028         Override = 0, /**< The highest priority rules. */
0029         Content, /**< These configure behaviour for messages that match certain patterns. */
0030         Room, /**< These rules change the behaviour of all messages for a given room. */
0031         Sender, /**< These rules configure notification behaviour for messages from a specific Matrix user ID. */
0032         Underride, /**< These are identical to override rules, but have a lower priority than content, room and sender rules. */
0033     };
0034     Q_ENUM(Kind)
0035 
0036     /**
0037      * @brief Translate the Kind enum value to a human readable string.
0038      *
0039      * @sa Kind
0040      */
0041     static QString kindString(Kind kind)
0042     {
0043         switch (kind) {
0044         case Kind::Override:
0045             return QLatin1String("override");
0046         case Kind::Content:
0047             return QLatin1String("content");
0048         case Kind::Room:
0049             return QLatin1String("room");
0050         case Kind::Sender:
0051             return QLatin1String("sender");
0052         case Kind::Underride:
0053             return QLatin1String("underride");
0054         default:
0055             return {};
0056         }
0057     };
0058 };
0059 
0060 /**
0061  * @class PushRuleAction
0062  *
0063  * A class with the Action enum for push notifications.
0064  *
0065  * The action relates to the actions of push rule defined in the matrix spec, see
0066  * https://spec.matrix.org/v1.7/client-server-api/#push-rules for full details.
0067  */
0068 class PushRuleAction : public QObject
0069 {
0070     Q_OBJECT
0071     QML_ELEMENT
0072     QML_UNCREATABLE("")
0073 
0074 public:
0075     /**
0076      * @brief Defines the global push notification actions.
0077      */
0078     enum Action {
0079         Unknown = 0, /**< The action has not yet been obtained from the server. */
0080         Off, /**< No push notifications are to be sent. */
0081         On, /**< Push notifications are on. */
0082         Noisy, /**< Push notifications are on, also trigger a notification sound. */
0083         Highlight, /**< Push notifications are on, also the event should be highlighted in chat. */
0084         NoisyHighlight, /**< Push notifications are on, also trigger a notification sound and highlight in chat. */
0085     };
0086     Q_ENUM(Action)
0087 };
0088 
0089 /**
0090  * @class PushNotificationState
0091  *
0092  * A class with the State enum for room push notification state.
0093  *
0094  * The state define whether the room adheres to the global push rule states for the
0095  * account or is overridden for a room.
0096  *
0097  * @note This is different to the PushRuleAction which defines the type of notification
0098  *       for an individual rule.
0099  *
0100  * @sa PushRuleAction
0101  */
0102 class PushNotificationState : public QObject
0103 {
0104     Q_OBJECT
0105     QML_ELEMENT
0106     QML_UNCREATABLE("")
0107 
0108 public:
0109     /**
0110      * @brief Describes the push notification state for the room.
0111      */
0112     enum State {
0113         Unknown, /**< The state has not yet been obtained from the server. */
0114         Default, /**< The room follows the globally configured rules for the local user. */
0115         Mute, /**< No notifications for messages in the room. */
0116         MentionKeyword, /**< Notifications only for local user mentions and keywords. */
0117         All, /**< Notifications for all messages. */
0118     };
0119     Q_ENUM(State)
0120 };
0121 
0122 /**
0123  * @class PushRuleSection
0124  *
0125  * A class with the Section enum for push notifications and helper functions.
0126  *
0127  * @note This is different from the PushRuleKind and instead is used for sorting
0128  *       in the settings page which is not necessarily by Kind.
0129  *
0130  * @sa PushRuleKind
0131  */
0132 class PushRuleSection : public QObject
0133 {
0134     Q_OBJECT
0135     QML_ELEMENT
0136     QML_UNCREATABLE("")
0137 
0138 public:
0139     /**
0140      * @brief Defines the sections to sort push rules into.
0141      */
0142     enum Section {
0143         Master = 0, /**< The master push rule */
0144         Room, /**< Push rules relating to all rooms. */
0145         Mentions, /**< Push rules relating to user mentions. */
0146         Keywords, /**< Global Keyword push rules. */
0147         RoomKeywords, /**< Keyword push rules that only apply to a specific room. */
0148         Invites, /**< Push rules relating to invites. */
0149         Unknown, /**< New default push rules that have not been added to the model yet. */
0150         /**
0151          * @brief Push rules that should never be shown.
0152          *
0153          * There are numerous rules that get set that shouldn't be shown in the general
0154          * list e.g. The array of rules used to override global settings in individual
0155          * rooms.
0156          *
0157          * This is specifically different to unknown which are just new default push
0158          * rule that haven't been added to the model yet.
0159          */
0160         Undefined,
0161     };
0162     Q_ENUM(Section)
0163 
0164     /**
0165      * @brief Translate the Section enum value to a human readable string.
0166      *
0167      * @sa Section
0168      */
0169     static QString sectionString(Section section)
0170     {
0171         switch (section) {
0172         case Section::Master:
0173             return QLatin1String("Master");
0174         case Section::Room:
0175             return QLatin1String("Room Notifications");
0176         case Section::Mentions:
0177             return QLatin1String("@Mentions");
0178         case Section::Keywords:
0179             return QLatin1String("Keywords");
0180         case Section::Invites:
0181             return QLatin1String("Invites");
0182         default:
0183             return {};
0184         }
0185     };
0186 };