2023-04-07 03:56:46 +02:00
|
|
|
import { SwSubscriptions } from "@/models/index.js";
|
2023-04-04 05:36:59 +02:00
|
|
|
import define from "../../define.js";
|
|
|
|
|
|
|
|
export const meta = {
|
2023-04-07 03:56:46 +02:00
|
|
|
tags: ["account"],
|
2023-04-04 05:36:59 +02:00
|
|
|
|
|
|
|
requireCredential: true,
|
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
description: "Check push notification registration exists.",
|
2023-04-04 05:36:59 +02:00
|
|
|
|
|
|
|
res: {
|
2023-04-07 03:56:46 +02:00
|
|
|
type: "object",
|
|
|
|
optional: false,
|
|
|
|
nullable: true,
|
2023-04-04 05:36:59 +02:00
|
|
|
properties: {
|
|
|
|
userId: {
|
2023-04-07 03:56:46 +02:00
|
|
|
type: "string",
|
|
|
|
optional: false,
|
|
|
|
nullable: false,
|
2023-04-04 05:36:59 +02:00
|
|
|
},
|
|
|
|
endpoint: {
|
2023-04-07 03:56:46 +02:00
|
|
|
type: "string",
|
|
|
|
optional: false,
|
|
|
|
nullable: false,
|
2023-04-04 05:36:59 +02:00
|
|
|
},
|
|
|
|
sendReadMessage: {
|
2023-04-07 03:56:46 +02:00
|
|
|
type: "boolean",
|
|
|
|
optional: false,
|
|
|
|
nullable: false,
|
2023-04-04 05:36:59 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
export const paramDef = {
|
2023-04-07 03:56:46 +02:00
|
|
|
type: "object",
|
2023-04-04 05:36:59 +02:00
|
|
|
properties: {
|
2023-04-07 03:56:46 +02:00
|
|
|
endpoint: { type: "string" },
|
2023-04-04 05:36:59 +02:00
|
|
|
},
|
2023-04-07 03:56:46 +02:00
|
|
|
required: ["endpoint"],
|
2023-04-04 05:36:59 +02:00
|
|
|
} as const;
|
|
|
|
|
|
|
|
// eslint-disable-next-line import/no-default-export
|
|
|
|
export default define(meta, paramDef, async (ps, me) => {
|
2023-07-13 17:28:44 +02:00
|
|
|
const subscription = await SwSubscriptions.findOneBy({
|
2023-04-04 05:36:59 +02:00
|
|
|
userId: me.id,
|
|
|
|
endpoint: ps.endpoint,
|
|
|
|
});
|
|
|
|
|
2023-07-13 17:28:44 +02:00
|
|
|
if (subscription != null) {
|
2023-04-04 05:36:59 +02:00
|
|
|
return {
|
2023-07-13 17:28:44 +02:00
|
|
|
userId: subscription.userId,
|
|
|
|
endpoint: subscription.endpoint,
|
|
|
|
sendReadMessage: subscription.sendReadMessage,
|
2023-04-04 05:36:59 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
});
|