put pusher bits in separate class to enable and disable on the HS

This commit is contained in:
Bruno Windels 2021-03-18 20:42:46 +01:00
parent 1b0f175b02
commit d4fc08c06b
2 changed files with 39 additions and 0 deletions

View file

@ -254,6 +254,10 @@ export class HomeServerApi {
uploadAttachment(blob, filename, options = null) {
return this._authedRequest("POST", `${this._homeserver}/_matrix/media/r0/upload`, {filename}, blob, options);
}
setPusher(pusher, options = null) {
return this._post("/pushers/set", null, pusher, options);
}
}
export function tests() {

35
src/matrix/push/Pusher.js Normal file
View file

@ -0,0 +1,35 @@
export class Pusher {
constructor(description) {
this._description = description;
}
static httpPusher(host, appId, pushkey, data) {
return new Pusher({
kind: "http",
append: true, // as pushkeys are shared between multiple users on one origin
data: Object.assign({}, data, {url: host + "/_matrix/push/v1/notify"}),
pushkey,
app_id: appId,
app_display_name: "Hydrogen",
device_display_name: "Hydrogen",
lang: "en"
});
}
static createDefaultPayload(sessionId) {
return {session_id: sessionId};
}
async enable(hsApi, log) {
await hsApi.setPusher(this._description, {log}).response();
}
async disable(hsApi, log) {
const deleteDescription = Object.assign({}, this._description, {kind: null});
await hsApi.setPusher(deleteDescription, {log}).response();
}
serialize() {
return this._description;
}
}