Add event when user goes offline.

This commit is contained in:
Paul
2021-05-03 08:57:49 +01:00
parent 92bface6ae
commit 2e996a487b
3 changed files with 28 additions and 7 deletions

7
publish.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
# Tip: for subsequent builds, don't update Cargo.toml
# in order to not download all the crates again.
# Update Cargo.toml on major release.
version=0.4.1-alpha.4
docker build -t revoltchat/server:${version} . &&
docker push revoltchat/server:${version}

View File

@@ -220,14 +220,28 @@ async fn accept(stream: TcpStream) {
info!("User {} disconnected.", &addr); info!("User {} disconnected.", &addr);
CONNECTIONS.lock().unwrap().remove(&addr); CONNECTIONS.lock().unwrap().remove(&addr);
let session = session.lock().unwrap(); let mut offline = None;
if let Some(session) = session.as_ref() { {
let mut users = USERS.write().unwrap(); let session = session.lock().unwrap();
users.remove(&session.user_id, &addr); if let Some(session) = session.as_ref() {
if users.get_left(&session.user_id).is_none() { let mut users = USERS.write().unwrap();
get_hive().drop_client(&session.user_id).unwrap(); users.remove(&session.user_id, &addr);
if users.get_left(&session.user_id).is_none() {
get_hive().drop_client(&session.user_id).unwrap();
offline = Some(session.user_id.clone());
}
} }
} }
if let Some(id) = offline {
ClientboundNotification::UserPresence {
id: id.clone(),
online: false,
}
.publish(id)
.await
.ok();
}
} }
pub fn publish(ids: Vec<String>, notification: ClientboundNotification) { pub fn publish(ids: Vec<String>, notification: ClientboundNotification) {

View File

@@ -9,7 +9,7 @@ use rocket_contrib::json::JsonValue;
#[get("/")] #[get("/")]
pub async fn root() -> JsonValue { pub async fn root() -> JsonValue {
json!({ json!({
"revolt": "0.4.1-alpha.3", "revolt": "0.4.1-alpha.4",
"features": { "features": {
"registration": !*DISABLE_REGISTRATION, "registration": !*DISABLE_REGISTRATION,
"captcha": { "captcha": {