2014-06-27 23:37:33 +08:00
|
|
|
Meteor.methods
|
2014-11-27 06:49:21 +08:00
|
|
|
# meetingId: the id of the meeting
|
|
|
|
# chatObject: the object including info on the chat message, including the text
|
|
|
|
# requesterUserId: the userId of the user sending chat
|
|
|
|
# requesterToken: the authToken of the requester
|
|
|
|
sendChatMessagetoServer: (meetingId, chatObject, requesterUserId, requesterToken) ->
|
|
|
|
chatType = chatObject.chat_type
|
|
|
|
recipient = chatObject.to_userid
|
|
|
|
eventName = null
|
|
|
|
action = ->
|
|
|
|
if chatType is "PUBLIC_CHAT"
|
|
|
|
eventName = "send_public_chat_message_request"
|
|
|
|
return 'chatPublic'
|
|
|
|
else
|
|
|
|
eventName = "send_private_chat_message_request"
|
|
|
|
if recipient is requesterUserId
|
|
|
|
return 'chatSelf' #not allowed
|
|
|
|
else
|
|
|
|
return 'chatPrivate'
|
|
|
|
|
2014-11-27 07:57:39 +08:00
|
|
|
if isAllowedTo(action(), meetingId, requesterUserId, requesterToken) and chatObject.from_userid is requesterUserId
|
2014-11-27 06:49:21 +08:00
|
|
|
|
|
|
|
message =
|
|
|
|
header :
|
|
|
|
timestamp: new Date().getTime()
|
|
|
|
name: eventName
|
|
|
|
payload:
|
|
|
|
message: chatObject
|
|
|
|
meeting_id: meetingId
|
|
|
|
requester_id: chatObject.from_userid
|
|
|
|
|
|
|
|
Meteor.log.info "publishing chat to redis"
|
|
|
|
publish Meteor.config.redis.channels.toBBBApps.chat, message
|
|
|
|
return
|
2014-09-24 03:55:25 +08:00
|
|
|
|
2014-10-21 20:22:54 +08:00
|
|
|
deletePrivateChatMessages: (userId, contact_id) ->
|
|
|
|
# if authorized pass through
|
2014-10-22 02:11:22 +08:00
|
|
|
requester = Meteor.Users.findOne({userId: userId})
|
|
|
|
contact = Meteor.Users.findOne({_id: contact_id})
|
|
|
|
deletePrivateChatMessages(requester.userId, contact.userId)
|
2014-09-25 23:54:14 +08:00
|
|
|
# --------------------------------------------------------------------------------------------
|
|
|
|
# Private methods on server
|
|
|
|
# --------------------------------------------------------------------------------------------
|
2014-09-26 02:47:43 +08:00
|
|
|
@addChatToCollection = (meetingId, messageObject) ->
|
2014-11-27 06:49:21 +08:00
|
|
|
console.log "\n\n\n stage 2 - adding \n\n"
|
2014-10-02 02:02:29 +08:00
|
|
|
transformedChatObject = messageObject
|
|
|
|
|
2014-09-26 02:47:43 +08:00
|
|
|
# manually convert time from 1.408645053653E12 to 1408645053653 if necessary (this is the time_from that the Flash client outputs)
|
2014-10-02 02:02:29 +08:00
|
|
|
transformedChatObject.from_time = (transformedChatObject.from_time).toString().split('.').join("").split("E")[0]
|
|
|
|
|
2014-11-27 06:49:21 +08:00
|
|
|
if transformedChatObject.from_userid? and transformedChatObject.to_userid?
|
|
|
|
entry =
|
|
|
|
meetingId: meetingId
|
|
|
|
message:
|
|
|
|
chat_type: transformedChatObject.chat_type
|
|
|
|
message: transformedChatObject.message
|
|
|
|
to_username: transformedChatObject.to_username
|
|
|
|
from_tz_offset: transformedChatObject.from_tz_offset
|
|
|
|
from_color: transformedChatObject.from_color
|
|
|
|
to_userid: transformedChatObject.to_userid
|
|
|
|
from_userid: transformedChatObject.from_userid
|
|
|
|
from_time: transformedChatObject.from_time
|
|
|
|
from_username: transformedChatObject.from_username
|
|
|
|
from_lang: transformedChatObject.from_lang
|
2014-10-02 02:02:29 +08:00
|
|
|
|
2014-11-27 06:49:21 +08:00
|
|
|
id = Meteor.Chat.insert(entry)
|
|
|
|
Meteor.log.info "added chat id=[#{id}]:#{transformedChatObject.message}. Chat.size is now #{Meteor.Chat.find({meetingId: meetingId}).count()}"
|
2014-10-01 01:02:36 +08:00
|
|
|
# --------------------------------------------------------------------------------------------
|
|
|
|
# end Private methods on server
|
|
|
|
# --------------------------------------------------------------------------------------------
|