Add desktop search and result anchors (#15)

This commit is contained in:
Wes
2026-03-10 13:54:25 -07:00
committed by GitHub
parent 4fcc4c35cc
commit 1be84cc315
16 changed files with 1079 additions and 45 deletions
+47
View File
@@ -8,6 +8,8 @@ import type {
HomeFeedResponse,
Identity,
RelayEvent,
SearchMessagesInput,
SearchMessagesResponse,
} from "@/shared/api/types";
type RawIdentity = {
@@ -50,6 +52,22 @@ type RawHomeFeedResponse = {
};
};
type RawSearchHit = {
event_id: string;
content: string;
kind: number;
pubkey: string;
channel_id: string;
channel_name: string;
created_at: number;
score: number;
};
type RawSearchResponse = {
hits: RawSearchHit[];
found: number;
};
function fromRawChannel(channel: RawChannel): Channel {
return {
id: channel.id,
@@ -75,6 +93,19 @@ function fromRawFeedItem(item: RawFeedItem) {
};
}
function fromRawSearchHit(hit: RawSearchHit) {
return {
eventId: hit.event_id,
content: hit.content,
kind: hit.kind,
pubkey: hit.pubkey,
channelId: hit.channel_id,
channelName: hit.channel_name,
createdAt: hit.created_at,
score: hit.score,
};
}
export async function getIdentity(): Promise<Identity> {
const identity = await invoke<RawIdentity>("get_identity");
@@ -120,6 +151,22 @@ export async function getHomeFeed(
};
}
export async function searchMessages(
input: SearchMessagesInput,
): Promise<SearchMessagesResponse> {
const response = await invoke<RawSearchResponse>("search_messages", input);
return {
hits: response.hits.map(fromRawSearchHit),
found: response.found,
};
}
export async function getEventById(eventId: string): Promise<RelayEvent> {
const eventJson = await invoke<string>("get_event", { eventId });
return JSON.parse(eventJson) as RelayEvent;
}
export async function signRelayEvent(input: {
kind: number;
content: string;
+21
View File
@@ -74,3 +74,24 @@ export type GetHomeFeedInput = {
limit?: number;
types?: string;
};
export type SearchMessagesInput = {
q: string;
limit?: number;
};
export type SearchHit = {
eventId: string;
content: string;
kind: number;
pubkey: string;
channelId: string;
channelName: string;
createdAt: number;
score: number;
};
export type SearchMessagesResponse = {
hits: SearchHit[];
found: number;
};