interaction system

This commit is contained in:
2026-01-13 12:55:25 +08:00
parent efb2a2e4d1
commit 354e362ac3
15 changed files with 381 additions and 12 deletions

33
src/events/interaction.ts Normal file
View File

@@ -0,0 +1,33 @@
import { listen } from "@tauri-apps/api/event";
import { addInteraction } from "$lib/stores/interaction-store";
import type { InteractionPayloadDto } from "../types/bindings/InteractionPayloadDto";
import type { InteractionDeliveryFailedDto } from "../types/bindings/InteractionDeliveryFailedDto";
let unlistenReceived: (() => void) | undefined;
let unlistenFailed: (() => void) | undefined;
export async function initInteractionListeners() {
unlistenReceived = await listen<InteractionPayloadDto>(
"interaction-received",
(event) => {
console.log("Received interaction:", event.payload);
addInteraction(event.payload);
},
);
unlistenFailed = await listen<InteractionDeliveryFailedDto>(
"interaction-delivery-failed",
(event) => {
console.error("Interaction delivery failed:", event.payload);
// You might want to show a toast or alert here
alert(
`Failed to send message to user ${event.payload.recipientUserId}: ${event.payload.reason}`,
);
},
);
}
export function stopInteractionListeners() {
if (unlistenReceived) unlistenReceived();
if (unlistenFailed) unlistenFailed();
}