mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Factor in platoons during team assignment #88
This commit is contained in:
@@ -23,7 +23,7 @@ impl SimpleOperation<crate::data::custom::CustomType> for PlatoonPendingInviter
|
||||
let user_info = user.user()?;
|
||||
let my_public_id = user_info.public_id();
|
||||
log::debug!("Checking for pending platoon invite of user {}", my_public_id);
|
||||
if let Some(platoon_id) = self.social.platoon_of_user(my_public_id).await {
|
||||
if let Some(platoon_id) = self.social.platoon_invite_of_user(my_public_id).await {
|
||||
let members = self.social.users_of_platoon(&platoon_id).await;
|
||||
let social_infos = user_info.list_social_info(&[members[0].public_id.clone()]).await?;
|
||||
params.insert(INVITER_NAME_PARAM_KEY, Typed::Str(social_infos[0].public_id.clone().into()));
|
||||
|
||||
@@ -92,6 +92,20 @@ impl SocialMesh {
|
||||
.map(|x| x.to_owned())
|
||||
}
|
||||
|
||||
pub async fn platoon_invite_of_user(&self, public_id: &str) -> Option<String> {
|
||||
if let Some(platoon_id) = self.platoons.platoon_by_user.read().await.get(public_id) {
|
||||
if let Some(platoon) = self.platoons.platoon_by_id.read().await.get(platoon_id) {
|
||||
let myself = platoon.iter()
|
||||
.find(|mem| mem.public_id == public_id)
|
||||
.unwrap();
|
||||
if matches!(myself.status, crate::data::platoon::MemberStatus::Invited) {
|
||||
return Some(platoon_id.to_owned());
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub async fn users_of_platoon(&self, platoon_id: &str) -> Vec<PlatoonMemberInfo> {
|
||||
self.platoons.platoon_by_id.read().await
|
||||
.get(platoon_id)
|
||||
@@ -150,12 +164,14 @@ impl SocialMesh {
|
||||
}
|
||||
|
||||
pub async fn remove_user_from_platoon(&self, public_id: &str) -> bool {
|
||||
if let Some(platoon_id) = self.platoons.platoon_by_user.write().await.remove(public_id) {
|
||||
let mut platoon_by_user_lock = self.platoons.platoon_by_user.write().await;
|
||||
if let Some(platoon_id) = platoon_by_user_lock.remove(public_id) {
|
||||
let mut platoon_by_id_lock = self.platoons.platoon_by_id.write().await;
|
||||
if let Some(platoon) = platoon_by_id_lock.get_mut(&platoon_id) {
|
||||
platoon.retain(|member| member.public_id != public_id);
|
||||
if platoon.is_empty() {
|
||||
if platoon.len() <= 1 {
|
||||
platoon_by_id_lock.remove(&platoon_id);
|
||||
platoon_by_user_lock.retain(|_pub_id, platoon_id_val| platoon_id_val != &platoon_id);
|
||||
}
|
||||
true
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user