feat: add basic relay management in rust
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
type LumeColumn,
|
||||
type Metadata,
|
||||
type Settings,
|
||||
Relays,
|
||||
} from "@lume/types";
|
||||
import { generateContentTags } from "@lume/utils";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
@@ -55,16 +56,6 @@ export class Ark {
|
||||
}
|
||||
}
|
||||
|
||||
public async get_activities(account: string, kind: "1" | "6" | "9735" = "1") {
|
||||
try {
|
||||
const events: Event[] = await invoke("get_activities", { account, kind });
|
||||
return events;
|
||||
} catch (e) {
|
||||
console.error(String(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async nostr_connect(uri: string) {
|
||||
try {
|
||||
const remoteKey = uri.replace("bunker://", "").split("?")[0];
|
||||
@@ -117,6 +108,52 @@ export class Ark {
|
||||
}
|
||||
}
|
||||
|
||||
public async get_relays() {
|
||||
try {
|
||||
const cmd: Relays = await invoke("get_relays");
|
||||
return cmd;
|
||||
} catch (e) {
|
||||
console.error(String(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async add_relay(url: string) {
|
||||
try {
|
||||
const relayUrl = new URL(url);
|
||||
|
||||
if (relayUrl.protocol === "wss:" || relayUrl.protocol === "ws:") {
|
||||
const cmd: boolean = await invoke("connect_relay", { relay: relayUrl });
|
||||
return cmd;
|
||||
}
|
||||
} catch (e) {
|
||||
throw new Error(String(e));
|
||||
}
|
||||
}
|
||||
|
||||
public async remove_relay(url: string) {
|
||||
try {
|
||||
const relayUrl = new URL(url);
|
||||
|
||||
if (relayUrl.protocol === "wss:" || relayUrl.protocol === "ws:") {
|
||||
const cmd: boolean = await invoke("remove_relay", { relay: relayUrl });
|
||||
return cmd;
|
||||
}
|
||||
} catch (e) {
|
||||
throw new Error(String(e));
|
||||
}
|
||||
}
|
||||
|
||||
public async get_activities(account: string, kind: "1" | "6" | "9735" = "1") {
|
||||
try {
|
||||
const events: Event[] = await invoke("get_activities", { account, kind });
|
||||
return events;
|
||||
} catch (e) {
|
||||
console.error(String(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async get_event(id: string) {
|
||||
try {
|
||||
const eventId: string = id.replace("nostr:", "").replace(/[^\w\s]/gi, "");
|
||||
@@ -463,16 +500,6 @@ export class Ark {
|
||||
}
|
||||
}
|
||||
|
||||
public async get_contact_metadata() {
|
||||
try {
|
||||
const cmd: Contact[] = await invoke("get_contact_metadata");
|
||||
return cmd;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async follow(id: string, alias?: string) {
|
||||
try {
|
||||
const cmd: string = await invoke("follow", { id, alias });
|
||||
|
||||
@@ -1,19 +1,12 @@
|
||||
export function RelayIcon(props: JSX.IntrinsicElements["svg"]) {
|
||||
return (
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="25"
|
||||
height="24"
|
||||
fill="none"
|
||||
viewBox="0 0 25 24"
|
||||
{...props}
|
||||
>
|
||||
<svg width="24" height="24" fill="none" viewBox="0 0 24 24" {...props}>
|
||||
<path
|
||||
stroke="currentColor"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth="2"
|
||||
d="M21.5 12a9.002 9.002 0 01-4.682 7.897 9 9 0 01-5.59 1.013c-1.203-.17-1.805-.255-1.964-.267-.257-.02-.165-.016-.423-.014-.159 0-.34.014-.702.04l-2.153.153c-.857.062-1.286.092-1.607-.06a1.348 1.348 0 01-.641-.64c-.152-.32-.122-.75-.06-1.608l.153-2.153c.026-.362.04-.542.04-.702.002-.258.006-.166-.014-.423-.012-.159-.098-.76-.268-1.964A9 9 0 1121.5 12z"
|
||||
strokeWidth="1.5"
|
||||
d="m7.5 3.25 4.5 3.5 4.5-3.5m-11.75 17h14.5a2 2 0 0 0 2-2v-9.5a2 2 0 0 0-2-2H4.75a2 2 0 0 0-2 2v9.5a2 2 0 0 0 2 2Z"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
|
||||
7
packages/types/index.d.ts
vendored
7
packages/types/index.d.ts
vendored
@@ -165,3 +165,10 @@ export interface NIP05 {
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export interface Relays {
|
||||
connected: string[];
|
||||
read: string[];
|
||||
write: string[];
|
||||
both: string[];
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ export function NoteActivity({ className }: { className?: string }) {
|
||||
{mentions.splice(0, 4).map((mention) => (
|
||||
<User.Provider key={mention} pubkey={mention}>
|
||||
<User.Root>
|
||||
<User.Name className="text-sm font-medium" />
|
||||
<User.Name className="text-sm font-medium" prefix="@" />
|
||||
</User.Root>
|
||||
</User.Provider>
|
||||
))}
|
||||
|
||||
@@ -3,19 +3,19 @@ import { useUserContext } from "./provider";
|
||||
|
||||
export function UserName({
|
||||
className,
|
||||
suffix,
|
||||
prefix,
|
||||
}: {
|
||||
className?: string;
|
||||
suffix?: string;
|
||||
prefix?: string;
|
||||
}) {
|
||||
const user = useUserContext();
|
||||
|
||||
return (
|
||||
<div className={cn("max-w-[12rem] truncate", className)}>
|
||||
{prefix}
|
||||
{user.profile?.display_name ||
|
||||
user.profile?.name ||
|
||||
displayNpub(user.pubkey, 16)}
|
||||
{suffix}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user