瀏覽代碼

Fixed userList bug.

KrisVos130 9 年之前
父節點
當前提交
cad854c5cd
共有 1 個文件被更改,包括 7 次插入8 次删除
  1. 7 8
      app/server/server.js

+ 7 - 8
app/server/server.js

@@ -27,8 +27,6 @@ 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 = {
@@ -160,24 +158,25 @@ function Station(type) {
         Playlists.update({type: type}, {$push: {songs: default_song.mid}});
     }
     var usersObj = {};
+    Rooms.update({type: type}, {$set: {userList: []}});
     Meteor.publish(type, function () {
         var user = Meteor.users.findOne(this.userId);
         if (this.userId !== undefined && user !== undefined && user.profile !== undefined && user.profile.username !== undefined) {
             var username = user.profile.username;
             if (usersObj[username] === undefined) {
                 usersObj[username] = 1;
+            } else {
+                usersObj[username]++;
             }
             Rooms.update({type: type}, {$push: {userList: username}});
             this.onStop(function() {
                 usersObj[username]--;
                 var list = Rooms.findOne({type: type}).userList;
                 var index = list.indexOf(username);
-                /*if (index >= 0) { //TODO Fix this
-                    var t = {};
-                    t["userList" + index] = 1;
-                    Rooms.update({type: type}, {$unset : t});
-                    Rooms.update({type: type}, {$pull : {"userList": null}});
-                }*/
+                if (index >= 0) { //TODO Fix this
+                    list.splice(index, 1);
+                    Rooms.update({type: type}, {$set: {userList: list}});
+                }
             });
         }
         return undefined;