(
config: &DiscordConfig,
logged_in_user: Option<&CurrentUser>,
plugins: &[Plugin],
)
| 370 | } |
| 371 | |
| 372 | pub async fn fetch_plugin_authors( |
| 373 | config: &DiscordConfig, |
| 374 | logged_in_user: Option<&CurrentUser>, |
| 375 | plugins: &[Plugin], |
| 376 | ) -> ApiResult<Vec<PluginResponse>> { |
| 377 | let mut ids: Vec<_> = plugins.iter().map(|v| v.author_id).collect::<Vec<_>>(); |
| 378 | ids.sort_unstable(); |
| 379 | ids.dedup(); |
| 380 | |
| 381 | let mut fetched_users: Vec<User> = Vec::with_capacity(ids.len()); |
| 382 | for id in ids { |
| 383 | let user = fetch_discord_user(config, logged_in_user, id).await?; |
| 384 | let is_staff = config.owners.iter().any(|v| v.id == id); |
| 385 | fetched_users.push(User { |
| 386 | inner: user, |
| 387 | is_bl_staff: is_staff, |
| 388 | is_bl_trusted: is_staff, |
| 389 | }); |
| 390 | } |
| 391 | |
| 392 | Ok(plugins |
| 393 | .iter() |
| 394 | .map(|v| PluginResponse { |
| 395 | plugin: v.clone(), |
| 396 | author: fetched_users |
| 397 | .iter() |
| 398 | // fetch_discord_user always returns a user on Ok, it errors out on failure |
| 399 | // so all users are present at this point |
| 400 | .find(|u| u.inner.id == v.author_id) |
| 401 | .unwrap() |
| 402 | .clone(), |
| 403 | }) |
| 404 | .collect()) |
| 405 | } |
| 406 | |
| 407 | async fn fetch_discord_user( |
| 408 | config: &DiscordConfig, |
no test coverage detected