Skip to content

Commit

Permalink
User register method
Browse files Browse the repository at this point in the history
  • Loading branch information
fatalerrorcoded committed May 19, 2021
1 parent daffe80 commit 364db78
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/state/room/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 62,22 @@ impl<'r> RoomUsers {
})
}

pub async fn register(&'r self, token: &str) -> Option<UserGuard<'r>> {
let mut registrations = self.room.registrations.write().await;
let registration = registrations.remove(token)?;
drop(registrations);

let users = self.room.users.read().await;
let user = users.get(&registration)?;
let id = {
let mut user = user.write().await;
user.register().await;
user.id().to_string()
};

Some(UserGuard { inner: users, id })
}

pub async fn remove(&'r self, id: &str) -> Result<(), ()> {
let mut users = self.room.users.write().await;
match users.remove(id) {
Expand Down

0 comments on commit 364db78

Please sign in to comment.