Some improments and Negentropy (#219)

* feat: adjust default window size

* feat: save window state

* feat: add window state plugin

* feat: add search

* feat: use negentropy for newsfeed

* feat: live feeds

* feat: add search user
This commit is contained in:
雨宮蓮
2024-06-30 14:26:02 +07:00
committed by GitHub
parent 968b1ada94
commit 0fec21b9ce
46 changed files with 5633 additions and 3938 deletions

View File

@@ -148,7 +148,7 @@ try {
else return { status: "error", error: e as any };
}
},
async checkContact(hex: string) : Promise<Result<boolean, null>> {
async checkContact(hex: string) : Promise<Result<boolean, string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("check_contact", { hex }) };
} catch (e) {
@@ -300,14 +300,6 @@ try {
else return { status: "error", error: e as any };
}
},
async unlistenEventReply(id: string) : Promise<Result<null, null>> {
try {
return { status: "ok", data: await TAURI_INVOKE("unlisten_event_reply", { id }) };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
},
async getEventsBy(publicKey: string, asOf: string | null) : Promise<Result<RichEvent[], string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("get_events_by", { publicKey, asOf }) };
@@ -324,6 +316,14 @@ try {
else return { status: "error", error: e as any };
}
},
async listenLocalEvent(label: string) : Promise<Result<null, string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("listen_local_event", { label }) };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
},
async getGroupEvents(publicKeys: string[], until: string | null) : Promise<Result<RichEvent[], string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("get_group_events", { publicKeys, until }) };
@@ -388,6 +388,14 @@ try {
else return { status: "error", error: e as any };
}
},
async unlisten(id: string) : Promise<Result<null, null>> {
try {
return { status: "ok", data: await TAURI_INVOKE("unlisten", { id }) };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
},
async showInFolder(path: string) : Promise<void> {
await TAURI_INVOKE("show_in_folder", { path });
},

View File

@@ -200,7 +200,7 @@ export class LumeEvent {
}
public async unlistenEventReply() {
const query = await commands.unlistenEventReply(this.id);
const query = await commands.unlisten(this.id);
if (query.status === "ok") {
return query.data;
@@ -271,6 +271,17 @@ export class LumeEvent {
}
}
static async build(event: NostrEvent) {
const query = await commands.getEventMeta(event.content);
if (query.status === "ok") {
event.meta = query.data;
return new LumeEvent(event);
} else {
return new LumeEvent(event);
}
}
static from(raw: string, parsed?: Meta) {
const nostrEvent: NostrEvent = JSON.parse(raw);
@@ -280,6 +291,6 @@ export class LumeEvent {
nostrEvent.meta = null;
}
return new this(nostrEvent);
return new LumeEvent(nostrEvent);
}
}

View File

@@ -1,5 +1,6 @@
import type { LumeColumn, Metadata, NostrEvent, Relay } from "@lume/types";
import { resolveResource } from "@tauri-apps/api/path";
import { getCurrent } from "@tauri-apps/api/window";
import { open } from "@tauri-apps/plugin-dialog";
import { readFile, readTextFile } from "@tauri-apps/plugin-fs";
import { relaunch } from "@tauri-apps/plugin-process";
@@ -206,6 +207,17 @@ export class NostrQuery {
}
}
static async listenLocalEvent() {
const label = getCurrent().label;
const query = await commands.listenLocalEvent(label);
if (query.status === "ok") {
return query.data;
} else {
throw new Error(query.error);
}
}
static async getGroupEvents(pubkeys: string[], asOf?: number) {
const until: string = asOf && asOf > 0 ? asOf.toString() : undefined;
const query = await commands.getGroupEvents(pubkeys, until);
@@ -403,4 +415,15 @@ export class NostrQuery {
throw new Error(query.error);
}
}
static async unlisten(id?: string) {
const label = id ? id : getCurrent().label;
const query = await commands.unlisten(label);
if (query.status === "ok") {
return query.data;
} else {
throw new Error(query.error);
}
}
}

View File

@@ -129,11 +129,17 @@ export class LumeWindow {
}
}
static async openSearch() {
const label = "search";
static async openSearch(searchType: "notes" | "users", searchQuery: string) {
const url = `/search/${searchType}?query=${searchQuery}`;
const label = `search-${searchQuery
.toLowerCase()
.replace(/[^\w ]+/g, "")
.replace(/ +/g, "_")
.replace(/_+/g, "_")}`;
const query = await commands.openWindow({
label,
url: "/search",
url,
title: "Search",
width: 400,
height: 600,