From 750f8c67380b6d9b1a3e7dd5fe554d03ac8485e1 Mon Sep 17 00:00:00 2001
From: Paul Makles <paulmakles@gmail.com>
Date: Tue, 11 Aug 2020 16:20:24 +0200
Subject: [PATCH] Provide version object at /, add ready event.

---
 Cargo.lock              |  2 +-
 Cargo.toml              |  2 +-
 src/notifications/ws.rs | 13 +++++++++++++
 src/routes/root.rs      |  7 ++++++-
 4 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 9e8c5de..6e85b9e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1885,7 +1885,7 @@ dependencies = [
 
 [[package]]
 name = "revolt"
-version = "0.2.6"
+version = "0.2.7"
 dependencies = [
  "bcrypt",
  "bitfield",
diff --git a/Cargo.toml b/Cargo.toml
index fa70586..849b553 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "revolt"
-version = "0.2.6"
+version = "0.2.7"
 authors = ["Paul Makles <paulmakles@gmail.com>"]
 edition = "2018"
 
diff --git a/src/notifications/ws.rs b/src/notifications/ws.rs
index c853aea..0d3f343 100644
--- a/src/notifications/ws.rs
+++ b/src/notifications/ws.rs
@@ -36,6 +36,8 @@ impl Handler for Server {
 
                             match state.try_authenticate(self.id.clone(), token.to_string()) {
                                 StateResult::Success(user_id) => {
+                                    let user = crate::database::user::fetch_user(&user_id).unwrap().unwrap();
+                                    
                                     self.user_id = Some(user_id);
                                     self.sender.send(
                                         json!({
@@ -43,6 +45,17 @@ impl Handler for Server {
                                             "success": true,
                                         })
                                         .to_string(),
+                                    )?;
+                                    
+                                    self.sender.send(
+                                        json!({
+                                            "type": "ready",
+                                            "data": {
+                                                // ! FIXME: rewrite
+                                                "user": user
+                                            }
+                                        })
+                                        .to_string(),
                                     )
                                 }
                                 StateResult::DatabaseError => self.sender.send(
diff --git a/src/routes/root.rs b/src/routes/root.rs
index 2f2f03c..bb9fa55 100644
--- a/src/routes/root.rs
+++ b/src/routes/root.rs
@@ -6,7 +6,12 @@ use mongodb::bson::doc;
 #[get("/")]
 pub fn root() -> Response {
     Response::Success(json!({
-        "revolt": "0.2.6"
+        "revolt": "0.2.7",
+        "version": {
+            "major": 0,
+            "minor": 2,
+            "patch": 7
+        }
     }))
 }
 
-- 
GitLab