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,16 +220,30 @@ async fn accept(stream: TcpStream) {
info!("User {} disconnected.", &addr); info!("User {} disconnected.", &addr);
CONNECTIONS.lock().unwrap().remove(&addr); CONNECTIONS.lock().unwrap().remove(&addr);
let mut offline = None;
{
let session = session.lock().unwrap(); let session = session.lock().unwrap();
if let Some(session) = session.as_ref() { if let Some(session) = session.as_ref() {
let mut users = USERS.write().unwrap(); let mut users = USERS.write().unwrap();
users.remove(&session.user_id, &addr); users.remove(&session.user_id, &addr);
if users.get_left(&session.user_id).is_none() { if users.get_left(&session.user_id).is_none() {
get_hive().drop_client(&session.user_id).unwrap(); 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) {
let mut targets = vec![]; let mut targets = vec![];
{ {

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": {