1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00

Implement basic chat functionality

This commit is contained in:
NGnius (Graham)
2025-04-14 21:17:41 -04:00
parent 4d2ddaeafb
commit 792a6362e3
37 changed files with 1119 additions and 34 deletions

View File

@@ -8,6 +8,10 @@ pub struct UserState<C: Clone = ()> {
impl <C: Clone> UserState<C> {
pub fn update_with_auth(&self, auth_str: &str) -> bool {
self.update_with_auth_ext(auth_str, |_| Some(Default::default()))
}
pub fn update_with_auth_ext<F: FnOnce(&crate::persist::user::UserToken) -> Option<std::collections::HashMap<std::any::TypeId, Box<dyn std::any::Any + Send + Sync + 'static>>>>(&self, auth_str: &str, ext_f: F) -> bool {
let mut lock = self.state.write().unwrap();
match &*lock {
InitState::Unauthenticated(auth) => {
@@ -21,7 +25,12 @@ impl <C: Clone> UserState<C> {
token: splits[1].to_owned(),
refresh_token: splits[2].to_owned(),
};
match auth.authenticate(token) {
let ext = if let Some(ext) = ext_f(&token) {
ext
} else {
return false;
};
match auth.authenticate(token, ext) {
Ok(user) => {
*lock = InitState::Authenticated(std::sync::Arc::new(user));
true