瀏覽代碼

Merge pull request #25 from dwrensha/board-members-join

fix bug where old users could see broken presence indicators on new users
Lauri Ojansivu 8 年之前
父節點
當前提交
96e5e8d058
共有 1 個文件被更改,包括 20 次插入14 次删除
  1. 20 14
      server/publications/boards.js

+ 20 - 14
server/publications/boards.js

@@ -60,6 +60,7 @@ Meteor.publish('archivedBoards', function() {
 
 Meteor.publishRelations('board', function(boardId) {
   check(boardId, String);
+  const thisUserId = this.userId;
 
   this.cursor(Boards.find({
     _id: boardId,
@@ -99,20 +100,25 @@ Meteor.publishRelations('board', function(boardId) {
       this.cursor(Attachments.find({ cardId }));
     });
 
-    // Board members. This publication also includes former board members that
-    // aren't members anymore but may have some activities attached to them in
-    // the history.
-    //
-    this.cursor(Users.find({
-      _id: { $in: _.pluck(board.members, 'userId') },
-    }, { fields: {
-      'username': 1,
-      'profile.fullname': 1,
-      'profile.avatarUrl': 1,
-    }}), function(userId) {
-      // Presence indicators
-      this.cursor(presences.find({ userId }));
-    });
+    if (board.members) {
+      // Board members. This publication also includes former board members that
+      // aren't members anymore but may have some activities attached to them in
+      // the history.
+      const memberIds = _.pluck(board.members, 'userId');
+
+      // We omit the current user because the client should already have that data,
+      // and sending it triggers a subtle bug:
+      // https://github.com/wefork/wekan/issues/15
+      this.cursor(Users.find({
+        _id: { $in: _.without(memberIds, thisUserId)},
+      }, { fields: {
+        'username': 1,
+        'profile.fullname': 1,
+        'profile.avatarUrl': 1,
+      }}));
+
+      this.cursor(presences.find({ userId: { $in: memberIds } }));
+    }
   });
 
   return this.ready();