]> Untitled Git - lemmy.git/commitdiff
Fixing online counts. Fixes #664
authorDessalines <tyhou13@gmx.com>
Tue, 11 Aug 2020 21:46:58 +0000 (17:46 -0400)
committerDessalines <tyhou13@gmx.com>
Tue, 11 Aug 2020 21:46:58 +0000 (17:46 -0400)
server/src/api/community.rs
server/src/api/post.rs
server/src/api/site.rs
ui/src/components/main.tsx
ui/src/components/sidebar.tsx

index fb153895f22fb20863f8464788ad7f0fe49aed75..642752e827b1da303dfe1a0a4bc715c7cb91d950 100644 (file)
@@ -4,7 +4,7 @@ use crate::{
   apub::ActorType,
   blocking,
   websocket::{
-    server::{JoinCommunityRoom, SendCommunityRoomMessage},
+    server::{GetCommunityUsersOnline, JoinCommunityRoom, SendCommunityRoomMessage},
     UserOperation,
     WebsocketInfo,
   },
@@ -203,13 +203,10 @@ impl Perform for Oper<GetCommunity> {
           id,
         });
       }
-
-      // TODO
-      1
-    // let fut = async {
-    //   ws.chatserver.send(GetCommunityUsersOnline {community_id}).await.unwrap()
-    // };
-    // Runtime::new().unwrap().block_on(fut)
+      ws.chatserver
+        .send(GetCommunityUsersOnline { community_id })
+        .await
+        .unwrap_or(1)
     } else {
       0
     };
index b43e4e55cf6b2a8a5c0ab6ea972b2ebdfd1c9e8d..24b4031336300d52ce7ae28beebd5f8b7b180537 100644 (file)
@@ -14,7 +14,7 @@ use crate::{
   blocking,
   fetch_iframely_and_pictrs_data,
   websocket::{
-    server::{JoinCommunityRoom, JoinPostRoom, SendPost},
+    server::{GetPostUsersOnline, JoinCommunityRoom, JoinPostRoom, SendPost},
     UserOperation,
     WebsocketInfo,
   },
@@ -306,13 +306,10 @@ impl Perform for Oper<GetPost> {
           id,
         });
       }
-
-      // TODO
-      1
-    // let fut = async {
-    //   ws.chatserver.send(GetPostUsersOnline {post_id: data.id}).await.unwrap()
-    // };
-    // Runtime::new().unwrap().block_on(fut)
+      ws.chatserver
+        .send(GetPostUsersOnline { post_id: data.id })
+        .await
+        .unwrap_or(1)
     } else {
       0
     };
index 515c3e5bed0649f284566424546041edce915d55..cc5dd841f0829c9f18d48ad3f0ed1a98bf3b2550 100644 (file)
@@ -13,7 +13,11 @@ use crate::{
   apub::fetcher::search_by_apub_id,
   blocking,
   version,
-  websocket::{server::SendAllMessage, UserOperation, WebsocketInfo},
+  websocket::{
+    server::{GetUsersOnline, SendAllMessage},
+    UserOperation,
+    WebsocketInfo,
+  },
   DbPool,
   LemmyError,
 };
@@ -409,13 +413,8 @@ impl Perform for Oper<GetSite> {
 
     let banned = blocking(pool, move |conn| UserView::banned(conn)).await??;
 
-    let online = if let Some(_ws) = websocket_info {
-      // TODO
-      1
-    // let fut = async {
-    //   ws.chatserver.send(GetUsersOnline).await.unwrap()
-    // };
-    // Runtime::new().unwrap().block_on(fut)
+    let online = if let Some(ws) = websocket_info {
+      ws.chatserver.send(GetUsersOnline).await.unwrap_or(1)
     } else {
       0
     };
index 246db674644f4522f2513f7f53bfbdeef69dd4a8..3c303104ad1c1b7fd0792e11eca4161d23b2b9be 100644 (file)
@@ -385,11 +385,9 @@ export class Main extends Component<any, MainState> {
   badges() {
     return (
       <ul class="my-2 list-inline">
-        {/*
-              <li className="list-inline-item badge badge-light">
-                {i18n.t('number_online', { count: this.state.siteRes.online })}
-              </li>
-              */}
+        <li className="list-inline-item badge badge-light">
+          {i18n.t('number_online', { count: this.state.siteRes.online })}
+        </li>
         <li className="list-inline-item badge badge-light">
           {i18n.t('number_of_users', {
             count: this.state.siteRes.site.number_of_users,
index 61959eb07051c8585975e6399b23e6677fb967e2..411d6eccc0df6690f331fbacf34eea28071da899 100644 (file)
@@ -125,11 +125,9 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
     let community = this.props.community;
     return (
       <ul class="my-1 list-inline">
-        {/*
-              <li className="list-inline-item badge badge-light">
-                {i18n.t('number_online', { count: this.props.online })}
-              </li>
-              */}
+        <li className="list-inline-item badge badge-light">
+          {i18n.t('number_online', { count: this.props.online })}
+        </li>
         <li className="list-inline-item badge badge-light">
           {i18n.t('number_of_subscribers', {
             count: community.number_of_subscribers,