]> Untitled Git - lemmy.git/commitdiff
Adding an online user count to main page.
authorDessalines <tyhou13@gmx.com>
Fri, 13 Sep 2019 16:09:01 +0000 (09:09 -0700)
committerDessalines <tyhou13@gmx.com>
Fri, 13 Sep 2019 16:09:01 +0000 (09:09 -0700)
- Fixes #274

server/src/api/site.rs
server/src/websocket/server.rs
ui/src/components/main.tsx
ui/src/interfaces.ts
ui/src/translations/en.ts

index b517568e6262b9ea2f3d63d3c08795aa2433d8b4..912378ab3fbbbdec2cea14a6111c613f7a04563e 100644 (file)
@@ -81,6 +81,7 @@ pub struct GetSiteResponse {
   site: Option<SiteView>,
   admins: Vec<UserView>,
   banned: Vec<UserView>,
+  pub online: usize,
 }
 
 #[derive(Serialize, Deserialize)]
@@ -296,6 +297,7 @@ impl Perform<GetSiteResponse> for Oper<GetSite> {
       site: site_view,
       admins: admins,
       banned: banned,
+      online: 0
     })
   }
 }
@@ -486,6 +488,7 @@ impl Perform<GetSiteResponse> for Oper<TransferSite> {
       site: Some(site_view),
       admins: admins,
       banned: banned,
+      online: 0
     })
   }
 }
index 08714c30b6684d9137b858b1ce4f01aad983f0a1..41bb105812be25530dd9c556b0068d9c65d3fa8d 100644 (file)
@@ -492,8 +492,10 @@ fn parse_json_message(chat: &mut ChatServer, msg: StandardMessage) -> Result<Str
       Ok(serde_json::to_string(&res)?)
     }
     UserOperation::GetSite => {
+      let online: usize = chat.sessions.len();
       let get_site: GetSite = serde_json::from_str(data)?;
-      let res = Oper::new(user_operation, get_site).perform()?;
+      let mut res = Oper::new(user_operation, get_site).perform()?;
+      res.online = online;
       Ok(serde_json::to_string(&res)?)
     }
     UserOperation::Search => {
index 9ee4afdd4873436ce0fec70894c4cf4e5875f365..b6c901be172ae2d299217cbdfc9d064a313c6ad5 100644 (file)
@@ -43,6 +43,7 @@ export class Main extends Component<any, MainState> {
       },
       admins: [],
       banned: [],
+      online: null,
     },
     showEditSite: false,
     loading: true,
@@ -215,6 +216,9 @@ export class Main extends Component<any, MainState> {
               </ul>
             }
             <ul class="my-2 list-inline">
+              <li className="list-inline-item badge badge-secondary">
+                <T i18nKey="number_online" interpolation={{count: this.state.site.online}}>#</T>
+              </li>
               <li className="list-inline-item badge badge-secondary">
                 <T i18nKey="number_of_users" interpolation={{count: this.state.site.site.number_of_users}}>#</T>
               </li>
@@ -420,6 +424,7 @@ export class Main extends Component<any, MainState> {
       this.state.site.admins = res.admins;
       this.state.site.site = res.site;
       this.state.site.banned = res.banned;
+      this.state.site.online = res.online;
       this.setState(this.state);
       document.title = `${WebSocketService.Instance.site.name}`;
 
index 8c78d7d8990eaf277b7664542f6245009434ecb9..3221415b3bf6729bb7e59929f28d5383282d17a6 100644 (file)
@@ -546,6 +546,7 @@ export interface GetSiteResponse {
   site: Site;
   admins: Array<UserView>;
   banned: Array<UserView>;
+  online: number;
 }
 
 
index 459e3b79c8d332951663f636ad3304c44ce0c291..591221c63dca20b02da238881f6ca771a7501790 100644 (file)
@@ -70,6 +70,7 @@ export const en = {
     number_of_users:'{{count}} Users',
     number_of_subscribers:'{{count}} Subscribers',
     number_of_points:'{{count}} Points',
+    number_online:'{{count}} Users Online',
     name: 'Name',
     title: 'Title',
     category: 'Category',