mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
Add desktop search and result anchors (#15)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user