couchdb-changes-stream: add limit title and body length
This commit is contained in:
@@ -11,6 +11,10 @@ const abortController = new AbortController();
|
||||
|
||||
startHealthServer(abortController);
|
||||
|
||||
function limitStringLengthWithEllipsis(str: string, maxLength: number): string {
|
||||
return str.length > maxLength ? str.substring(0, maxLength) + "…" : str;
|
||||
}
|
||||
|
||||
const start = async () => {
|
||||
await setupVapidDetails();
|
||||
const serviceSeqTracker = await ServiceSeqTracker.Init(
|
||||
@@ -76,13 +80,21 @@ const start = async () => {
|
||||
try {
|
||||
const subscription = row.doc!.subscription;
|
||||
const topic = `chat-${msgDoc.qr_code_uri}-${msgDoc.chat}`;
|
||||
const tag = `${topic}-${(new Date(msgDoc.created_at).getTime() - new Date(qrDoc.created_at).getTime()).toString(36)}`;
|
||||
const timestamp = new Date(msgDoc.created_at).getTime();
|
||||
const tag = `${topic}-${(timestamp - new Date(qrDoc.created_at).getTime()).toString(36)}`;
|
||||
|
||||
const options: NotificationOptions = {
|
||||
const title = limitStringLengthWithEllipsis(
|
||||
`${qrDoc.name}: новое сообщение`,
|
||||
53,
|
||||
);
|
||||
const body = limitStringLengthWithEllipsis(msgDoc.body, 470);
|
||||
|
||||
const options: NotificationOptions & { timestamp: number } = {
|
||||
icon: "/images/qr-code-logo-200x200.jpg",
|
||||
body: msgDoc.body,
|
||||
body,
|
||||
tag,
|
||||
requireInteraction: true,
|
||||
timestamp,
|
||||
data: {
|
||||
url: `/manage/${msgDoc.qr_code_uri}/chat/${msgDoc.chat}`,
|
||||
payload: { tag },
|
||||
@@ -94,7 +106,7 @@ const start = async () => {
|
||||
JSON.stringify({
|
||||
type: "notification",
|
||||
notification: {
|
||||
title: qrDoc.name,
|
||||
title,
|
||||
options,
|
||||
},
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user