feat(service): expand service layer with new domain operations
- Add IM service modules: audit, channel roles, custom emojis, forum tags, integrations, invitations, repo links, slash commands, stages, voice, webhooks - Add PR service modules: review requests, templates - Add repo service modules: contributors, release assets, git extras (archive, branch rename, commit extras, diff/merge, tag, tree) - Add user service: social (follow/block) - Add internal auth service - Update existing service modules with expanded functionality - Remove deleted IM modules: articles, delivery trace, drafts, follows, messages, polls, presence, reactions, threads
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::error::AppError;
|
||||
use crate::models::channels::VoiceParticipant;
|
||||
use crate::service::ImService;
|
||||
|
||||
use super::session::ImSession;
|
||||
|
||||
#[derive(Deserialize, Serialize, Clone, Debug, utoipa::ToSchema)]
|
||||
pub struct UpdateVoiceStateParams {
|
||||
pub session_id: Option<String>,
|
||||
pub muted: Option<bool>,
|
||||
pub deafened: Option<bool>,
|
||||
pub self_muted: Option<bool>,
|
||||
pub self_deafened: Option<bool>,
|
||||
pub self_video: Option<bool>,
|
||||
pub streaming: Option<bool>,
|
||||
}
|
||||
|
||||
impl ImService {
|
||||
pub async fn voice_participant_list(
|
||||
&self,
|
||||
_ctx: &ImSession,
|
||||
channel_id: Uuid,
|
||||
) -> Result<Vec<VoiceParticipant>, AppError> {
|
||||
sqlx::query_as::<_, VoiceParticipant>(
|
||||
"SELECT id, channel_id, user_id, session_id, deafened, muted, \
|
||||
self_deafened, self_muted, self_video, streaming, speaking, \
|
||||
joined_at, left_at \
|
||||
FROM voice_participant WHERE channel_id = $1 AND left_at IS NULL \
|
||||
ORDER BY joined_at",
|
||||
)
|
||||
.bind(channel_id)
|
||||
.fetch_all(self.ctx.db.reader())
|
||||
.await
|
||||
.map_err(AppError::Database)
|
||||
}
|
||||
|
||||
pub async fn voice_state_update(
|
||||
&self,
|
||||
ctx: &ImSession,
|
||||
channel_id: Uuid,
|
||||
params: UpdateVoiceStateParams,
|
||||
) -> Result<VoiceParticipant, AppError> {
|
||||
let now = chrono::Utc::now();
|
||||
sqlx::query_as::<_, VoiceParticipant>(
|
||||
"INSERT INTO voice_participant \
|
||||
(id, channel_id, user_id, session_id, muted, deafened, \
|
||||
self_muted, self_deafened, self_video, streaming, speaking, joined_at) \
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, false, false, $10) \
|
||||
ON CONFLICT (channel_id, user_id) DO UPDATE SET \
|
||||
session_id = COALESCE($4, voice_participant.session_id), \
|
||||
muted = COALESCE($5, voice_participant.muted), \
|
||||
deafened = COALESCE($6, voice_participant.deafened), \
|
||||
self_muted = COALESCE($7, voice_participant.self_muted), \
|
||||
self_deafened = COALESCE($8, voice_participant.self_deafened), \
|
||||
self_video = COALESCE($9, voice_participant.self_video) \
|
||||
RETURNING id, channel_id, user_id, session_id, deafened, muted, \
|
||||
self_deafened, self_muted, self_video, streaming, speaking, \
|
||||
joined_at, left_at",
|
||||
)
|
||||
.bind(Uuid::now_v7())
|
||||
.bind(channel_id)
|
||||
.bind(ctx.user)
|
||||
.bind(params.session_id.as_deref())
|
||||
.bind(params.muted.unwrap_or(false))
|
||||
.bind(params.deafened.unwrap_or(false))
|
||||
.bind(params.self_muted.unwrap_or(false))
|
||||
.bind(params.self_deafened.unwrap_or(false))
|
||||
.bind(params.self_video.unwrap_or(false))
|
||||
.bind(now)
|
||||
.fetch_one(self.ctx.db.writer())
|
||||
.await
|
||||
.map_err(AppError::Database)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user