Created
August 2, 2016 10:49
-
-
Save sizovilya/2e87c4a67bcdf4028efce49c560869f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'add-to-members': function(postId,userId, postTitle, roomId) | |
{ | |
var curId = curId; | |
var coll = Posts.find({_id: postId,"requests.userId": curId}, {fields: {'requests': 1,'roomId':1}}).fetch(); | |
var members = Posts.find({_id: postId}, {fields: {'members': 1}}).fetch()[0].members; | |
var requesters = coll[0].requests; | |
var newRequesters = _.without(requesters, _.findWhere(requesters, {userId: curId})); | |
var curUsr = _.findWhere(requesters, {userId: curId}); | |
members.push(curUsr); | |
Posts.update({_id: postId},{$set:{requests:newRequesters,members:members}}); | |
var params = { | |
userId: curId, | |
request: { | |
title: postTitle, | |
reqId: postId | |
}, | |
who: { | |
id: Meteor.user()._id, | |
name: Meteor.user().profile.name | |
} | |
} | |
var fields = { | |
roomId: roomId, | |
userId: curId | |
} | |
Meteor.call('addInLastSeen', fields, function (error) { | |
if (error) | |
throwError(error.reason); | |
}); | |
Meteor.call('notifyUser', 'invite', params, function (error) { | |
if (error) | |
throwError(error.reason); | |
}); | |
var html = Blaze.toHTMLWithData(Template.addInTeam,params); | |
Meteor.call('sendEmail','addInTeam',params,html); | |
}, | |
remove-from-members': function(postId, userId) | |
{ | |
var curId = userId; | |
var coll = Posts.find({_id: postId,"members.userId": curId}, {fields: {'members': 1, 'roomId': 1}}).fetch(); | |
var requesters = Posts.find({_id: postId}, {fields: {'requests': 1}}).fetch()[0].requests; | |
var members = coll[0].members; | |
var newMembers = _.without(members, _.findWhere(members, {userId: curId})); | |
var curUsr = _.findWhere(members, {userId: curId}); | |
requesters.push(curUsr); | |
Posts.update({_id: postId},{$set:{requests:requesters,members:newMembers}}); | |
var obj = { | |
roomId: coll[0].roomId, | |
userId: curId | |
}; | |
Meteor.call('removeFromLastSeen', obj, function (error) { | |
if (error) | |
throwError(error.reason); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment