bigbluebutton-Github/labs/meteor-client/client/views/chat/chat_bar.coffee

118 lines
4.7 KiB
CoffeeScript
Raw Normal View History

Template.messageBar.helpers
getMessagesInChat: (beforeJoin=true) ->
friend = chattingWith = getInSession('inChatWith') # the recipient(s) of the messages
if chattingWith is 'PUBLIC_CHAT' # find all public messages
if beforeJoin
Meteor.Chat.find({'message.chat_type': chattingWith, 'message.from_time': {$lt: String(getInSession("joinedAt"))}})
else
Meteor.Chat.find({'message.chat_type': chattingWith, 'message.from_time': {$gt: String(getInSession("joinedAt"))}})
else
me = getInSession("userId")
Meteor.Chat.find({ # find all messages between current user and recipient
'message.chat_type': 'PRIVATE_CHAT',
$or: [{'message.from_userid': me, 'message.to_userid': friend},{'message.from_userid': friend, 'message.to_userid': me}]
})
isUserInPrivateChat: -> # true if user is in public chat
getInSession('inChatWith') isnt "PUBLIC_CHAT"
2014-06-25 21:28:15 +08:00
2014-07-02 23:41:12 +08:00
Template.tabButtons.events
2014-07-17 23:25:56 +08:00
'click .tab': (event) -> ;
'click .publicChatTab': (event) ->
setInSession 'display_chatPane', true
setInSession 'inChatWith', 'PUBLIC_CHAT'
2014-07-04 01:56:16 +08:00
'click .optionsChatTab': (event) ->
setInSession 'display_chatPane', false
2014-06-24 21:46:42 +08:00
'click .privateChatTab': (event) ->
setInSession 'display_chatPane', true
setInSession 'inChatWith', @userId
2014-07-17 23:25:56 +08:00
'click .close': (event) -> # user closes private chat
2014-07-17 23:25:56 +08:00
theName = @name
console.log theName
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-07 23:30:17 +08:00
2014-07-02 23:41:12 +08:00
Template.chatInput.events
'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
chattingWith = getInSession('inChatWith')
2014-07-02 23:41:12 +08:00
messageForServer = { # construct message for server
"message": $("#newMessageInput").val()
"chat_type": if chattingWith is "PUBLIC_CHAT" then "PUBLIC_CHAT" else "PRIVATE_CHAT"
"from_userid": getInSession("userId")
"from_username": getUsersName()
2014-07-02 23:41:12 +08:00
"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
2014-07-02 23:41:12 +08:00
"from_lang": "en"
"from_time": getTime()
2014-07-02 23:41:12 +08:00
"from_color": "0"
}
# console.log 'Sending message to server:'
# console.log messageForServer
Meteor.call "sendChatMessagetoServer", getInSession("meetingId"), messageForServer
2014-07-02 23:41:12 +08:00
$('#newMessageInput').val '' # Clear message box
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
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-17 23:25:56 +08:00
if duplicate.length<=0 and @userId isnt currUserId
messageForServer = {
"message": "Hey #{@user.name}, its #{getUsersName()} lets start a private chat."
"chat_type": "PRIVATE_CHAT"
"from_userid": getInSession("userId")
"from_username": getUsersName()
"from_tz_offset": "240"
"to_username": @user.name
"to_userid": @userId
"from_lang": "en"
"from_time": getTime()
"from_color": "0"
}
2014-07-04 01:56:16 +08:00
# console.log 'Sending private message to server:'
# console.log messageForServer
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')
setInSession 'display_chatPane', true
setInSession "inChatWith", @userId
Template.tabButtons.helpers
getChatbarTabs: ->
2014-07-17 23:25:56 +08:00
console.log myTabs.getValue()
myTabs.getValue()
2014-07-04 01:56:16 +08:00
makeTabButton: -> # create tab button for private chat or other such as options
button = '<li '
button += 'class="'
button += 'active ' if @isActive
button += "#{@class} tab\"><a href=\"#\" data-toggle=\"tab\">#{@name}"
button += '&nbsp;<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