Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

mobile: fix quick notes from notifications (#3165)

Ammar Ahmedd5038ac631cd
diff --git a/apps/mobile/app/app.js b/apps/mobile/app/app.js
index d2968ce8f..8f6a8e4d3 100644
--- a/apps/mobile/app/app.js
+++ b/apps/mobile/app/app.js
@@ -46,6 +46,7 @@ const App = () => {
if (appLockMode && appLockMode !== "none") {
useUserStore.getState().lockApp(true);
}
+ globalThis["IS_MAIN_APP_RUNNING"] = true;
init();
setTimeout(async () => {
SettingsService.onFirstLaunch();
diff --git a/apps/mobile/app/screens/editor/tiptap/use-editor.ts b/apps/mobile/app/screens/editor/tiptap/use-editor.ts
index c3ef88d35..5cd901a54 100644
--- a/apps/mobile/app/screens/editor/tiptap/use-editor.ts
+++ b/apps/mobile/app/screens/editor/tiptap/use-editor.ts
@@ -134,7 +134,7 @@ export const useEditor = (
const reset = useCallback(
async (resetState = true, resetContent = true) => {
- currentNote.current?.id && db.fs?.cancel(currentNote.current.id);
+ currentNote.current?.id && db.fs?.cancel(currentNote.current.id, null);
currentNote.current = null;
loadedImages.current = {};
currentContent.current = null;
diff --git a/apps/mobile/app/services/notifications.ts b/apps/mobile/app/services/notifications.ts
index 54f05dcd0..1dc25e805 100644
--- a/apps/mobile/app/services/notifications.ts
+++ b/apps/mobile/app/services/notifications.ts
@@ -46,8 +46,10 @@ 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 { encodeNonAsciiHTML } from "entities";
import { convertNoteToText } from "../utils/note-to-text";
+
export type Reminder = {
id: string;
type: string;
@@ -87,6 +89,28 @@ async function getNextMonthlyReminderDate(
return await getNextMonthlyReminderDate(reminder, dayjs().year() + 1);
}
+export function textToHTML(src: string) {
+ return src
+ .split(/[\r\n]/)
+ .map((line) =>
+ line
+ ? `<p data-spacing="single">${encodeLine(line)}</p>`
+ : `<p data-spacing="single"></p>`
+ )
+ .join("");
+}
+
+function encodeLine(line: string) {
+ line = encodeNonAsciiHTML(line);
+ line = line.replace(/(^ +)|( {2,})/g, (sub, ...args) => {
+ const [starting, inline] = args;
+ if (starting) return "&nbsp;".repeat(starting.length);
+ if (inline) return "&nbsp;".repeat(inline.length);
+ return sub;
+ });
+ return line;
+}
+
async function initDatabase(notes = true) {
if (!db.isInitialized) {
await db.initCollections();
@@ -207,16 +231,41 @@ const onEvent = async ({ type, detail }: Event) => {
});
if (!db.isInitialized) await db.init();
await db.notes?.init();
- await db.notes?.add({
+
+ const id = await db.notes?.add({
content: {
type: "tiptap",
- data: `<p>${input} </p>`
+ data: textToHTML(input as string)
}
});
+
+ const defaultNotebook = db.settings?.getDefaultNotebook();
+
+ if (defaultNotebook) {
+ if (!defaultNotebook.topic) {
+ await db.relations?.add(
+ { type: "notebook", id: defaultNotebook.id },
+ { type: "note", id: id }
+ );
+ } else {
+ await db.notes?.addToNotebook(
+ {
+ topic: defaultNotebook.topic,
+ id: defaultNotebook?.id
+ },
+ id
+ );
+ }
+ }
+
const status = await NetInfo.fetch();
if (status.isInternetReachable) {
try {
- await db.sync(false, false);
+ if (!globalThis["IS_MAIN_APP_RUNNING" as never]) {
+ await db.sync(false, false);
+ } else {
+ console.log("main app running, skipping sync");
+ }
} catch (e) {
console.log(e, (e as Error).stack);
}
diff --git a/apps/mobile/share/share.js b/apps/mobile/share/share.js
index 9cf982d17..5d6c03b01 100644
--- a/apps/mobile/share/share.js
+++ b/apps/mobile/share/share.js
@@ -377,7 +377,11 @@ const ShareView = ({ quicknote = false }) => {
});
try {
- await db.sync(false, false);
+ if (!globalThis["IS_MAIN_APP_RUNNING"]) {
+ await db.sync(false, false);
+ } else {
+ console.log("main app running, skipping sync");
+ }
} catch (e) {
console.log(e, e.stack);
}