mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
46 lines
1.9 KiB
Rust
46 lines
1.9 KiB
Rust
use polariton_server::operations::{SimpleOpError, SimpleOperation, SimpleOpImpl};
|
|
use polariton::operation::{ParameterTable, Typed};
|
|
|
|
const CODE: u8 = 37;
|
|
|
|
const CLAN_NAME_PARAM_KEY: u8 = 31; // str; in and out
|
|
|
|
pub(super) struct ClanInviteDecliner {
|
|
social: std::sync::Arc<crate::SocialMesh>,
|
|
}
|
|
|
|
#[async_trait::async_trait]
|
|
impl SimpleOperation<crate::data::custom::CustomType> for ClanInviteDecliner {
|
|
type User = crate::UserTy;
|
|
const CODE: u8 = CODE;
|
|
|
|
async fn handle(&self, mut params: ParameterTable<crate::data::custom::CustomType>, user: &Self::User) -> Result<ParameterTable<crate::data::custom::CustomType>, SimpleOpError> {
|
|
if let Some(Typed::Str(clan_name)) = params.remove(&CLAN_NAME_PARAM_KEY) {
|
|
let user_info = user.user()?;
|
|
log::debug!("User {} wants to decline invite to clan {}", user_info.public_id(), clan_name.string);
|
|
let members_info = user_info.decline_clan_invite(&clan_name.string).await?;
|
|
let mut online_clan_members: std::collections::HashSet<String> = members_info.iter()
|
|
.map(|mem| mem.public_id.clone())
|
|
.collect();
|
|
self.social.filter_online_only(&mut online_clan_members).await;
|
|
|
|
let my_pub_id = user_info.public_id();
|
|
let event = crate::events::clan_member_left::ClanMemberLeft {
|
|
leaver_public_id: my_pub_id.to_owned(),
|
|
new_leader_public_id: None,
|
|
};
|
|
for online_member in online_clan_members.iter() {
|
|
if online_member == my_pub_id { continue; }
|
|
self.social.send_event_to(online_member, event.clone()).await;
|
|
}
|
|
}
|
|
Ok(params)
|
|
}
|
|
}
|
|
|
|
pub(super) fn clan_decline_provider(init_ctx: &crate::InitConfig) -> SimpleOpImpl<crate::data::custom::CustomType, crate::UserTy, ClanInviteDecliner> {
|
|
SimpleOpImpl::new(ClanInviteDecliner {
|
|
social: init_ctx.social.clone()
|
|
})
|
|
}
|