Notification Panel (#200)

* feat: add tauri nspanel

* feat: add notification panel

* feat: move notification service to backend

* feat: add sync notification job

* feat: enable panel to join all spaces including fullscreen (#203)

* feat: fetch notification

* feat: listen for new notification

* feat: finish panel

---------

Co-authored-by: Victor Aremu <me@victorare.mu>
This commit is contained in:
雨宮蓮
2024-06-06 14:32:30 +07:00
committed by GitHub
parent 4e7da4108b
commit 799835a629
25 changed files with 1006 additions and 977 deletions

View File

@@ -1,5 +1,6 @@
import { Metadata } from "@lume/types";
import { Result, commands } from "./commands";
import { Window } from "@tauri-apps/api/window";
export class NostrAccount {
static async getAccounts() {
@@ -23,6 +24,9 @@ export class NostrAccount {
}
if (query.status === "ok") {
const panel = Window.getByLabel("panel");
panel.emit("load-notification", { account: npub }); // trigger load notification
return query.data;
} else {
throw new Error(query.error);

View File

@@ -144,20 +144,6 @@ export const commands = {
else return { status: "error", error: e as any };
}
},
async getActivities(
account: string,
kind: string,
): Promise<Result<string[], string>> {
try {
return {
status: "ok",
data: await TAURI_INVOKE("get_activities", { account, kind }),
};
} catch (e) {
if (e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
},
async getCurrentUserProfile(): Promise<Result<string, string>> {
try {
return {
@@ -334,6 +320,14 @@ export const commands = {
else return { status: "error", error: e as any };
}
},
async getNotifications(): Promise<Result<string[], string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("get_notifications") };
} catch (e) {
if (e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
},
async getEvent(id: string): Promise<Result<string, string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("get_event", { id }) };

View File

@@ -68,6 +68,18 @@ export class NostrQuery {
}
}
static async getNotifications() {
const query = await commands.getNotifications();
if (query.status === "ok") {
const events = query.data.map((item) => JSON.parse(item) as NostrEvent);
return events;
} else {
console.error(query.error);
return [];
}
}
static async getProfile(pubkey: string) {
const normalize = pubkey.replace("nostr:", "").replace(/[^\w\s]/gi, "");
const query = await commands.getProfile(normalize);
@@ -104,20 +116,6 @@ export class NostrQuery {
}
}
static async getUserActivities(
account: string,
kind: "1" | "6" | "9735" = "1",
) {
const query = await commands.getActivities(account, kind);
if (query.status === "ok") {
const events = query.data.map((item) => JSON.parse(item) as NostrEvent);
return events;
} else {
return [];
}
}
static async getLocalEvents(pubkeys: string[], asOf?: number) {
const until: string = asOf && asOf > 0 ? asOf.toString() : undefined;
const query = await commands.getLocalEvents(pubkeys, until);

View File

@@ -92,7 +92,7 @@ export class LumeWindow {
const query = await commands.openWindow(
label,
"Settings",
"/settings",
"/settings/general",
800,
500,
);