Hook for creating, updating, and deleting messages in cricket discussion rooms. Supports real-time messaging with validation and error handling.Parameters:
Validation:Messages are validated using Zod schemas:
CreateRoomMessageSchema: Validates roomId and content
UpdateRoomMessageSchema: Validates roomId, roomMessageId, and content
Error Handling:The hook displays specific error toasts for each operation:
Operation
Error Message
Create
”Error sending message. Please try again later.”
Update
”Error updating message. Please try again later.”
Delete
”Error deleting message. Please try again later.”
Validation errors display the specific validation message from the schema.Real-time Updates:While the hook handles mutations, real-time message updates are managed by Appwrite subscriptions in the room component:
// In the room componentuseEffect(() => { const unsubscribe = client.subscribe( `databases.${DATABASE_ID}.tables.${TABLE_ID}.rows`, (res) => { if (res.events.includes("databases.*.tables.*.rows.*.create")) { // Add new message to state } if (res.events.includes("databases.*.tables.*.rows.*.update")) { // Update message in state } if (res.events.includes("databases.*.tables.*.rows.*.delete")) { // Remove message from state } } ); return () => unsubscribe();}, [roomId]);