Merge pull request #14 from polyphony-chat/improvement/user-on-instance

Create internal User and API UserObject
This commit is contained in:
Flori 2023-04-24 15:11:36 +02:00 committed by GitHub
commit 8fa85e42fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 4 deletions

View File

@ -3,7 +3,7 @@ pub mod schemas {
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, fmt};
use crate::errors::FieldFormatError;
use crate::{errors::FieldFormatError, URLBundle};
/**
A struct that represents a well-formed email address.
@ -380,6 +380,76 @@ pub mod schemas {
pub message: String,
pub code: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct UserObject {
id: String,
username: String,
discriminator: String,
avatar: Option<String>,
bot: Option<bool>,
system: Option<bool>,
mfa_enabled: Option<bool>,
banner: Option<bool>,
accent_color: Option<String>,
locale: String,
verified: Option<bool>,
email: Option<String>,
flags: i8,
premium_type: Option<i8>,
public_flags: Option<i8>,
}
#[derive(Debug)]
pub struct User {
logged_in: bool,
belongs_to: URLBundle,
token: String,
pub settings: UserSettings,
pub object: UserObject,
}
impl User {
pub fn is_logged_in(&self) -> bool {
if self.logged_in == true {
true
} else {
false
}
}
pub fn belongs_to(&self) -> URLBundle {
return self.belongs_to.clone();
}
pub fn token(&self) -> String {
return self.token.clone();
}
pub fn set_logged_in(&mut self, bool: bool) {
self.logged_in = bool;
}
pub fn set_token(&mut self, token: String) {
self.token = token;
}
pub fn new(
logged_in: bool,
belongs_to: URLBundle,
token: String,
settings: UserSettings,
object: UserObject,
) -> User {
User {
logged_in,
belongs_to,
token,
settings,
object,
}
}
}
}
// I know that some of these tests are... really really basic and unneccessary, but sometimes, I

View File

@ -1,4 +1,4 @@
use crate::api::schemas::schemas::InstancePoliciesSchema;
use crate::api::schemas::schemas::{InstancePoliciesSchema, User};
use crate::errors::{FieldFormatError, InstanceServerError};
use crate::limit::LimitedRequester;
use crate::URLBundle;
@ -15,7 +15,7 @@ pub struct Instance {
pub instance_info: InstancePoliciesSchema,
pub requester: LimitedRequester,
//pub gateway: Gateway,
pub users: HashMap<Token, Username>,
pub users: HashMap<Token, User>,
}
impl Instance {
@ -29,7 +29,7 @@ impl Instance {
urls: URLBundle,
requester: LimitedRequester,
) -> Result<Instance, InstanceServerError> {
let users: HashMap<Token, Username> = HashMap::new();
let users: HashMap<Token, User> = HashMap::new();
let mut instance = Instance {
urls,
instance_info: InstancePoliciesSchema::new(