mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
feat: add channel creation flow (#8)
This commit is contained in:
@@ -3,6 +3,7 @@ import { invoke } from "@tauri-apps/api/core";
|
||||
import type {
|
||||
Channel,
|
||||
ChannelType,
|
||||
CreateChannelInput,
|
||||
Identity,
|
||||
RelayEvent,
|
||||
} from "@/shared/api/types";
|
||||
@@ -21,6 +22,17 @@ type RawChannel = {
|
||||
participant_pubkeys: string[];
|
||||
};
|
||||
|
||||
function fromRawChannel(channel: RawChannel): Channel {
|
||||
return {
|
||||
id: channel.id,
|
||||
name: channel.name,
|
||||
channelType: channel.channel_type,
|
||||
description: channel.description,
|
||||
participants: channel.participants,
|
||||
participantPubkeys: channel.participant_pubkeys,
|
||||
};
|
||||
}
|
||||
|
||||
export async function getIdentity(): Promise<Identity> {
|
||||
const identity = await invoke<RawIdentity>("get_identity");
|
||||
|
||||
@@ -36,15 +48,14 @@ export function getRelayWsUrl(): Promise<string> {
|
||||
|
||||
export async function getChannels(): Promise<Channel[]> {
|
||||
const channels = await invoke<RawChannel[]>("get_channels");
|
||||
return channels.map(fromRawChannel);
|
||||
}
|
||||
|
||||
return channels.map((channel) => ({
|
||||
id: channel.id,
|
||||
name: channel.name,
|
||||
channelType: channel.channel_type,
|
||||
description: channel.description,
|
||||
participants: channel.participants,
|
||||
participantPubkeys: channel.participant_pubkeys,
|
||||
}));
|
||||
export async function createChannel(
|
||||
input: CreateChannelInput,
|
||||
): Promise<Channel> {
|
||||
const channel = await invoke<RawChannel>("create_channel", input);
|
||||
return fromRawChannel(channel);
|
||||
}
|
||||
|
||||
export async function signRelayEvent(input: {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export type ChannelType = "stream" | "forum" | "dm";
|
||||
export type ChannelVisibility = "open" | "private";
|
||||
|
||||
export type Channel = {
|
||||
id: string;
|
||||
@@ -9,6 +10,13 @@ export type Channel = {
|
||||
participantPubkeys: string[];
|
||||
};
|
||||
|
||||
export type CreateChannelInput = {
|
||||
name: string;
|
||||
channelType: Exclude<ChannelType, "dm">;
|
||||
visibility: ChannelVisibility;
|
||||
description?: string;
|
||||
};
|
||||
|
||||
export type Identity = {
|
||||
pubkey: string;
|
||||
displayName: string;
|
||||
|
||||
Reference in New Issue
Block a user