Implement new model, hooks and reconcilation code for new GYU notification settings (#11089)

* Define new notification settings model

* Add new hooks

* make ts-strict happy

* add unit tests

* chore: make eslint/prettier happier :)

* make ts-strict happier

* Update src/notifications/NotificationUtils.ts

Co-authored-by: Robin <robin@robin.town>

* Add tests for hooks

* chore: fixed lint issues

* Add comments

---------

Co-authored-by: Robin <robin@robin.town>
This commit is contained in:
Janne Mareike Koschinski 2023-06-17 02:17:51 +02:00 committed by GitHub
parent 2972219959
commit 97765613bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 2383 additions and 6 deletions

View file

@ -16,7 +16,7 @@ limitations under the License.
import { PushRuleAction, PushRuleActionName, TweakHighlight, TweakSound } from "matrix-js-sdk/src/@types/PushRules";
interface IEncodedActions {
export interface PushRuleActions {
notify: boolean;
sound?: string;
highlight?: boolean;
@ -29,7 +29,7 @@ export class NotificationUtils {
// "highlight: true/false,
// }
// to a list of push actions.
public static encodeActions(action: IEncodedActions): PushRuleAction[] {
public static encodeActions(action: PushRuleActions): PushRuleAction[] {
const notify = action.notify;
const sound = action.sound;
const highlight = action.highlight;
@ -55,13 +55,12 @@ export class NotificationUtils {
// "highlight: true/false,
// }
// If the actions couldn't be decoded then returns null.
public static decodeActions(actions: PushRuleAction[]): IEncodedActions | null {
public static decodeActions(actions: PushRuleAction[]): PushRuleActions | null {
let notify = false;
let sound: string | undefined;
let highlight: boolean | undefined = false;
for (let i = 0; i < actions.length; ++i) {
const action = actions[i];
for (const action of actions) {
if (action === PushRuleActionName.Notify) {
notify = true;
} else if (action === PushRuleActionName.DontNotify) {
@ -86,7 +85,7 @@ export class NotificationUtils {
highlight = true;
}
const result: IEncodedActions = { notify, highlight };
const result: PushRuleActions = { notify, highlight };
if (sound !== undefined) {
result.sound = sound;
}