diff --git a/apps/mobile/app/screens/editor/tiptap/use-editor.ts b/apps/mobile/app/screens/editor/tiptap/use-editor.ts index f4a584e8f..c3ef88d35 100644 --- a/apps/mobile/app/screens/editor/tiptap/use-editor.ts +++ b/apps/mobile/app/screens/editor/tiptap/use-editor.ts @@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +import { getFormattedDate } from "@notesnook/common"; import { EVENTS } from "@notesnook/core/dist/common"; import { useThemeEngineStore } from "@notesnook/theme"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; @@ -31,6 +32,7 @@ import { openVault } from "../../../services/event-manager"; import Navigation from "../../../services/navigation"; +import Notifications from "../../../services/notifications"; import SettingsService from "../../../services/settings"; import { TipManager } from "../../../services/tip-manager"; import { useEditorStore } from "../../../stores/use-editor-store"; @@ -52,7 +54,6 @@ import { makeSessionId, post } from "./utils"; -import { getFormattedDate } from "@notesnook/common"; export const useEditor = ( editorId = "", @@ -234,6 +235,10 @@ export const useEditor = ( id && useEditorStore.getState().setCurrentlyEditingNote(id); }); } + + if (Notifications.isNotePinned(id as string)) { + Notifications.pinNote(id as string); + } } else { noteData.contentId = note?.contentId; // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/apps/mobile/app/services/notifications.ts b/apps/mobile/app/services/notifications.ts index 4d664065b..54f05dcd0 100644 --- a/apps/mobile/app/services/notifications.ts +++ b/apps/mobile/app/services/notifications.ts @@ -46,6 +46,7 @@ import { useRelationStore } from "../stores/use-relation-store"; import { useReminderStore } from "../stores/use-reminder-store"; import { presentDialog } from "../components/dialog/functions"; import NetInfo from "@react-native-community/netinfo"; +import { convertNoteToText } from "../utils/note-to-text"; export type Reminder = { id: string; @@ -757,6 +758,11 @@ function getPinnedNotes(): DisplayedNotification[] { return pinned; } +function isNotePinned(id: string) { + if (Platform.OS !== "android") return false; + return pinned.findIndex((notification) => notification.id === id) > -1; +} + function get(): Promise { return new Promise((resolve) => { if (Platform.OS === "ios") resolve([]); @@ -844,6 +850,26 @@ 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); + if (!text) text = ""; + let html = text.replace(/\n/g, "
"); + Notifications.displayNotification({ + title: note.title, + message: note.headline || text, + subtitle: note.headline || text, + bigText: html, + ongoing: true, + actions: ["UNPIN"], + id: note.id + }); + } catch (e) { + console.log(e); + } +} + const Notifications = { init, displayNotification, @@ -859,7 +885,9 @@ const Notifications = { checkAndRequestPermissions, clearAllTriggers, setupReminders, - getChannelId + getChannelId, + isNotePinned, + pinNote }; export default Notifications;