2014-06-27 23:37:33 +08:00
|
|
|
Meteor.methods
|
2014-06-28 00:16:17 +08:00
|
|
|
addChatToCollection: (meetingId, messageObject) ->
|
2014-09-19 05:55:53 +08:00
|
|
|
# manually convert time from 1.408645053653E12 to 1408645053653 if necessary (this is the time_from that the Flash client outputs)
|
2014-08-22 04:03:31 +08:00
|
|
|
messageObject.from_time = (messageObject.from_time).toString().split('.').join("").split("E")[0]
|
2014-07-10 03:09:10 +08:00
|
|
|
entry =
|
2014-06-28 00:16:17 +08:00
|
|
|
meetingId: meetingId
|
2014-07-10 03:09:10 +08:00
|
|
|
message:
|
2014-06-28 00:16:17 +08:00
|
|
|
chat_type: messageObject.chat_type
|
|
|
|
message: messageObject.message
|
|
|
|
to_username: messageObject.to_username
|
|
|
|
from_tz_offset: messageObject.from_tz_offset
|
|
|
|
from_color: messageObject.from_color
|
|
|
|
to_userid: messageObject.to_userid
|
|
|
|
from_userid: messageObject.from_userid
|
|
|
|
from_time: messageObject.from_time
|
|
|
|
from_username: messageObject.from_username
|
|
|
|
from_lang: messageObject.from_lang
|
2014-07-10 03:09:10 +08:00
|
|
|
|
2014-06-28 00:16:17 +08:00
|
|
|
id = Meteor.Chat.insert(entry)
|
|
|
|
console.log "added chat id=[#{id}]:#{messageObject.message}. Chat.size is now
|
|
|
|
#{Meteor.Chat.find({meetingId: meetingId}).count()}"
|
2014-06-28 01:53:31 +08:00
|
|
|
|
2014-09-24 03:55:25 +08:00
|
|
|
sendChatMessagetoServer: (meetingId, chatObject) ->
|
2014-09-24 04:15:03 +08:00
|
|
|
# check if this is a private or a public chat message
|
2014-09-24 03:55:25 +08:00
|
|
|
eventName = ->
|
|
|
|
if chatObject.chat_type is "PRIVATE_CHAT"
|
|
|
|
"send_private_chat_message_request"
|
|
|
|
else "send_public_chat_message_request"
|
|
|
|
|
2014-09-25 00:42:02 +08:00
|
|
|
# translate the userId to the user's _id
|
|
|
|
u = Meteor.Users.findOne({'userId':chatObject.from_userid})
|
|
|
|
if u?
|
|
|
|
chatObject.from_userid = u._id
|
|
|
|
# console.log "This is the message we're sending"
|
|
|
|
# console.log JSON.stringify chatObject
|
|
|
|
message =
|
|
|
|
header :
|
|
|
|
"timestamp": new Date().getTime()
|
|
|
|
"name": eventName()
|
|
|
|
payload:
|
|
|
|
"message" : chatObject
|
|
|
|
"meeting_id": meetingId
|
|
|
|
"requester_id": chatObject.from_userid
|
2014-09-26 02:29:43 +08:00
|
|
|
publish Meteor.config.redis.channels.toBBBApps.chat, message)
|
2014-09-24 03:55:25 +08:00
|
|
|
|
2014-09-25 23:54:14 +08:00
|
|
|
# --------------------------------------------------------------------------------------------
|
|
|
|
# Private methods on server
|
|
|
|
# --------------------------------------------------------------------------------------------
|
2014-09-26 02:29:43 +08:00
|
|
|
@deletePrivateChatMessages = (requesterUserId, requester_id, user1_id, user2_id) ->
|
|
|
|
requester = Meteor.Users.findOne({_id: requester_id, userId: requesterUserId})
|
|
|
|
u1 = Meteor.Users.findOne({_id: user1_id})
|
|
|
|
u2 = Meteor.Users.findOne({_id: user2_id})
|
|
|
|
|
|
|
|
if requester? and u1? and u2?
|
|
|
|
# Delete messages if the requester is a moderator, or one of the participants
|
|
|
|
if requester.role is "MODERATOR" or (requester._id is u1._id or requester._id is u2._id)
|
|
|
|
console.log "deleting chat conversation"
|
|
|
|
Meteor.Chat.remove({ # find all and remove private messages between the 2 users
|
|
|
|
'message.chat_type': 'PRIVATE_CHAT',
|
|
|
|
$or: [{'message.from_userid': u1._id, 'message.to_userid': u2._id},{'message.from_userid': u2._id, 'message.to_userid': u1._id}]
|
|
|
|
})
|