2015-07-31 08:08:12 +08:00
|
|
|
# --------------------------------------------------------------------------------------------
|
|
|
|
# Public methods on server
|
|
|
|
# --------------------------------------------------------------------------------------------
|
|
|
|
Meteor.methods
|
|
|
|
|
|
|
|
publishVoteMessage: (meetingId, pollAnswerId, requesterUserId, requesterToken) ->
|
|
|
|
if isAllowedTo("subscribePoll", meetingId, requesterUserId, requesterToken)
|
|
|
|
eventName = "vote_poll_user_request_message"
|
|
|
|
|
|
|
|
result = Meteor.Polls.findOne({"poll_info.users": requesterUserId, "poll_info.meetingId": meetingId, "poll_info.poll.answers.id": pollAnswerId},
|
|
|
|
{fields: {"poll_info.poll.id": 1, _id: 0}})
|
|
|
|
_poll_id = result.poll_info.poll.id
|
|
|
|
|
2015-08-01 02:07:27 +08:00
|
|
|
if eventName? and meetingId? and requesterUserId? and _poll_id? and pollAnswerId?
|
|
|
|
message =
|
|
|
|
header:
|
|
|
|
timestamp: new Date().getTime()
|
|
|
|
name: eventName
|
|
|
|
payload:
|
|
|
|
meeting_id: meetingId
|
|
|
|
user_id: requesterUserId
|
|
|
|
poll_id: _poll_id
|
|
|
|
question_id: 0
|
|
|
|
answer_id: pollAnswerId
|
2015-07-31 08:08:12 +08:00
|
|
|
|
2015-08-01 02:07:27 +08:00
|
|
|
Meteor.Polls.update({"poll_info.users": requesterUserId, "poll_info.meetingId": meetingId, "poll_info.poll.answers.id": pollAnswerId},
|
2015-08-02 03:27:01 +08:00
|
|
|
{ $pull: {"poll_info.users": requesterUserId}});
|
2015-08-01 02:07:27 +08:00
|
|
|
|
|
|
|
Meteor.log.info "publishing Poll response to redis"
|
|
|
|
publish Meteor.config.redis.channels.toBBBApps.polling, message
|
2015-07-31 08:08:12 +08:00
|
|
|
|
|
|
|
|
2015-07-23 11:31:08 +08:00
|
|
|
# --------------------------------------------------------------------------------------------
|
|
|
|
# Private methods on server
|
|
|
|
# --------------------------------------------------------------------------------------------
|
2015-07-27 06:12:08 +08:00
|
|
|
@addPollToCollection = (poll, requester_id, users, meetingId) ->
|
|
|
|
#copying all the userids into an array
|
2015-07-26 11:46:32 +08:00
|
|
|
_users = []
|
2015-07-27 06:12:08 +08:00
|
|
|
for user in users
|
|
|
|
_users.push user.user.userid
|
|
|
|
#adding the initial number of votes for each answer
|
|
|
|
for answer in poll.answers
|
2015-08-02 03:27:01 +08:00
|
|
|
answer.num_votes = 0
|
|
|
|
#adding the initial number of responders and respondents to the poll, which will be displayed for presenter (in HTML5 client) when he starts the poll
|
|
|
|
poll.num_responders = -1
|
|
|
|
poll.num_respondents = -1
|
|
|
|
|
2015-07-27 06:12:08 +08:00
|
|
|
#adding all together and inserting into the Polls collection
|
2015-07-25 07:09:27 +08:00
|
|
|
entry =
|
|
|
|
poll_info:
|
2015-07-27 06:12:08 +08:00
|
|
|
"meetingId": meetingId
|
2015-07-25 07:09:27 +08:00
|
|
|
"poll": poll
|
|
|
|
"requester": requester_id
|
2015-07-26 11:46:32 +08:00
|
|
|
"users": _users
|
2015-08-01 02:07:27 +08:00
|
|
|
Meteor.log.info "added poll _id=[#{poll.id}]:meetingId=[#{meetingId}]."
|
2015-07-25 07:09:27 +08:00
|
|
|
Meteor.Polls.insert(entry)
|
2015-07-23 11:31:08 +08:00
|
|
|
|
2015-07-28 02:23:29 +08:00
|
|
|
@clearPollCollection = (meetingId, poll_id) ->
|
|
|
|
if meetingId? and poll_id? and Meteor.Polls.findOne({"poll_info.meetingId": meetingId, "poll_info.poll.id": poll_id})?
|
|
|
|
Meteor.Polls.remove({
|
2015-07-28 06:55:29 +08:00
|
|
|
"poll_info.meetingId": meetingId,
|
|
|
|
"poll_info.poll.id": poll_id},
|
2015-08-02 03:27:01 +08:00
|
|
|
Meteor.log.info "cleared Polls Collection (meetingId: #{meetingId}, pollId: #{poll_id}!)")
|
2015-07-23 11:31:08 +08:00
|
|
|
else
|
2015-07-28 02:23:29 +08:00
|
|
|
Meteor.Polls.remove({}, Meteor.log.info "cleared Polls Collection (all meetings)!")
|
2015-08-02 03:27:01 +08:00
|
|
|
|
|
|
|
@updatePollCollection = (poll, meetingId, requesterId) ->
|
|
|
|
if poll.answers? and poll.num_responders? and poll.num_respondents? and poll.id? and meetingId? and requesterId?
|
|
|
|
Meteor.Polls.update({"poll_info.meetingId": meetingId, "poll_info.requester": requesterId, "poll_info.poll.id": poll.id},
|
|
|
|
{$set:
|
|
|
|
{"poll_info.poll.answers": poll.answers, "poll_info.poll.num_responders": poll.num_responders, "poll_info.poll.num_respondents": poll.num_respondents}
|
|
|
|
}, Meteor.log.info "updating Polls Collection (meetingId: #{meetingId}, pollId: #{poll.id}!)")
|