From 1c3ed864e7516a4a13b3eb2e2172aab90f384edf Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 11 Aug 2020 17:46:58 -0400 Subject: [PATCH] Fixing online counts. Fixes #664 --- server/src/api/community.rs | 13 +++++-------- server/src/api/post.rs | 13 +++++-------- server/src/api/site.rs | 15 +++++++-------- ui/src/components/main.tsx | 8 +++----- ui/src/components/sidebar.tsx | 8 +++----- 5 files changed, 23 insertions(+), 34 deletions(-) diff --git a/server/src/api/community.rs b/server/src/api/community.rs index fb153895f..642752e82 100644 --- a/server/src/api/community.rs +++ b/server/src/api/community.rs @@ -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 { 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 }; diff --git a/server/src/api/post.rs b/server/src/api/post.rs index b43e4e55c..24b403133 100644 --- a/server/src/api/post.rs +++ b/server/src/api/post.rs @@ -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 { 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 }; diff --git a/server/src/api/site.rs b/server/src/api/site.rs index 515c3e5be..cc5dd841f 100644 --- a/server/src/api/site.rs +++ b/server/src/api/site.rs @@ -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 { 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 }; diff --git a/ui/src/components/main.tsx b/ui/src/components/main.tsx index 246db6746..3c303104a 100644 --- a/ui/src/components/main.tsx +++ b/ui/src/components/main.tsx @@ -385,11 +385,9 @@ export class Main extends Component { badges() { return (
    - {/* -
  • - {i18n.t('number_online', { count: this.state.siteRes.online })} -
  • - */} +
  • + {i18n.t('number_online', { count: this.state.siteRes.online })} +
  • {i18n.t('number_of_users', { count: this.state.siteRes.site.number_of_users, diff --git a/ui/src/components/sidebar.tsx b/ui/src/components/sidebar.tsx index 61959eb07..411d6eccc 100644 --- a/ui/src/components/sidebar.tsx +++ b/ui/src/components/sidebar.tsx @@ -125,11 +125,9 @@ export class Sidebar extends Component { let community = this.props.community; return (
      - {/* -
    • - {i18n.t('number_online', { count: this.props.online })} -
    • - */} +
    • + {i18n.t('number_online', { count: this.props.online })} +
    • {i18n.t('number_of_subscribers', { count: community.number_of_subscribers,