浏览代码

Added userList array! Fixed news.

KrisVos130 9 年之前
父节点
当前提交
040e0849e6
共有 3 个文件被更改,包括 25 次插入1 次删除
  1. 1 1
      app/client/templates/news.html
  2. 9 0
      app/database/schemas.js
  3. 15 0
      app/server/server.js

+ 1 - 1
app/client/templates/news.html

@@ -1,6 +1,6 @@
 <template name="news">
     {{> header}}
-    <main class="content-box row">
+    <main class="content-box row hack-container">
         <h3 class="black-text thin center">News</h3>
             {{#each articles}}
                 <div class="card teal-text col m6 s12 l6 offset-m3 offset-l3">

+ 9 - 0
app/database/schemas.js

@@ -241,6 +241,15 @@ Schemas.Room = new SimpleSchema({
     roomDesc: {
         type: String,
         label: "Room description"
+    },
+    userList: {
+        type: Array,
+        label: "List of currently online people",
+        defaultValue: []
+    },
+    "userList.$": {
+        type: String,
+        label: "Username of user currently in a room"
     }
 });
 

+ 15 - 0
app/server/server.js

@@ -27,6 +27,8 @@ Meteor.startup(function () {
     if (Songs.find().count() === 0 || Songs.find({mid: default_song.mid}).count() === 0) {
         Songs.insert(default_song);
     }
+
+    Rooms.update({}, {$set: {userList: []}});
 });
 
 var default_song = {
@@ -159,6 +161,19 @@ function Station(type) {
         Playlists.update({type: type}, {$push: {songs: default_song.mid}});
     }
     Meteor.publish(type, function () {
+        var userId = this.userId;
+        Meteor.thisIsA = this;
+        var username = Meteor.users.findOne(userId).profile.username;
+        Rooms.update({type: type}, {$push: {userList: username}});
+        this.onStop(function() {
+            var list = Rooms.findOne({type: type}).userList;
+            var index = list.indexOf(username);
+            if (index >= 0) {
+                list.splice( index, 1 );
+            }
+
+            Rooms.update({type: type}, {$set: {userList: list}});
+        });
         return undefined;
     });
     var self = this;