1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00

Platoons social functionality (#91)

### Description

This implements and completes #87 (to the best of my knowledge)

### Game

Robocraft

### Please confirm

- [x] I am the legal owner or represent the owner of all work submitted
- [x] I consent to my submission being added to this FOSS project
- [ ] This PR used LLMs to generate some or all of the code changes

Reviewed-on: https://git.ngram.ca/OpenJam/rc-servers/pulls/91
Co-authored-by: NG (Graham) <ngniusness@gmail.com>
Co-committed-by: NG (Graham) <ngniusness@gmail.com>
This commit is contained in:
NG (Graham)
2026-02-19 01:57:03 +00:00
committed by NGnius
parent a82488ab3a
commit 50b396f34a
49 changed files with 1152 additions and 47 deletions

View File

@@ -57,7 +57,7 @@ impl super::SocialUser for UserData {
format!("Failed to retrieve friends: {}", e),
)
})?;
let friend_ids: Vec<i32> = friends.iter().map(|(_, user)| user.id).collect();
let friend_ids = friends.iter().map(|(_, user)| user.id);
let friend_avatars = self.db.user_auxs_by_user_ids_and_descriptor(friend_ids, oj_rc_database::schema::user_aux::Descriptor::AvatarId).await
.map_err(|e| {
log::error!("Failed to retrieve friend avatars for user {} : {}", self.account.id, e);
@@ -81,6 +81,37 @@ impl super::SocialUser for UserData {
)
}
async fn list_social_info(&self, public_ids: &[String]) -> Result<Vec<super::SocialInfo>, polariton_server::operations::SimpleOpError> {
let users = self.db.users_by_public_id(public_ids.iter()).await
.map_err(|e| {
log::error!("Failed to retrieve friend avatars for user {} : {}", self.account.id, e);
polariton_server::operations::SimpleOpError::with_message(
crate::data::error_codes::SocialErrorCode::DatabaseError as i16,
format!("Failed to retrieve friend avatars: {}", e),
)
})?;
let user_ids = users.iter().map(|user| user.id);
let user_avatars = self.db.user_auxs_by_user_ids_and_descriptor(user_ids, oj_rc_database::schema::user_aux::Descriptor::AvatarId).await
.map_err(|e| {
log::error!("Failed to retrieve friend avatars for user {} : {}", self.account.id, e);
polariton_server::operations::SimpleOpError::with_message(
crate::data::error_codes::SocialErrorCode::DatabaseError as i16,
format!("Failed to retrieve friend avatars: {}", e),
)
})?;
let avatar_map: std::collections::HashMap<i32, u32> = user_avatars.iter()
.filter_map(|avatar| avatar.data.parse().ok().map(|avatar_id| (avatar.user_id, avatar_id)))
.collect();
Ok(users.iter()
.map(|user| super::SocialInfo {
public_id: user.public_id.clone(),
display_name: user.display_name.clone(),
avatar_id: avatar_map.get(&user.id).and_then(|&avatar_id| if avatar_id == u32::MAX { None } else { Some(avatar_id as i32) }),
})
.collect()
)
}
async fn has_unclaimed_match_rewards(&self) -> Result<bool, polariton_server::operations::SimpleOpError> {
let count = self.db.count_score_by_user_id_and_claimed(self.account.id, false).await
.map_err(|e| {