Skip to content

Commit d414375

Browse files
committed
web push fixes
1 parent f553389 commit d414375

5 files changed

Lines changed: 15 additions & 8 deletions

File tree

api-server/source/admin/admin-routes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { upsertContentRoute } from "./upsert-content.ts";
44
import { upsertRegistrationsRoute } from "./upsert-registrations.ts";
55
import { upsertScheduleRoute } from "./upsert-schedule.ts";
66
import { getWebPushInfo } from "./web-push-info.ts";
7+
import { sendWebPushMessage } from "./web-push-send.ts";
78
import { testWebPushMessage } from "./web-push-test.ts";
89

910
export const adminRoutes = [
@@ -15,4 +16,5 @@ export const adminRoutes = [
1516

1617
getWebPushInfo,
1718
testWebPushMessage,
19+
sendWebPushMessage,
1820
];

api-server/source/admin/web-push-info.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { WebPushRepo } from "../notifications/web-push-repo.ts";
44

55
export const getWebPushInfo = defineRoute({
66
method: "GET",
7-
pathname: "/admin/v1/conference/:conference/web-push",
7+
pathname: "/admin/v1/conferences/:conference/web-push/info",
88
dependencies: {
99
authz: useAuthz,
1010
webPush: WebPushRepo.use,

api-server/source/admin/web-push-send.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const _Request = Structure.object({
1111

1212
export const sendWebPushMessage = defineRoute({
1313
method: "POST",
14-
pathname: "/admin/v1/conference/:conference/web-push-test",
14+
pathname: "/admin/v1/conferences/:conference/web-push/send",
1515
dependencies: {
1616
authz: useAuthz,
1717
webPush: WebPushRepo.use,
@@ -30,7 +30,9 @@ export const sendWebPushMessage = defineRoute({
3030
const body = await assertRequestBody(_Request, request);
3131

3232
// Get all of the web-push-devices for the conference
33-
const devices = await webPush.listConferenceDevices(conference.id);
33+
const devices = await webPush.listConferenceDevices(conference.id, [
34+
"Special",
35+
]);
3436

3537
// Send the message
3638
const stats = await _sendToDevices(devices, webPush, {

api-server/source/admin/web-push-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const _Request = Structure.object({
1111

1212
export const testWebPushMessage = defineRoute({
1313
method: "POST",
14-
pathname: "/admin/v1/conference/:conference/web-push-test",
14+
pathname: "/admin/v1/conferences/:conference/web-push/test",
1515
dependencies: {
1616
authz: useAuthz,
1717
webPush: WebPushRepo.use,

api-server/source/notifications/web-push-repo.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export class WebPushRepo {
192192

193193
const devices = await WebPushDeviceTable.select(
194194
this.sql,
195-
this.sql`id IN ${this.sql(registrations.map((r) => r.id))}`,
195+
this.sql`registration_id IN ${this.sql(registrations.map((r) => r.id))}`,
196196
);
197197

198198
const categories = sumCategories(devices);
@@ -208,16 +208,19 @@ export class WebPushRepo {
208208
return { categories, messages };
209209
}
210210

211-
async listConferenceDevices(conferenceId: number) {
211+
async listConferenceDevices(conferenceId: number, categories: string[]) {
212212
const registrations = await RegistrationTable.select(
213213
this.sql,
214-
this.sql` conference_id = ${conferenceId} `,
214+
this.sql`conference_id = ${conferenceId}`,
215215
["id"],
216216
);
217217

218218
return WebPushDeviceTable.select(
219219
this.sql,
220-
this.sql`id IN ${this.sql(registrations.map((r) => r.id))}`,
220+
this.sql`
221+
registration_id IN ${this.sql(registrations.map((r) => r.id))}
222+
AND categories ? ${this.sql(categories)}
223+
`,
221224
);
222225
}
223226
}

0 commit comments

Comments
 (0)