forked from jmug/stoatchat
Users: Serve early adopter badge from server.
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
#!/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
|
||||
|
||||
@@ -6,11 +6,15 @@ use mongodb::{
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
use num_enum::TryFromPrimitive;
|
||||
use ulid::Ulid;
|
||||
use std::ops;
|
||||
|
||||
use crate::database::permissions::user::UserPermissions;
|
||||
use crate::database::*;
|
||||
use crate::notifications::websocket::is_online;
|
||||
use crate::util::result::{Error, Result};
|
||||
use crate::util::variables::EARLY_ADOPTER_BADGE;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||
pub enum RelationshipStatus {
|
||||
@@ -30,13 +34,6 @@ pub struct Relationship {
|
||||
pub status: RelationshipStatus,
|
||||
}
|
||||
|
||||
/*
|
||||
pub enum Badge {
|
||||
Developer = 1,
|
||||
Translator = 2,
|
||||
}
|
||||
*/
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub enum Presence {
|
||||
Online,
|
||||
@@ -62,6 +59,17 @@ pub struct UserProfile {
|
||||
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
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct User {
|
||||
@@ -110,6 +118,15 @@ impl User {
|
||||
|
||||
/// Mutate the user object to appear as seen by 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() {
|
||||
self.online = Some(is_online(&self.id));
|
||||
} else {
|
||||
|
||||
@@ -16,6 +16,9 @@ pub enum ChannelPermission {
|
||||
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! {
|
||||
pub struct ChannelPermissions(MSB0 [u32]);
|
||||
u32;
|
||||
@@ -26,9 +29,6 @@ bitfield! {
|
||||
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> {
|
||||
pub async fn calculate_channel(self) -> Result<u32> {
|
||||
let channel = if let Some(channel) = self.channel {
|
||||
|
||||
@@ -64,6 +64,8 @@ lazy_static! {
|
||||
// Application Logic Settings
|
||||
pub static ref MAX_GROUP_SIZE: usize =
|
||||
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() {
|
||||
|
||||
@@ -1 +1 @@
|
||||
pub const VERSION: &str = "0.4.1-alpha.12";
|
||||
pub const VERSION: &str = "0.4.1-alpha.13";
|
||||
|
||||
Reference in New Issue
Block a user