From 236d17620dbf3fd9ab1d055ba58439435a976d11 Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Wed, 7 Feb 2024 19:18:10 +0500 Subject: [PATCH] mobile: minor fixes --- apps/mobile/app/services/notifications.ts | 75 ++++++++++++----------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/apps/mobile/app/services/notifications.ts b/apps/mobile/app/services/notifications.ts index abed69452..3d1090a77 100644 --- a/apps/mobile/app/services/notifications.ts +++ b/apps/mobile/app/services/notifications.ts @@ -94,7 +94,7 @@ function encodeLine(line: string) { return line; } -async function initDatabase(notes = true) { +async function initDatabase() { if (!db.isInitialized) { await db.init(); } @@ -399,7 +399,7 @@ async function scheduleNotification( async function loadNote(id: string, jump: boolean) { if (!id || id === "notesnook_note_input") return; - const note = await db.notes?.note(id); + const note = await db.notes.note(id); if (!note) return; if (!DDS.isTab && jump) { tabBarRef.current?.goToPage(1); @@ -521,7 +521,7 @@ async function displayNotification({ } } -function openSettingsDialog(context: any) { +function openSettingsDialog(context: string) { return new Promise((resolve) => { presentDialog({ title: "Notifications disabled", @@ -737,38 +737,39 @@ async function getTriggers( break; case "year": - let timestamp = dayjs() - .month(relativeTime.month()) - .date(relativeTime.date()) - .hour(relativeTime.hour()) - .minute(relativeTime.minute()); + { + let timestamp = dayjs() + .month(relativeTime.month()) + .date(relativeTime.date()) + .hour(relativeTime.hour()) + .minute(relativeTime.minute()); + // Timestamp must always be in future. + if (timestamp.isBefore(dayjs())) { + do { + timestamp = timestamp.add(1, "year"); + } while (timestamp.isBefore(dayjs())); + } - // Timestamp must always be in future. - if (timestamp.isBefore(dayjs())) { - do { - timestamp = timestamp.add(1, "year"); - } while (timestamp.isBefore(dayjs())); - } - - if (Platform.OS === "ios") { - triggers.push({ - timestamp: timestamp.toDate().getTime() as number, - type: TriggerType.TIMESTAMP, - repeatFrequency: RepeatFrequency.YEARLY, - id: `${reminder.id}`, - alarmManager: { - allowWhileIdle: true - } - }); - } else { - triggers.push({ - timestamp: timestamp.toDate().getTime() as number, - type: TriggerType.TIMESTAMP, - id: reminder.id, - alarmManager: { - allowWhileIdle: true - } - }); + if (Platform.OS === "ios") { + triggers.push({ + timestamp: timestamp.toDate().getTime() as number, + type: TriggerType.TIMESTAMP, + repeatFrequency: RepeatFrequency.YEARLY, + id: `${reminder.id}`, + alarmManager: { + allowWhileIdle: true + } + }); + } else { + triggers.push({ + timestamp: timestamp.toDate().getTime() as number, + type: TriggerType.TIMESTAMP, + id: reminder.id, + alarmManager: { + allowWhileIdle: true + } + }); + } } break; } @@ -912,8 +913,10 @@ async function setupReminders(checkNeedsScheduling = false) { async function pinNote(id: string) { try { - const note = db.notes?.note(id as string) as any; - let text = await convertNoteToText(note as any, false); + const note = await db.notes.note(id as string); + if (!note) return; + + let text = await convertNoteToText(note, false); if (!text) text = ""; const html = text.replace(/\n/g, "
"); Notifications.displayNotification({