diff --git a/.meteor/packages b/.meteor/packages index d50e8a2..bb08e00 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -32,7 +32,6 @@ meteorhacks:npm npm-container check -reywood:publish-composite mongo random meteor-platform @@ -41,3 +40,4 @@ coderstv:reactive-path tmeasday:presence coderstv:chat meteorhacks:kadira +cottz:publish-relations diff --git a/.meteor/versions b/.meteor/versions index 9be2561..c5081dd 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -19,6 +19,7 @@ cmather:handlebars-server@2.0.0 coderstv:chat@0.2.0 coderstv:reactive-path@0.2.1 coffeescript@1.0.5 +cottz:publish-relations@1.2.0 dburles:collection-helpers@1.0.2 ddp@1.0.14 deps@1.0.6 @@ -80,7 +81,6 @@ reactive-dict@1.0.5 reactive-var@1.0.4 reload@1.1.2 retry@1.0.2 -reywood:publish-composite@1.3.5 routepolicy@1.0.4 service-configuration@1.0.3 session@1.0.5 diff --git a/server/publish/channels.js b/server/publish/channels.js index 048d404..f8a4c81 100644 --- a/server/publish/channels.js +++ b/server/publish/channels.js @@ -1,63 +1,63 @@ -Meteor.publishComposite('FeaturedChannelWithUser', function () { - return { - find: function () { - return Channels.find({}, {sort: {finishedAt: 1, createdAt: 1}}); - }, - children: [{ - find: function (channel) { - return Meteor.users.find({_id: channel.owner}, { - superchat: 1, - profile: 1 - }); +Meteor.publishRelations('FeaturedChannelWithUser', function () { + this.cursor(Channels.find({featured: true}, {sort: {finishedAt: 1, createdAt: 1}}), function (_id, channel) { + this.cursor(Meteor.users.find({_id: channel.owner}, { + fields: { + superchat: 1, + profile: 1 } - }] - }; -}); + })); + }); -Meteor.publishComposite('ChannelsSearchWithUsers', function (searchText) { - return { - find: function () { - if (_.isEmpty(searchText)) { - return Channels.find({}, {sort: {finishedAt: 1, createdAt: 1}}); - } - check(searchText, String); + return this.ready(); +}); - var regex = '.*' + searchText + '.*'; +Meteor.publishRelations('ChannelsSearchWithUsers', function (searchText) { + if (_.isEmpty(searchText)) { + this.cursor(Channels.find({}, {sort: {finishedAt: 1, createdAt: 1}}), function (_id, channel) { + this.cursor(Meteor.users.find({_id: channel.owner}, { + fields: { + profile: 1 + } + })); + }); + } else { + check(searchText, String); - return Channels.find({$or : [ - {title: {$regex: regex, $options: 'i'}}, - {language: {$regex: regex, $options: 'i'}} - ]}, { - sort: {finishedAt: 1, createdAt: 1} - }); - }, - children: [{ - find: function (channel) { - return Meteor.users.find({_id: channel.owner}, { + var regex = '.*' + searchText + '.*'; + this.cursor(Channels.find({$or : [ + {title: {$regex: regex, $options: 'i'}}, + {language: {$regex: regex, $options: 'i'}} + ]}, { + sort: {finishedAt: 1, createdAt: 1} + }), function (_id, channel) { + this.cursor(Meteor.users.find({_id: channel.owner}, { + fields: { profile: 1 - }); - } - }] - }; + } + })); + }); + } + return this.ready(); }); -Meteor.publishComposite('ChannelsWithOwner', function (limit) { - return { - find: function () { - return Channels.find({}, {sort: {finishedAt: 1, createdAt: 1}, limit: limit || 0}); - }, - children: [{ - find: function (channel) { - return Meteor.users.find({_id: channel.owner}, { - superchat: 1, - profile: 1 - }); +Meteor.publishRelations('ChannelsWithOwner', function (limit) { + this.cursor(Channels.find({}, {sort: {finishedAt: -1, createdAt: -1}, limit: limit || 0}), function (_id, channel) { + this.cursor(Meteor.users.find({_id: channel.owner}, { + fields: { + superchat: 1, + profile: 1 } - }] - }; + })); + }); + + return this.ready(); }); Meteor.publish('CoderChannel', function (coderId) { + if (! coderId) { + return this.ready(); + } + var channels = Channels.find({ owner: coderId }); @@ -77,5 +77,5 @@ Meteor.publish('CoderChannel', function (coderId) { }); Meteor.publish('SelfVideos', function () { - return Channels.find({owner: this.userId}); + return this.userId && Channels.find({owner: this.userId}) || this.ready(); }); diff --git a/server/publish/followers.js b/server/publish/followers.js index eb60fce..4cfef58 100644 --- a/server/publish/followers.js +++ b/server/publish/followers.js @@ -1,24 +1,27 @@ Meteor.publish('Followers', function () { - return Followers.find({followerId: this.userId}); + return this.userId && Followers.find({followerId: this.userId}) || this.ready(); }); Meteor.publish('CoderFollowers', function (coderId) { + if (! coderId) { + return this.ready(); + } + var user = Meteor.users.findOneFromCoderId(coderId); - return Followers.find({coderId: user._id}); + return user && Followers.find({coderId: user._id}) || this.ready(); }); -Meteor.publishComposite('SelfFollowersWithProfiles', function () { - return { - find: function () { - return Followers.find({followerId: this.userId}); - }, - children: [{ - find: function (follower) { - return Meteor.users.find({_id: follower.coderId}, { +Meteor.publishRelations('SelfFollowersWithProfiles', function () { + if (this.userId) { + this.cursor(Followers.find({followerId: this.userId}), function (_id, follower) { + this.cursor(Meteor.users.find({_id: follower.coderId}, { + fields: { profile: 1 - }); - } - }] - }; + } + })); + }); + } + + return this.ready(); }); diff --git a/server/publish/presence.js b/server/publish/presence.js index 6ad7a9c..f03c2ba 100644 --- a/server/publish/presence.js +++ b/server/publish/presence.js @@ -1,35 +1,22 @@ -Meteor.publishComposite('userPresenceWithProfile', function (coderUsername, coderId) { - return { - find: function () { - var filter, presences; +Meteor.publishRelations('userPresenceWithProfile', function (coderUsername, coderId) { + var filter, presences; - if (_.isEmpty(coderUsername) && _.isEmpty(coderId)) { - this.ready(); - return; - } + if (_.isEmpty(coderUsername) && _.isEmpty(coderId)) { + return this.ready(); + } - if (coderUsername) { - check(coderUsername, String); - } else { - check(coderId, String); - } + check(coderUsername || coderId, String); + filter = {$or: [ + {'state.whereAt': '/coder/' + coderUsername}, + {'state.whereAt': '/coder/' + coderId} + ]}; - filter = {$or: [ - {'state.whereAt': '/coder/' + coderUsername}, - {'state.whereAt': '/coder/' + coderId} - ]}; - return Presences.find(filter, {fields: {state: true, userId: true}}); - }, - children: [{ - find: function (presence) { - if (presence.userId) { - return Meteor.users.find({_id: presence.userId}); - } + this.cursor(Presences.find(filter, {fields: {state: true, userId: true}}), function (_id, presence) { + if (presence.userId) { + this.cursor(Meteor.users.find({_id: presence.userId})); + } + }); - this.ready(); - return; - } - }] - }; + return this.ready(); }); diff --git a/server/publish/schedule.js b/server/publish/schedule.js index 9327921..3595e0e 100644 --- a/server/publish/schedule.js +++ b/server/publish/schedule.js @@ -6,7 +6,7 @@ Meteor.publish('Schedule', function (_id, activeOnly) { } if (activeOnly) { - query.$or = [{ + query.$or = [{ owner: this.userId, isActive: false }, { @@ -17,43 +17,37 @@ Meteor.publish('Schedule', function (_id, activeOnly) { return Schedule.find(query); }); -Meteor.publishComposite('OneScheduleWithProfile', function (_id) { - return { - find: function () { - return Schedule.find({_id: _id}); - }, - children: [{ - find: function (schedule) { - return Meteor.users.find({_id: schedule.owner}, { +Meteor.publishRelations('OneScheduleWithProfile', function (_id) { + if (_id) { + this.cursor(Schedule.find({_id: _id}), function (_id, schedule) { + this.cursor(Meteor.users.find({_id: schedule.owner}, { + fields: { profile: 1, superchat: 1 - }); - } - }] - }; -}); - -Meteor.publishComposite('AgendaWithProfiles', function () { - return { - find: function () { + } + })); + }); + } - return Schedule.find({ - $or: [{ - owner: this.userId, - isActive: false - }, { - isActive: true - }] - }, {sort: {date: -1}}); + return this.ready(); +}); - }, - children: [{ - find: function (schedule) { - return Meteor.users.find({_id: schedule.owner}, { - profile: 1, - superchat: 1 - }); - } +Meteor.publishRelations('AgendaWithProfiles', function () { + this.cursor(Schedule.find({ + $or: [{ + owner: this.userId, + isActive: false + }, { + isActive: true }] - }; + }, {sort: {date: -1}}), function (_id, schedule) { + this.cursor(Meteor.users.find({_id: schedule.owner}, { + fields: { + profile: 1, + superchat: 1 + } + })); + }); + + return this.ready(); }); diff --git a/server/publish/users.js b/server/publish/users.js index 840b4db..35a6304 100644 --- a/server/publish/users.js +++ b/server/publish/users.js @@ -3,7 +3,9 @@ Meteor.publish('Users', function () { }); Meteor.publish('SelfUser', function () { - return Meteor.users.find({_id: this.userId}, {fields: {profile: 1, paypal: 1, superchat: 1}}); + return this.userId && Meteor.users.find({_id: this.userId}, { + fields: {profile: 1, paypal: 1, superchat: 1} + }) || this.ready(); }); Meteor.publish('SingleUser', function (userId) { @@ -12,5 +14,5 @@ Meteor.publish('SingleUser', function (userId) { {_id: userId} ]}, { fields: {profile: 1, paypal: 1, superchat: 1} - }); + }) || this.ready(); });