420dedbc1e
- 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
58 lines
1.3 KiB
Rust
58 lines
1.3 KiB
Rust
use std::sync::Arc;
|
|
|
|
use serde::Serialize;
|
|
use uuid::Uuid;
|
|
|
|
use crate::service::ServiceContext;
|
|
|
|
pub mod audit;
|
|
pub mod categories;
|
|
pub mod channel_roles;
|
|
pub mod channels;
|
|
pub mod custom_emojis;
|
|
pub mod events;
|
|
pub mod forum_tags;
|
|
pub mod integrations;
|
|
pub mod invitations;
|
|
pub mod members;
|
|
pub mod repo_links;
|
|
pub mod session;
|
|
pub mod slash_commands;
|
|
pub mod stages;
|
|
pub mod util;
|
|
pub mod voice;
|
|
pub mod webhooks;
|
|
|
|
pub use session::ImSession;
|
|
|
|
#[derive(Clone)]
|
|
pub struct ImService {
|
|
pub ctx: Arc<ServiceContext>,
|
|
}
|
|
|
|
impl ImService {
|
|
pub(crate) fn emit_event(&self, event: events::ImEvent) {
|
|
let _ = self.ctx.im_events.publish(event);
|
|
}
|
|
|
|
pub(crate) async fn publish<T: Serialize>(&self, subject: &str, request_id: Uuid, event: &T) {
|
|
match self
|
|
.ctx
|
|
.nats
|
|
.publish_with_headers(
|
|
subject,
|
|
&serde_json::to_vec(event).unwrap_or_default(),
|
|
vec![("X-Request-Id".into(), request_id.to_string())],
|
|
)
|
|
.await
|
|
{
|
|
Ok(_) => {
|
|
tracing::debug!(subject, %request_id, "nats event published");
|
|
}
|
|
Err(e) => {
|
|
tracing::warn!(subject, error = %e, "nats publish failed");
|
|
}
|
|
}
|
|
}
|
|
}
|