@ -55,11 +55,10 @@ Meteor.publish('archivedBoards', function() {
} ) ;
} ) ;
Meteor . publishComposite ( 'board' , function ( boardId ) {
Meteor . publishRelations ( 'board' , function ( boardId ) {
check ( boardId , String ) ;
return {
find ( ) {
return Boards . find ( {
this . cursor ( Boards . find ( {
_id : boardId ,
archived : false ,
// If the board is not public the user has to be a member of it to see
@ -68,17 +67,8 @@ Meteor.publishComposite('board', function(boardId) {
{ permission : 'public' } ,
{ members : { $elemMatch : { userId : this . userId , isActive : true } } } ,
] ,
} , { limit : 1 } ) ;
} ,
children : [
// Lists
{
find ( board ) {
return Lists . find ( {
boardId : board . _id ,
} ) ;
} ,
} ,
} , { limit : 1 } ) , function ( boardId , board ) {
this . cursor ( Lists . find ( { boardId } ) ) ;
// Cards and cards comments
// XXX Originally we were publishing the card documents as a child of the
@ -88,11 +78,9 @@ Meteor.publishComposite('board', function(boardId) {
//
// https://github.com/englue/meteor-publish-composite/issues/29
//
// I then tried to replace publish-composite by cottz:publish, but it had
// a similar problem:
// cottz:publish had a similar problem:
//
// https://github.com/Goluis/cottz-publish/issues/4
// https://github.com/wekan/wekan/pull/78
//
// The current state of relational publishing in meteor is a bit sad,
// there are a lot of various packages, with various APIs, some of them
@ -103,49 +91,22 @@ Meteor.publishComposite('board', function(boardId) {
//
// And in the meantime our code below works pretty well -- it's not even a
// hack!
{
find ( board ) {
return Cards . find ( {
boardId : board . _id ,
this . cursor ( Cards . find ( { boardId } ) , function ( cardId ) {
this . cursor ( CardComments . find ( { cardId } ) ) ;
this . cursor ( Attachments . find ( { cardId } ) ) ;
} ) ;
} ,
children : [
// comments
{
find ( card ) {
return CardComments . find ( {
cardId : card . _id ,
} ) ;
} ,
} ,
// Attachments
{
find ( card ) {
return Attachments . find ( {
cardId : card . _id ,
} ) ;
} ,
} ,
] ,
} ,
// 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.
{
find ( board ) {
return Users . find ( {
//
this . cursor ( Users . find ( {
_id : { $in : _ . pluck ( board . members , 'userId' ) } ,
} ) ;
} ,
} ) , function ( userId ) {
// Presence indicators
children : [ {
find ( user ) {
return presences . find ( { userId : user . _id } ) ;
} ,
} ] ,
} ,
] ,
} ;
this . cursor ( presences . find ( { userId } ) ) ;
} ) ;
} ) ;
return this . ready ( ) ;
} ) ;