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
|
2015-02-11 00:29:52 +08:00
|
|
|
chatObject.message = translateHTML5ToFlash(chatObject.message)
|
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 08:01:40 +08:00
|
|
|
# manually convert time from 1.408645053653E12 to 1408645053653 if necessary
|
|
|
|
# (this is the time_from that the Flash client outputs)
|
|
|
|
messageObject.from_time = (messageObject.from_time).toString().split('.').join("").split("E")[0]
|
2014-10-02 02:02:29 +08:00
|
|
|
|
2014-11-27 08:01:40 +08:00
|
|
|
if messageObject.from_userid? and messageObject.to_userid?
|
2015-02-11 00:29:52 +08:00
|
|
|
messageObject.message = translateFlashToHTML5(messageObject.message)
|
|
|
|
|
2014-11-27 06:49:21 +08:00
|
|
|
entry =
|
|
|
|
meetingId: meetingId
|
|
|
|
message:
|
2014-11-27 08:01:40 +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-10-02 02:02:29 +08:00
|
|
|
|
2014-11-27 06:49:21 +08:00
|
|
|
id = Meteor.Chat.insert(entry)
|
2014-12-23 05:21:30 +08:00
|
|
|
Meteor.log.info "added chat id=[#{id}]:#{messageObject.message}." #" Chat.size is now #{Meteor.Chat.find({meetingId: meetingId}).count()}"
|
2014-12-23 03:43:27 +08:00
|
|
|
|
|
|
|
# called on server start and meeting end
|
|
|
|
@clearChatCollection = (meetingId) ->
|
|
|
|
if meetingId?
|
|
|
|
Meteor.Chat.remove({meetingId: meetingId}, Meteor.log.info "cleared Chat Collection (meetingId: #{meetingId}!")
|
|
|
|
else
|
|
|
|
Meteor.Chat.remove({}, Meteor.log.info "cleared Chat Collection (all meetings)!")
|
|
|
|
|
2014-10-01 01:02:36 +08:00
|
|
|
# --------------------------------------------------------------------------------------------
|
|
|
|
# end Private methods on server
|
|
|
|
# --------------------------------------------------------------------------------------------
|
2015-02-11 00:29:52 +08:00
|
|
|
|
2015-02-12 04:06:19 +08:00
|
|
|
# translate '\n' newline character and '\r' carriage returns to '<br/>' breakline character for Flash
|
2015-02-11 00:29:52 +08:00
|
|
|
@translateHTML5ToFlash = (message) ->
|
2015-02-12 03:55:50 +08:00
|
|
|
result = message
|
|
|
|
result = result.replace(new RegExp(CARRIAGE_RETURN, 'g'), BREAK_LINE)
|
|
|
|
result = result.replace(new RegExp(NEW_LINE, 'g'), BREAK_LINE)
|
|
|
|
result
|
2015-02-11 00:29:52 +08:00
|
|
|
|
2015-02-12 04:06:19 +08:00
|
|
|
# translate '<br/>' breakline character to '\r' carriage return character for HTML5
|
2015-02-11 00:29:52 +08:00
|
|
|
@translateFlashToHTML5 = (message) ->
|
2015-02-12 03:55:50 +08:00
|
|
|
result = message
|
|
|
|
result = result.replace(new RegExp(BREAK_LINE, 'g'), CARRIAGE_RETURN)
|
|
|
|
result
|
2015-02-12 03:43:46 +08:00
|
|
|
|