diff --git a/src/matrix/Session.js b/src/matrix/Session.js index 735967bf..0ddf44ae 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -522,6 +522,18 @@ export class Session { const pusherData = await readTxn.session.get(PUSHER_KEY); return !!pusherData; } + + async checkPusherEnabledOnHomeServer() { + const readTxn = await this._storage.readTxn([this._storage.storeNames.session]); + const pusherData = await readTxn.session.get(PUSHER_KEY); + if (!pusherData) { + return false; + } + const myPusher = new Pusher(pusherData); + const serverPushersData = await this._hsApi.getPushers().response(); + const serverPushers = (serverPushersData?.pushers || []).map(data => new Pusher(data)); + return serverPushers.some(p => p.equals(myPusher)); + } } export function tests() { diff --git a/src/matrix/net/HomeServerApi.js b/src/matrix/net/HomeServerApi.js index a6acaf74..f8dfa517 100644 --- a/src/matrix/net/HomeServerApi.js +++ b/src/matrix/net/HomeServerApi.js @@ -258,6 +258,10 @@ export class HomeServerApi { setPusher(pusher, options = null) { return this._post("/pushers/set", null, pusher, options); } + + getPushers(options = null) { + return this._get("/pushers", null, null, options); + } } export function tests() { diff --git a/src/matrix/push/Pusher.js b/src/matrix/push/Pusher.js index cc370f82..99baeae6 100644 --- a/src/matrix/push/Pusher.js +++ b/src/matrix/push/Pusher.js @@ -37,4 +37,14 @@ export class Pusher { serialize() { return this._description; } + + equals(pusher) { + if (this._description.app_id !== pusher._description.app_id) { + return false; + } + if (this._description.pushkey !== pusher._description.pushkey) { + return false; + } + return JSON.stringify(this._description.data) === JSON.stringify(pusher._description.data); + } }