A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
mobile: fix notification notes created on every app launch
Ammar Ahmed2f66ee04cc8f
diff --git a/apps/mobile/app/app.tsx b/apps/mobile/app/app.tsxindex 9f439bcec..2289f5342 100644--- a/apps/mobile/app/app.tsx+++ b/apps/mobile/app/app.tsx@@ -64,7 +64,7 @@ const App = (props: { configureMode: "note-preview" }) => {setTimeout(async () => {await Notifications.get();if (SettingsService.get().notifNotes) {- Notifications.pinQuickNote(true);+ Notifications.pinQuickNote();}TipManager.init();}, 100);diff --git a/apps/mobile/app/hooks/use-app-events.tsx b/apps/mobile/app/hooks/use-app-events.tsxindex a6d0e21cf..a1db09c94 100644--- a/apps/mobile/app/hooks/use-app-events.tsx+++ b/apps/mobile/app/hooks/use-app-events.tsx@@ -455,9 +455,6 @@ const initializeDatabase = async (password?: string) => {await setAppMessage();useSettingStore.getState().setAppLoading(false);Notifications.setupReminders(true);- if (SettingsService.get().notifNotes) {- Notifications.pinQuickNote(false);- }DatabaseLogger.info("Database initialized");Notifications.restorePinnedNotes();}diff --git a/apps/mobile/app/screens/settings/settings-data.tsx b/apps/mobile/app/screens/settings/settings-data.tsxindex 5bb57d3f4..afd94a195 100644--- a/apps/mobile/app/screens/settings/settings-data.tsx+++ b/apps/mobile/app/screens/settings/settings-data.tsx@@ -1329,7 +1329,7 @@ export const settingsGroups: SettingSection[] = [if (settings.notifNotes) {Notifications.unpinQuickNote();} else {- Notifications.pinQuickNote(false);+ Notifications.pinQuickNote();}SettingsService.set({notifNotes: !settings.notifNotesdiff --git a/apps/mobile/app/services/background-sync.ts b/apps/mobile/app/services/background-sync.tsindex f1cbc5647..a747d31ea 100644--- a/apps/mobile/app/services/background-sync.ts+++ b/apps/mobile/app/services/background-sync.ts@@ -114,7 +114,7 @@ async function onBackgroundSyncStarted() {}await Notifications.setupReminders();if (SettingsService.get().notifNotes) {- Notifications.pinQuickNote(false);+ Notifications.pinQuickNote();}Notifications.restorePinnedNotes();NotePreviewWidget.updateNotes();@@ -142,7 +142,7 @@ const onBoot = async () => {await Notifications.setupReminders();if (SettingsService.get().notifNotes) {- Notifications.pinQuickNote(false);+ Notifications.pinQuickNote();}Notifications.restorePinnedNotes();NotePreviewWidget.updateNotes();diff --git a/apps/mobile/app/services/notifications.ts b/apps/mobile/app/services/notifications.tsindex 05d2b32da..651d4fb4e 100644--- a/apps/mobile/app/services/notifications.ts+++ b/apps/mobile/app/services/notifications.ts@@ -109,6 +109,15 @@ async function initDatabase() {const onEvent = async ({ type, detail }: Event) => {await initDatabase();const { notification, pressAction, input } = detail;+ if (+ type === EventType.DISMISSED &&+ Platform.OS === "android" &&+ notification?.id === "notesnook_note_input" &&+ SettingsService.getProperty("notifNotes")+ ) {+ pinQuickNote();+ }+if (type === EventType.DELIVERED && Platform.OS === "android") {if (notification?.id) {const reminder = await db.reminders?.reminder(@@ -503,7 +512,8 @@ async function displayNotification({ongoing,reply_placeholder_text,reply_button_text,- id+ id,+ channelId = "default"}: {title?: string;message: string;@@ -514,6 +524,7 @@ async function displayNotification({reply_placeholder_text?: string;reply_button_text?: string;id?: string;+ channelId?: "silent" | "vibrate" | "urgent" | "default";}) {useUserStore.setState({disableAppLockRequests: true@@ -538,7 +549,7 @@ async function displayNotification({ongoing: ongoing,smallIcon: "ic_stat_name",localOnly: true,- channelId: await getChannelId("default"),+ channelId: await getChannelId(channelId),autoCancel: false,pressAction: {id: "default",@@ -885,7 +896,7 @@ function init() {notifee.onForegroundEvent(onEvent);}-async function pinQuickNote(launch: boolean) {+async function pinQuickNote() {useUserStore.setState({disableAppLockRequests: true});@@ -897,14 +908,13 @@ async function pinQuickNote(launch: boolean) {return;}get().then((items) => {- const notification = items.filter((n) => n.id === "notesnook_note_input");- if (notification && launch) {- return;- }+ const notification = items.find((n) => n.id === "notesnook_note_input");+ if (notification) return;displayNotification({title: strings.quickNoteTitle(),message: strings.quickNoteContent(),ongoing: true,+ channelId: "silent",actions: ["ReplyInput", strings.hide()],reply_button_text: strings.takeNote(),reply_placeholder_text: strings.quickNotePlaceholder(),@@ -1031,6 +1041,7 @@ async function pinNote(id: string) {subtitle: "",bigText: html,ongoing: true,+ channelId: "silent",actions: [strings.unpin()],id: note.id});@@ -1041,9 +1052,13 @@ async function pinNote(id: string) {async function restorePinnedNotes() {const pinnedNotes = PinnedNotesStorage.get();- for (const id of pinnedNotes) {- pinNote(id);- }+ Notifications.get().then(() => {+ for (const id of pinnedNotes) {+ if (!isNotePinned(id)) {+ pinNote(id);+ }+ }+ });}async function clearPinnedNotes() {