Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add client method to remove pusher #3324

Merged
merged 3 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions spec/unit/matrix-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2909,4 +2909,43 @@ describe("MatrixClient", function () {
});
});
});

describe("pushers", () => {
const pusher = {
app_id: "test",
app_display_name: "Test App",
data: {},
device_display_name: "test device",
kind: "http",
lang: "en-NZ",
pushkey: "1234",
};

beforeEach(() => {
makeClient();
const response: HttpLookup = {
method: Method.Post,
path: "/pushers/set",
data: {},
};
httpLookups = [response];
jest.spyOn(client.http, "authedRequest").mockClear();
});

it("should make correct request to set pusher", async () => {
const result = await client.setPusher(pusher);
expect(client.http.authedRequest).toHaveBeenCalledWith(Method.Post, "/pushers/set", undefined, pusher);
expect(result).toEqual({});
});

it("should make correct request to remove pusher", async () => {
const result = await client.removePusher(pusher.pushkey, pusher.app_id);
expect(client.http.authedRequest).toHaveBeenCalledWith(Method.Post, "/pushers/set", undefined, {
pushkey: pusher.pushkey,
app_id: pusher.app_id,
kind: null,
});
expect(result).toEqual({});
});
});
});
17 changes: 17 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8627,6 +8627,23 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
return this.http.authedRequest(Method.Post, path, undefined, pusher);
}

/**
* Removes an existing pusher
* @param pushKey - pushkey of pusher to remove
* @param appId - app_id of pusher to remove
* @returns Promise which resolves: Empty json object on success
* @returns Rejects: with an error response.
*/
public removePusher(pushKey: string, appId: string): Promise<{}> {
const path = "/pushers/set";
const body = {
pushkey: pushKey,
app_id: appId,
kind: null, // marks pusher for removal
};
return this.http.authedRequest(Method.Post, path, undefined, body);
}

/**
* Persists local notification settings
* @returns Promise which resolves: an empty object
Expand Down