Skip to content

Commit

Permalink
Merge pull request #67 from CodersTV/change-publish-composite
Browse files Browse the repository at this point in the history
Replace publish composite with publish relations and fix publication fields
  • Loading branch information
gabrielhpugliese committed Apr 26, 2015
2 parents 3ed9c12 + dc7d144 commit bd4f672
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ meteorhacks:npm

npm-container
check
reywood:publish-composite
mongo
random
meteor-platform
Expand All @@ -41,3 +40,4 @@ coderstv:reactive-path
tmeasday:presence
coderstv:chat
meteorhacks:kadira
cottz:publish-relations
2 changes: 1 addition & 1 deletion .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ cmather:[email protected]
coderstv:[email protected]
coderstv:[email protected]
[email protected]
cottz:[email protected]
dburles:[email protected]
[email protected]
[email protected]
Expand Down Expand Up @@ -80,7 +81,6 @@ [email protected]
[email protected]
[email protected]
[email protected]
reywood:[email protected]
[email protected]
[email protected]
[email protected]
Expand Down
100 changes: 50 additions & 50 deletions server/publish/channels.js
Original file line number Diff line number Diff line change
@@ -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
});
Expand All @@ -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();
});
31 changes: 17 additions & 14 deletions server/publish/followers.js
Original file line number Diff line number Diff line change
@@ -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();
});
45 changes: 16 additions & 29 deletions server/publish/presence.js
Original file line number Diff line number Diff line change
@@ -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();
});

64 changes: 29 additions & 35 deletions server/publish/schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meteor.publish('Schedule', function (_id, activeOnly) {
}

if (activeOnly) {
query.$or = [{
query.$or = [{
owner: this.userId,
isActive: false
}, {
Expand All @@ -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();
});
6 changes: 4 additions & 2 deletions server/publish/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -12,5 +14,5 @@ Meteor.publish('SingleUser', function (userId) {
{_id: userId}
]}, {
fields: {profile: 1, paypal: 1, superchat: 1}
});
}) || this.ready();
});

0 comments on commit bd4f672

Please sign in to comment.