feat: allow reactions to particles in stream

Closes #111
This commit is contained in:
talksik
2026-04-08 10:14:47 -07:00
parent ac7336592a
commit 5f80bd15d5
4 changed files with 173 additions and 6 deletions
+19 -1
View File
@@ -12,6 +12,8 @@ import {
serverTimestamp,
where,
Timestamp,
arrayUnion,
arrayRemove,
type DocumentData,
type FirestoreDataConverter,
type QueryDocumentSnapshot,
@@ -21,7 +23,7 @@ import {
} from "firebase/firestore";
import { firestoreDb } from "@/firebase";
import { isContainerType, ParticleSchema } from "@/api/types";
import type { Particle, ParticleType, ParticlePropertiesMap } from "@/api/types";
import type { Particle, ParticleType, ParticlePropertiesMap, Reactions } from "@/api/types";
// --- Converter ---
@@ -87,6 +89,7 @@ const particleConverter: FirestoreDataConverter<Particle> = {
created_at: (raw.created_at as Timestamp).toDate(),
created_by_human_id: raw.created_by_human_id,
updated_at: raw.updated_at ? (raw.updated_at as Timestamp).toDate() : undefined,
reactions: raw.reactions ?? undefined,
});
default:
throw new Error(`Unknown particle type: ${type}`);
@@ -342,3 +345,18 @@ export async function updateStreamPlaybackMarker(
updated_at: serverTimestamp(),
});
}
export async function toggleParticleReaction(
docPath: string,
emoji: string,
humanId: string,
currentReactions?: Reactions,
): Promise<void> {
const particleRef = typedDoc(docPath);
const field = `reactions.${emoji}`;
const alreadyReacted = currentReactions?.[emoji]?.includes(humanId) ?? false;
await updateDoc(particleRef, {
[field]: alreadyReacted ? arrayRemove(humanId) : arrayUnion(humanId),
updated_at: serverTimestamp(),
});
}