import { invoke } from "@tauri-apps/api/core"; import { listen, type UnlistenFn } from "@tauri-apps/api/event"; import type { PublicIdentity, CommunityMeta, ChannelMeta, CategoryMeta, ChatMessage, Member, DuskEvent, UserSettings, DirectoryEntry, ChallengeExport, VoiceParticipant, VoiceMediaState, DirectMessage, DMConversationMeta, GifResponse, } from "./types"; // -- identity -- export async function hasIdentity(): Promise { return invoke("has_identity"); } export async function loadIdentity(): Promise { return invoke("load_identity"); } export async function createIdentity( displayName: string, bio?: string, challengeData?: ChallengeExport, ): Promise { return invoke("create_identity", { displayName, bio, challengeData }); } export async function updateDisplayName(name: string): Promise { return invoke("update_display_name", { name }); } export async function updateProfile( displayName: string, bio: string, ): Promise { return invoke("update_profile", { displayName, bio }); } // -- settings -- export async function loadSettings(): Promise { return invoke("load_settings"); } export async function saveSettings(settings: UserSettings): Promise { return invoke("save_settings", { settings }); } // -- node lifecycle -- export async function startNode(): Promise { return invoke("start_node"); } export async function stopNode(): Promise { return invoke("stop_node"); } // -- community -- export async function createCommunity( name: string, description: string, ): Promise { return invoke("create_community", { name, description }); } export async function joinCommunity( inviteCode: string, ): Promise { return invoke("join_community", { inviteCode }); } export async function leaveCommunity(communityId: string): Promise { return invoke("leave_community", { communityId }); } export async function getCommunities(): Promise { return invoke("get_communities"); } // -- channels -- export async function createChannel( communityId: string, name: string, topic: string, kind?: string, categoryId?: string | null, ): Promise { return invoke("create_channel", { communityId, name, topic, kind, categoryId, }); } export async function getChannels(communityId: string): Promise { return invoke("get_channels", { communityId }); } export async function createCategory( communityId: string, name: string, ): Promise { return invoke("create_category", { communityId, name }); } export async function getCategories( communityId: string, ): Promise { return invoke("get_categories", { communityId }); } export async function reorderChannels( communityId: string, channelIds: string[], ): Promise { return invoke("reorder_channels", { communityId, channelIds }); } // -- messages -- export async function sendMessage( channelId: string, content: string, ): Promise { return invoke("send_message", { channelId, content }); } export async function getMessages( channelId: string, before?: number, limit?: number, ): Promise { return invoke("get_messages", { channelId, before, limit }); } // -- members -- export async function getMembers(communityId: string): Promise { return invoke("get_members", { communityId }); } export async function sendTypingIndicator(channelId: string): Promise { return invoke("send_typing", { channelId }); } export async function broadcastPresence(status: string): Promise { return invoke("broadcast_presence", { status }); } // -- moderation -- export async function deleteMessage( communityId: string, messageId: string, ): Promise { return invoke("delete_message", { communityId, messageId }); } export async function kickMember( communityId: string, memberPeerId: string, ): Promise { return invoke("kick_member", { communityId, memberPeerId }); } export async function generateInvite(communityId: string): Promise { return invoke("generate_invite", { communityId }); } // -- user directory -- export async function getKnownPeers(): Promise { return invoke("get_known_peers"); } export async function searchDirectory( query: string, ): Promise { return invoke("search_directory", { query }); } export async function getFriends(): Promise { return invoke("get_friends"); } export async function addFriend(peerId: string): Promise { return invoke("add_friend", { peerId }); } export async function removeFriend(peerId: string): Promise { return invoke("remove_friend", { peerId }); } export async function discoverGlobalPeers(): Promise { return invoke("discover_global_peers"); } export async function setRelayAddress(relayAddr: string): Promise { return invoke("set_relay_address", { relayAddr }); } export async function resetIdentity(): Promise { return invoke("reset_identity"); } // -- connectivity -- export async function checkInternetConnectivity(): Promise { return invoke("check_internet_connectivity"); } // -- events -- export function onDuskEvent( callback: (event: DuskEvent) => void, ): Promise { return listen("dusk-event", (e) => callback(e.payload)); } // -- voice -- export async function joinVoiceChannel( communityId: string, channelId: string, ): Promise { return invoke("join_voice_channel", { communityId, channelId }); } export async function leaveVoiceChannel( communityId: string, channelId: string, ): Promise { return invoke("leave_voice_channel", { communityId, channelId }); } export async function updateVoiceMediaState( communityId: string, channelId: string, mediaState: VoiceMediaState, ): Promise { return invoke("update_voice_media_state", { communityId, channelId, mediaState, }); } export async function sendVoiceSdp( communityId: string, channelId: string, toPeer: string, sdpType: string, sdp: string, ): Promise { return invoke("send_voice_sdp", { communityId, channelId, toPeer, sdpType, sdp, }); } export async function sendVoiceIceCandidate( communityId: string, channelId: string, toPeer: string, candidate: string, sdpMid: string | null, sdpMlineIndex: number | null, ): Promise { return invoke("send_voice_ice_candidate", { communityId, channelId, toPeer, candidate, sdpMid, sdpMlineIndex, }); } export async function getVoiceParticipants( communityId: string, channelId: string, ): Promise { return invoke("get_voice_participants", { communityId, channelId }); } // -- direct messages -- export async function sendDM( peerId: string, content: string, ): Promise { return invoke("send_dm", { peerId, content }); } export async function getDMMessages( peerId: string, before?: number, limit?: number, ): Promise { return invoke("get_dm_messages", { peerId, before, limit }); } export async function getDMConversations(): Promise { return invoke("get_dm_conversations"); } export async function markDMRead(peerId: string): Promise { return invoke("mark_dm_read", { peerId }); } export async function deleteDMConversation(peerId: string): Promise { return invoke("delete_dm_conversation", { peerId }); } export async function sendDMTyping(peerId: string): Promise { return invoke("send_dm_typing", { peerId }); } export async function openDMConversation( peerId: string, displayName: string, ): Promise { return invoke("open_dm_conversation", { peerId, displayName }); } // -- gifs -- export async function searchGifs( query: string, limit?: number, ): Promise { return invoke("search_gifs", { query, limit }); } export async function getTrendingGifs(limit?: number): Promise { return invoke("get_trending_gifs", { limit }); }