use crate::error::RoomError; use crate::service::RoomService; use crate::ws_context::WsUserContext; use chrono::Utc; use models::rooms::{room_message, room_message_reaction}; use sea_orm::*; use uuid::Uuid; impl RoomService { pub async fn room_message_reaction_list(&self, room_id: Uuid, message_id: Uuid, ctx: &WsUserContext) -> Result { let user_id = ctx.user_id; self.require_room_access(room_id, user_id).await?; let _msg = room_message::Entity::find_by_id(message_id).one(&self.db).await? .ok_or_else(|| RoomError::NotFound("Message not found".to_string()))?; self.get_message_reactions(message_id, Some(user_id)).await } pub async fn room_message_reaction_toggle(&self, room_id: Uuid, message_id: Uuid, emoji: String, ctx: &WsUserContext) -> Result { let user_id = ctx.user_id; self.require_room_access(room_id, user_id).await?; if emoji.is_empty() || emoji.len() > 50 { return Err(RoomError::BadRequest("Invalid emoji format".to_string())); } if let Some(existing) = room_message_reaction::Entity::find() .filter(room_message_reaction::Column::Room.eq(room_id)) .filter(room_message_reaction::Column::Message.eq(message_id)) .filter(room_message_reaction::Column::User.eq(user_id)) .filter(room_message_reaction::Column::Emoji.eq(&emoji)) .one(&self.db).await? { room_message_reaction::Entity::delete_by_id(existing.id).exec(&self.db).await?; } else { room_message_reaction::ActiveModel { id: Set(Uuid::now_v7()), room: Set(room_id), message: Set(message_id), user: Set(user_id), emoji: Set(emoji), created_at: Set(Utc::now()), }.insert(&self.db).await?; } self.get_message_reactions(message_id, Some(user_id)).await } }