Log new messages
This commit is contained in:
parent
18194f586c
commit
9931a932bf
1 changed files with 11 additions and 3 deletions
|
|
@ -27,14 +27,16 @@ struct Client {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Room {
|
struct Room {
|
||||||
|
name: String,
|
||||||
clients: HashMap<SessionId, Client>,
|
clients: HashMap<SessionId, Client>,
|
||||||
last_message: MessageId,
|
last_message: MessageId,
|
||||||
last_timestamp: u128,
|
last_timestamp: u128,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Room {
|
impl Room {
|
||||||
fn new() -> Self {
|
fn new(name: String) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
name,
|
||||||
clients: HashMap::new(),
|
clients: HashMap::new(),
|
||||||
last_message: MessageId::of(&format!("{}", rand::thread_rng().gen::<u64>())),
|
last_message: MessageId::of(&format!("{}", rand::thread_rng().gen::<u64>())),
|
||||||
last_timestamp: util::timestamp(),
|
last_timestamp: util::timestamp(),
|
||||||
|
|
@ -109,6 +111,12 @@ impl Room {
|
||||||
content,
|
content,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
self.last_message = message.id();
|
||||||
|
info!(
|
||||||
|
"&{} now at {} ({})",
|
||||||
|
self.name, self.last_message, self.last_timestamp
|
||||||
|
);
|
||||||
|
|
||||||
self.notify_except(
|
self.notify_except(
|
||||||
id,
|
id,
|
||||||
&Packet::ntf(SendNtf {
|
&Packet::ntf(SendNtf {
|
||||||
|
|
@ -216,8 +224,8 @@ impl Server {
|
||||||
self.rooms
|
self.rooms
|
||||||
.lock()
|
.lock()
|
||||||
.await
|
.await
|
||||||
.entry(name)
|
.entry(name.clone())
|
||||||
.or_insert_with(|| Arc::new(Mutex::new(Room::new())))
|
.or_insert_with(|| Arc::new(Mutex::new(Room::new(name))))
|
||||||
.clone()
|
.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue