feat: add basic web of trust

This commit is contained in:
2024-09-23 13:24:33 +07:00
parent a5574bef6c
commit 9152c3e122
6 changed files with 127 additions and 62 deletions

View File

@@ -256,6 +256,14 @@ async verifyNip05(id: string, nip05: string) : Promise<Result<boolean, string>>
else return { status: "error", error: e as any };
}
},
async isTrustedUser(id: string) : Promise<Result<boolean, string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("is_trusted_user", { id }) };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
},
async getEventMeta(content: string) : Promise<Result<Meta, null>> {
try {
return { status: "ok", data: await TAURI_INVOKE("get_event_meta", { content }) };
@@ -463,7 +471,7 @@ export type NewSettings = Settings
export type Profile = { name: string; display_name: string; about: string | null; picture: string; banner: string | null; nip05: string | null; lud16: string | null; website: string | null }
export type Relays = { connected: string[]; read: string[] | null; write: string[] | null; both: string[] | null }
export type RichEvent = { raw: string; parsed: Meta | null }
export type Settings = { proxy: string | null; image_resize_service: string | null; use_relay_hint: boolean; content_warning: boolean; display_avatar: boolean; display_zap_button: boolean; display_repost_button: boolean; display_media: boolean; transparent: boolean }
export type Settings = { proxy: string | null; image_resize_service: string | null; use_relay_hint: boolean; content_warning: boolean; trusted_only: boolean; display_avatar: boolean; display_zap_button: boolean; display_repost_button: boolean; display_media: boolean; transparent: boolean }
export type SubKind = "Subscribe" | "Unsubscribe"
export type Subscription = { label: string; kind: SubKind; event_id: string | null }
export type Window = { label: string; title: string; url: string; width: number; height: number; maximizable: boolean; minimizable: boolean; hidden_title: boolean }

View File

@@ -1,3 +1,4 @@
import { commands } from "@/commands.gen";
import { cn, replyTime } from "@/commons";
import { Note } from "@/components/note";
import { type LumeEvent, LumeWindow } from "@/system";
@@ -5,7 +6,7 @@ import { CaretDown } from "@phosphor-icons/react";
import { Link, useSearch } from "@tanstack/react-router";
import { Menu, MenuItem } from "@tauri-apps/api/menu";
import { writeText } from "@tauri-apps/plugin-clipboard-manager";
import { memo, useCallback } from "react";
import { memo, useCallback, useEffect, useState } from "react";
import { User } from "./user";
export const ReplyNote = memo(function ReplyNote({
@@ -16,6 +17,7 @@ export const ReplyNote = memo(function ReplyNote({
className?: string;
}) {
const search = useSearch({ strict: false });
const [isTrusted, setIsTrusted] = useState<boolean>(null);
const showContextMenu = useCallback(async (e: React.MouseEvent) => {
e.preventDefault();
@@ -41,6 +43,22 @@ export const ReplyNote = memo(function ReplyNote({
await menu.popup().catch((e) => console.error(e));
}, []);
useEffect(() => {
async function check() {
const res = await commands.isTrustedUser(event.pubkey);
if (res.status === "ok") {
setIsTrusted(res.data);
}
}
check();
}, []);
if (isTrusted !== null && isTrusted === false) {
return <div>Not trusted</div>;
}
return (
<Note.Provider event={event}>
<User.Provider pubkey={event.pubkey}>

View File

@@ -82,7 +82,7 @@ export function Screen() {
);
useEffect(() => {
const unlisten = listen("newsfeed_synchronized", async () => {
const unlisten = listen("synchronized", async () => {
await queryClient.invalidateQueries({ queryKey: [label, account] });
});