fix: add back missing early adopter badge

This commit is contained in:
Zomatree
2025-04-22 19:44:30 +01:00
parent 02f18705f4
commit cc9ff9a632
6 changed files with 48 additions and 17 deletions

View File

@@ -3,12 +3,13 @@ use std::{collections::HashSet, str::FromStr, time::Duration};
use crate::{events::client::EventV1, Database, File, RatelimitEvent, AMQP};
use authifier::config::{EmailVerificationConfig, Template};
use futures::future::join_all;
use iso8601_timestamp::Timestamp;
use once_cell::sync::Lazy;
use rand::seq::SliceRandom;
use redis_kiss::{get_connection, AsyncCommands};
use revolt_config::{config, FeaturesLimits};
use revolt_models::v0::{self, UserFlags};
use revolt_models::v0::{self, UserFlags, UserBadges};
use revolt_presence::filter_online;
use revolt_result::{create_error, Result};
use serde_json::json;
@@ -349,15 +350,16 @@ impl User {
) -> Result<Vec<v0::User>> {
let online_ids = filter_online(ids).await;
Ok(db
Ok(join_all(
db
.fetch_users(ids)
.await?
.into_iter()
.map(|user| {
.map(|user| async {
let is_online = online_ids.contains(&user.id);
user.into_known(perspective, is_online)
user.into_known(perspective, is_online).await
})
.collect())
).await)
}
/// Find a free discriminator for a given username
@@ -821,4 +823,18 @@ impl User {
)
.await
}
/// Gets the user's badges along with calculating any dynamic badges
pub async fn get_badges(&self) -> u32 {
let config = config().await;
let badges = self.badges.unwrap_or_default() as u32;
if let Some(cutoff) = config.api.users.early_adopter_cutoff {
if Ulid::from_string(&self.id).unwrap().timestamp_ms() < cutoff {
return badges + UserBadges::EarlyAdopter as u32
};
};
badges
}
}