This repository has been archived by the owner on May 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an early structure for notification processing
The general idea is that the room service will call into the notification service for each renderable event. This offloads push rule calculations to the notification service. Notifications and unread counts are both going to be calculated client side. Therefore we can ignore the server values in the sync response. This is because issues like [element-hq/element-web#3363] are inevitable if we try and do a mix of server and client processing. However, to get to that point we need read receipts so we can see what we've read and what we haven't read. Ideally this reliance on read receipts will disappear when this is resolved: element-hq/riot-meta#66 The amount of interaction between the room service and notification service is still relatively undecided. It will call into the notification service for determining if something should notify, however the read receipt parsing needs to somehow update the notification count somewhere.
- Loading branch information
Showing
5 changed files
with
172 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Evelium - A matrix client | ||
* Copyright (C) 2018 Travis Ralston | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { AuthenticatedApi } from "./authenticated-api"; | ||
import { HttpClient } from "@angular/common/http"; | ||
import { AuthService } from "./auth.service"; | ||
import { Injectable } from "@angular/core"; | ||
import { AccountService } from "./account.service"; | ||
import { AccountDataEvent } from "../../models/matrix/events/account/account-data-event"; | ||
import { PushRulesEvent } from "../../models/matrix/events/account/m.push_rules"; | ||
|
||
// For singleton access | ||
let notificationsHandler: NotificationsHandler; | ||
|
||
// .m.rule.master - enabled=false means enabled | ||
// .m.rule.suppress_notices - should be an override | ||
// | ||
|
||
@Injectable() | ||
export class NotificationsService extends AuthenticatedApi { | ||
|
||
constructor(http: HttpClient, auth: AuthService, private account: AccountService) { | ||
super(http, auth); | ||
} | ||
|
||
private checkHandler(): void { | ||
if (!notificationsHandler) notificationsHandler = new NotificationsHandler(this.account); | ||
} | ||
|
||
public getPushRules(): any { | ||
this.checkHandler(); | ||
return notificationsHandler.getPushRules(); | ||
} | ||
} | ||
|
||
class NotificationsHandler { | ||
|
||
constructor(private account: AccountService) { | ||
|
||
account.accountData.events.subscribe(event => this.processPushRules(event)); | ||
|
||
account.accountData.get("m.push_rules") | ||
.then(e => this.processPushRules(e)).catch(() => Promise.resolve()); // swallow errors | ||
} | ||
|
||
private processPushRules(evt: AccountDataEvent) { | ||
if (evt.type !== "m.push_rules") return; | ||
const rules = <PushRulesEvent>evt; | ||
|
||
console.log(rules); | ||
} | ||
|
||
public async getPushRules() { | ||
const rules = await this.account.accountData.get("m.push_rules"); | ||
console.log(rules); | ||
return rules; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters