Skip to content
Snippets Groups Projects
Commit 67b9b8ce authored by insert's avatar insert
Browse files

Users: Serve early adopter badge from server.

parent f1462d4e
Branches
Tags
No related merge requests found
#!/bin/bash #!/bin/bash
export version=0.4.1-alpha.12 export version=0.4.1-alpha.13
echo "pub const VERSION: &str = \"${version}\";" > src/version.rs echo "pub const VERSION: &str = \"${version}\";" > src/version.rs
...@@ -6,11 +6,15 @@ use mongodb::{ ...@@ -6,11 +6,15 @@ use mongodb::{
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use validator::Validate; use validator::Validate;
use num_enum::TryFromPrimitive;
use ulid::Ulid;
use std::ops;
use crate::database::permissions::user::UserPermissions; use crate::database::permissions::user::UserPermissions;
use crate::database::*; use crate::database::*;
use crate::notifications::websocket::is_online; use crate::notifications::websocket::is_online;
use crate::util::result::{Error, Result}; use crate::util::result::{Error, Result};
use crate::util::variables::EARLY_ADOPTER_BADGE;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub enum RelationshipStatus { pub enum RelationshipStatus {
...@@ -30,13 +34,6 @@ pub struct Relationship { ...@@ -30,13 +34,6 @@ pub struct Relationship {
pub status: RelationshipStatus, pub status: RelationshipStatus,
} }
/*
pub enum Badge {
Developer = 1,
Translator = 2,
}
*/
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub enum Presence { pub enum Presence {
Online, Online,
...@@ -62,6 +59,17 @@ pub struct UserProfile { ...@@ -62,6 +59,17 @@ pub struct UserProfile {
pub background: Option<File>, pub background: Option<File>,
} }
#[derive(Debug, PartialEq, Eq, TryFromPrimitive, Copy, Clone)]
#[repr(i32)]
pub enum Badges {
Developer = 1,
Translator = 2,
Supporter = 4,
EarlyAdopter = 256
}
impl_op_ex_commutative!(+ |a: &i32, b: &Badges| -> i32 { *a | *b as i32 });
// When changing this struct, update notifications/payload.rs#80 // When changing this struct, update notifications/payload.rs#80
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct User { pub struct User {
...@@ -110,6 +118,15 @@ impl User { ...@@ -110,6 +118,15 @@ impl User {
/// Mutate the user object to appear as seen by user. /// Mutate the user object to appear as seen by user.
pub fn with(mut self, permissions: UserPermissions<[u32; 1]>) -> User { pub fn with(mut self, permissions: UserPermissions<[u32; 1]>) -> User {
let mut badges = self.badges.unwrap_or_else(|| 0);
if let Ok(id) = Ulid::from_string(&self.id) {
if id.datetime().timestamp_millis() < *EARLY_ADOPTER_BADGE {
badges = badges + Badges::EarlyAdopter;
}
}
self.badges = Some(badges);
if permissions.get_view_profile() { if permissions.get_view_profile() {
self.online = Some(is_online(&self.id)); self.online = Some(is_online(&self.id));
} else { } else {
......
...@@ -16,6 +16,9 @@ pub enum ChannelPermission { ...@@ -16,6 +16,9 @@ pub enum ChannelPermission {
VoiceCall = 16, VoiceCall = 16,
} }
impl_op_ex!(+ |a: &ChannelPermission, b: &ChannelPermission| -> u32 { *a as u32 | *b as u32 });
impl_op_ex_commutative!(+ |a: &u32, b: &ChannelPermission| -> u32 { *a | *b as u32 });
bitfield! { bitfield! {
pub struct ChannelPermissions(MSB0 [u32]); pub struct ChannelPermissions(MSB0 [u32]);
u32; u32;
...@@ -26,9 +29,6 @@ bitfield! { ...@@ -26,9 +29,6 @@ bitfield! {
pub get_voice_call, _: 27; pub get_voice_call, _: 27;
} }
impl_op_ex!(+ |a: &ChannelPermission, b: &ChannelPermission| -> u32 { *a as u32 | *b as u32 });
impl_op_ex_commutative!(+ |a: &u32, b: &ChannelPermission| -> u32 { *a | *b as u32 });
impl<'a> PermissionCalculator<'a> { impl<'a> PermissionCalculator<'a> {
pub async fn calculate_channel(self) -> Result<u32> { pub async fn calculate_channel(self) -> Result<u32> {
let channel = if let Some(channel) = self.channel { let channel = if let Some(channel) = self.channel {
......
...@@ -64,6 +64,8 @@ lazy_static! { ...@@ -64,6 +64,8 @@ lazy_static! {
// Application Logic Settings // Application Logic Settings
pub static ref MAX_GROUP_SIZE: usize = pub static ref MAX_GROUP_SIZE: usize =
env::var("REVOLT_MAX_GROUP_SIZE").unwrap_or_else(|_| "50".to_string()).parse().unwrap(); env::var("REVOLT_MAX_GROUP_SIZE").unwrap_or_else(|_| "50".to_string()).parse().unwrap();
pub static ref EARLY_ADOPTER_BADGE: i64 =
env::var("REVOLT_EARLY_ADOPTER_BADGE").unwrap_or_else(|_| "0".to_string()).parse().unwrap();
} }
pub fn preflight_checks() { pub fn preflight_checks() {
......
pub const VERSION: &str = "0.4.1-alpha.12"; pub const VERSION: &str = "0.4.1-alpha.13";
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment