2014-07-03 00:17:05 +08:00
|
|
|
|
Template.messageBar.helpers
|
2014-07-18 22:08:59 +08:00
|
|
|
|
# This method returns all messages for the user. It looks at the session to determine whether the user is in
|
|
|
|
|
#private or public chat. If true is passed, messages returned are from before the user joined. Else, the messages are from after the user joined
|
2014-08-08 04:29:13 +08:00
|
|
|
|
getFormattedMessagesForChat: () ->
|
2014-07-18 04:13:06 +08:00
|
|
|
|
friend = chattingWith = getInSession('inChatWith') # the recipient(s) of the messages
|
2014-07-09 21:18:52 +08:00
|
|
|
|
|
2014-07-11 23:53:49 +08:00
|
|
|
|
if chattingWith is 'PUBLIC_CHAT' # find all public messages
|
2014-08-07 01:46:54 +08:00
|
|
|
|
before = Meteor.Chat.find({'message.chat_type': chattingWith, 'message.from_time': {$lt: String(getInSession("joinedAt"))}}).fetch()
|
|
|
|
|
after = Meteor.Chat.find({'message.chat_type': chattingWith, 'message.from_time': {$gt: String(getInSession("joinedAt"))}}).fetch()
|
2014-07-09 21:18:52 +08:00
|
|
|
|
else
|
2014-07-18 04:13:06 +08:00
|
|
|
|
me = getInSession("userId")
|
2014-08-07 01:46:54 +08:00
|
|
|
|
before = Meteor.Chat.find({ # find all messages between current user and recipient
|
2014-07-09 21:18:52 +08:00
|
|
|
|
'message.chat_type': 'PRIVATE_CHAT',
|
|
|
|
|
$or: [{'message.from_userid': me, 'message.to_userid': friend},{'message.from_userid': friend, 'message.to_userid': me}]
|
2014-08-07 01:46:54 +08:00
|
|
|
|
}).fetch()
|
|
|
|
|
after = []
|
|
|
|
|
|
|
|
|
|
greeting = [
|
|
|
|
|
'class': 'chatGreeting',
|
|
|
|
|
'message':
|
|
|
|
|
'message': Template.messageBar.getChatGreeting(),
|
|
|
|
|
'from_username': 'System',
|
|
|
|
|
'from_time': getTime()
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
messages = (before.concat greeting).concat after
|
2014-08-08 04:29:13 +08:00
|
|
|
|
###
|
|
|
|
|
# Now after all messages + the greeting have been inserted into our collection, what we have to do is go through all messages
|
|
|
|
|
# and modify them to join all sequential messages by users together so each entries will be chat messages by a user in the same time frame
|
|
|
|
|
# we can use a time frame, so join messages together that are within 5 minutes of eachother, for example
|
|
|
|
|
###
|
2014-07-09 21:18:52 +08:00
|
|
|
|
|
|
|
|
|
isUserInPrivateChat: -> # true if user is in public chat
|
2014-07-18 04:13:06 +08:00
|
|
|
|
getInSession('inChatWith') isnt "PUBLIC_CHAT"
|
2014-06-25 21:28:15 +08:00
|
|
|
|
|
2014-08-07 01:46:54 +08:00
|
|
|
|
getChatGreeting: ->
|
|
|
|
|
greeting =
|
2014-08-08 23:12:02 +08:00
|
|
|
|
"<p>Welcome to #{getMeetingName()}!</p>
|
2014-08-07 01:46:54 +08:00
|
|
|
|
<p>For help on using BigBlueButton see these (short) <a href='http://bigbluebutton.org/videos/' target='_blank'>tutorial videos</a>.</p>
|
|
|
|
|
<p>To join the audio bridge click the headset icon (upper-left hand corner). Use a headset to avoid causing background noise for others.</p>
|
|
|
|
|
<br/>
|
|
|
|
|
<p>This server is running BigBlueButton #{getInSession 'bbbServerVersion'}.</p>"
|
|
|
|
|
|
2014-07-02 23:41:12 +08:00
|
|
|
|
Template.tabButtons.events
|
2014-07-17 23:25:56 +08:00
|
|
|
|
'click .tab': (event) -> ;
|
2014-07-10 21:11:38 +08:00
|
|
|
|
|
2014-07-09 21:18:52 +08:00
|
|
|
|
'click .publicChatTab': (event) ->
|
2014-07-18 04:13:06 +08:00
|
|
|
|
setInSession 'display_chatPane', true
|
|
|
|
|
setInSession 'inChatWith', 'PUBLIC_CHAT'
|
2014-07-04 01:56:16 +08:00
|
|
|
|
|
2014-07-09 21:18:52 +08:00
|
|
|
|
'click .optionsChatTab': (event) ->
|
2014-07-18 04:13:06 +08:00
|
|
|
|
setInSession 'display_chatPane', false
|
2014-06-24 21:46:42 +08:00
|
|
|
|
|
2014-07-09 21:18:52 +08:00
|
|
|
|
'click .privateChatTab': (event) ->
|
2014-07-18 04:13:06 +08:00
|
|
|
|
setInSession 'display_chatPane', true
|
|
|
|
|
setInSession 'inChatWith', @userId
|
2014-07-17 23:25:56 +08:00
|
|
|
|
|
2014-07-09 21:18:52 +08:00
|
|
|
|
'click .close': (event) -> # user closes private chat
|
2014-07-17 23:25:56 +08:00
|
|
|
|
theName = @name
|
2014-07-18 04:13:06 +08:00
|
|
|
|
setInSession 'display_chatPane', true
|
|
|
|
|
setInSession 'inChatWith', 'PUBLIC_CHAT'
|
2014-07-17 23:25:56 +08:00
|
|
|
|
|
|
|
|
|
origTabs = myTabs.getValue()
|
|
|
|
|
newTabs = []
|
|
|
|
|
for x in origTabs
|
|
|
|
|
if x.name isnt theName
|
|
|
|
|
x.isActive = (x.name is "Public") # set public chat to default
|
|
|
|
|
newTabs.push x
|
|
|
|
|
|
|
|
|
|
myTabs.updateValue newTabs
|
|
|
|
|
$(".publicChatTab").addClass('active') # doesn't work when closing the tab that's not currently active :(
|
2014-07-29 23:04:55 +08:00
|
|
|
|
Meteor.call("deletePrivateChatMessages", getInSession("userId"), @userId)
|
2014-07-31 04:51:54 +08:00
|
|
|
|
|
|
|
|
|
Template.chatInput.rendered = ->
|
|
|
|
|
$('input[rel=tooltip]').tooltip()
|
2014-07-31 22:11:01 +08:00
|
|
|
|
$('button[rel=tooltip]').tooltip()
|
|
|
|
|
|
|
|
|
|
@sendMessage = ->
|
|
|
|
|
message = $('#newMessageInput').val() # get the message from the input box
|
|
|
|
|
unless (message?.length > 0 and (/\S/.test(message))) # check the message has content and it is not whitespace
|
|
|
|
|
return # do nothing if invalid message
|
|
|
|
|
|
|
|
|
|
chattingWith = getInSession('inChatWith')
|
|
|
|
|
|
|
|
|
|
messageForServer = { # construct message for server
|
|
|
|
|
"message": message
|
|
|
|
|
"chat_type": if chattingWith is "PUBLIC_CHAT" then "PUBLIC_CHAT" else "PRIVATE_CHAT"
|
|
|
|
|
"from_userid": getInSession("userId")
|
|
|
|
|
"from_username": getUsersName()
|
|
|
|
|
"from_tz_offset": "240"
|
|
|
|
|
"to_username": if chattingWith is "PUBLIC_CHAT" then "public_chat_username" else chattingWith
|
|
|
|
|
"to_userid": if chattingWith is "PUBLIC_CHAT" then "public_chat_userid" else chattingWith
|
|
|
|
|
"from_lang": "en"
|
|
|
|
|
"from_time": getTime()
|
|
|
|
|
"from_color": "0"
|
|
|
|
|
}
|
|
|
|
|
# console.log 'Sending message to server:'
|
|
|
|
|
# console.log messageForServer
|
|
|
|
|
Meteor.call "sendChatMessagetoServer", getInSession("meetingId"), messageForServer
|
|
|
|
|
$('#newMessageInput').val '' # Clear message box
|
2014-07-31 04:51:54 +08:00
|
|
|
|
|
2014-07-02 23:41:12 +08:00
|
|
|
|
Template.chatInput.events
|
2014-07-31 22:11:01 +08:00
|
|
|
|
'click #sendMessageButton': (event) ->
|
|
|
|
|
sendMessage()
|
2014-07-09 21:18:52 +08:00
|
|
|
|
'keypress #newMessageInput': (event) -> # user pressed a button inside the chatbox
|
2014-07-02 23:41:12 +08:00
|
|
|
|
if event.which is 13 # Check for pressing enter to submit message
|
2014-07-31 22:11:01 +08:00
|
|
|
|
sendMessage()
|
2014-07-04 01:56:16 +08:00
|
|
|
|
|
|
|
|
|
Template.optionsBar.events
|
|
|
|
|
'click .private-chat-user-entry': (event) -> # clicked a user's name to begin private chat
|
2014-07-18 04:13:06 +08:00
|
|
|
|
currUserId = getInSession("userId")
|
2014-07-17 23:25:56 +08:00
|
|
|
|
duplicate = (x for x in myTabs.get() when x.userId is @userId)
|
2014-07-04 01:56:16 +08:00
|
|
|
|
|
2014-07-29 05:01:06 +08:00
|
|
|
|
if duplicate.length <=0 and @userId isnt currUserId
|
|
|
|
|
messageForServer =
|
2014-07-22 21:33:27 +08:00
|
|
|
|
"message": "#{getUsersName()} has joined private chat with #{@user.name}."
|
2014-07-09 21:18:52 +08:00
|
|
|
|
"chat_type": "PRIVATE_CHAT"
|
2014-07-18 04:13:06 +08:00
|
|
|
|
"from_userid": getInSession("userId")
|
2014-07-09 21:18:52 +08:00
|
|
|
|
"from_username": getUsersName()
|
|
|
|
|
"from_tz_offset": "240"
|
|
|
|
|
"to_username": @user.name
|
|
|
|
|
"to_userid": @userId
|
|
|
|
|
"from_lang": "en"
|
2014-07-11 23:53:49 +08:00
|
|
|
|
"from_time": getTime()
|
2014-07-09 21:18:52 +08:00
|
|
|
|
"from_color": "0"
|
2014-07-04 01:56:16 +08:00
|
|
|
|
|
2014-07-09 21:18:52 +08:00
|
|
|
|
# console.log 'Sending private message to server:'
|
|
|
|
|
# console.log messageForServer
|
2014-07-18 04:13:06 +08:00
|
|
|
|
Meteor.call "sendChatMessagetoServer", getInSession("meetingId"), messageForServer
|
2014-07-17 23:25:56 +08:00
|
|
|
|
|
|
|
|
|
t = myTabs.getValue()
|
|
|
|
|
t = t.map (x) -> x.isActive = false; return x
|
|
|
|
|
t.push {name: @user.name, isActive: true, class: "privateChatTab", 'userId': @userId }
|
|
|
|
|
myTabs.updateValue t
|
|
|
|
|
$(".optionsChatTab").removeClass('active')
|
|
|
|
|
|
2014-07-18 04:13:06 +08:00
|
|
|
|
setInSession 'display_chatPane', true
|
|
|
|
|
setInSession "inChatWith", @userId
|
2014-07-10 21:11:38 +08:00
|
|
|
|
|
2014-07-09 21:18:52 +08:00
|
|
|
|
Template.tabButtons.helpers
|
|
|
|
|
getChatbarTabs: ->
|
2014-07-17 23:25:56 +08:00
|
|
|
|
myTabs.getValue()
|
2014-07-04 01:56:16 +08:00
|
|
|
|
|
2014-07-09 21:18:52 +08:00
|
|
|
|
makeTabButton: -> # create tab button for private chat or other such as options
|
2014-07-10 21:11:38 +08:00
|
|
|
|
button = '<li '
|
|
|
|
|
button += 'class="'
|
2014-07-09 21:18:52 +08:00
|
|
|
|
button += 'active ' if @isActive
|
2014-07-10 21:11:38 +08:00
|
|
|
|
button += "#{@class} tab\"><a href=\"#\" data-toggle=\"tab\">#{@name}"
|
2014-07-09 21:18:52 +08:00
|
|
|
|
button += ' <button class="close closeTab" type="button" >×</button>' if @name isnt 'Public' and @name isnt 'Options'
|
|
|
|
|
button += '</a></li>'
|
|
|
|
|
button
|
2014-07-07 23:30:17 +08:00
|
|
|
|
|
2014-07-22 21:33:27 +08:00
|
|
|
|
Template.message.rendered = -> # When a message has been added and finished rendering, scroll to the bottom of the chat
|
|
|
|
|
$('#chatScrollWindow').scrollTop($('#chatScrollWindow')[0].scrollHeight)
|