use ::session::AuthedUser; use api::http::{Json, Path, State}; use api::rest::{AppResponseData, NoData}; use crate::errors::ApiError; use crate::services::presence::{PresenceDto, SetPresenceCmd}; use crate::services::service::ChatService; #[utoipa::path( put, path = "/chat/presence", tag = "chat", description = "更新当前用户的在线状态、离开状态或隐身状态。", request_body = SetPresenceCmd, responses( (status = 200, description = "presence updated", body = AppResponseData), (status = 401, description = "unauthorized", body = AppResponseData), (status = 400, description = "request failed validation", body = AppResponseData) ) )] pub async fn set_presence( State(service): State, AuthedUser(uid): AuthedUser, Json(cmd): Json, ) -> Result, ApiError> { let dto = service.participants.set_presence(uid, cmd).await?; Ok(AppResponseData::ok(dto)) } #[utoipa::path( get, path = "/chat/users/{user_id}/presence", tag = "chat", description = "读取指定用户的在线状态;仅在可见关系成立时返回。", params(("user_id" = i64, Path, description = "user id")), responses( (status = 200, description = "presence", body = AppResponseData), (status = 401, description = "unauthorized", body = AppResponseData) ) )] pub async fn get_presence( State(service): State, AuthedUser(uid): AuthedUser, Path(user_id): Path, ) -> Result, ApiError> { let dto = service.participants.get_presence_for(uid, user_id).await?; Ok(AppResponseData::ok(dto)) } #[utoipa::path( get, path = "/chat/spaces/{space_name}/presences", tag = "chat", description = "返回指定空间活跃成员及其在线状态。", params(("space_name" = String, Path, description = "space name")), responses( (status = 200, description = "space presences", body = AppResponseData>), (status = 404, description = "not found", body = AppResponseData), (status = 401, description = "authentication required", body = AppResponseData) ) )] pub async fn list_space_presences( State(service): State, AuthedUser(uid): AuthedUser, Path(space_name): Path, ) -> Result>, ApiError> { let presences = service .participants .list_space_presences(uid, &space_name) .await?; Ok(AppResponseData::ok(presences)) }