1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-22 21:40:08 +00:00

Merge branch 'privateChannels'

This commit is contained in:
Tim Düsterhus 2013-07-24 16:21:33 +02:00
commit 51c5aed800
2 changed files with 108 additions and 59 deletions

View File

@ -38,6 +38,7 @@ exposed by a function if necessary.
inputErrorHidingTimer = null inputErrorHidingTimer = null
lastMessage = null lastMessage = null
openChannel = 0
remainingFailures = 3 remainingFailures = 3
@ -123,6 +124,9 @@ and afterwards sent to the server by an AJAX request.
return false if text.length is 0 return false if text.length is 0
unless openChannel is 0
text = "/whisper #{$("#timsChatMessageContainer#{openChannel}").data 'username'}, #{text}"
# Free the fish! # Free the fish!
do freeTheFish if text.toLowerCase() is '/free the fish' do freeTheFish if text.toLowerCase() is '/free the fish'
@ -215,8 +219,8 @@ Clear the chat by removing every single message once the clear button is `clicke
$('#timsChatClear').click (event) -> $('#timsChatClear').click (event) ->
do event.preventDefault do event.preventDefault
do $('.timsChatMessage').remove do $('.timsChatMessageContainer.active .timsChatMessage').remove
$('#timsChatMessageContainer').scrollTop $('#timsChatMessageContainer').prop 'scrollHeight' $('.timsChatMessageContainer.active').scrollTop $('.timsChatMessageContainer.active').prop 'scrollHeight'
Handle toggling of the toggleable buttons. Handle toggling of the toggleable buttons.
@ -277,9 +281,9 @@ Scroll down when autoscroll is being activated.
$('#timsChatAutoscroll').click (event) -> $('#timsChatAutoscroll').click (event) ->
if $('#timsChatAutoscroll').data 'status' if $('#timsChatAutoscroll').data 'status'
$('#timsChatMessageContainer').scrollTop $('#timsChatMessageContainer').prop 'scrollHeight' $('.timsChatMessageContainer.active').scrollTop $('.timsChatMessageContainer.active').prop 'scrollHeight'
$('#timsChatMessageContainer').on 'scroll', (event) -> $('.timsChatMessageContainer.active').on 'scroll', (event) ->
element = $ @ element = $ @
scrollTop = element.scrollTop() scrollTop = element.scrollTop()
scrollHeight = element.prop 'scrollHeight' scrollHeight = element.prop 'scrollHeight'
@ -431,14 +435,16 @@ Prevent loading messages in parallel.
Insert the given messages into the chat stream. Insert the given messages into the chat stream.
handleMessages = (messages) -> handleMessages = (messages) ->
$('#timsChatMessageContainer').trigger 'scroll' $('.timsChatMessageContainer.active').trigger 'scroll'
for message in messages for message in messages
events.newMessage.fire message events.newMessage.fire message
message.isInPrivateChannel = (String(message.type) is v.config.messageTypes.WHISPER) and ($.wcfIsset("timsChatMessageContainer#{message.receiver}") or $.wcfIsset("timsChatMessageContainer#{message.sender}"))
createNewMessage = yes createNewMessage = yes
if $('.timsChatMessage:last-child .text').is('ul') and lastMessage isnt null and lastMessage.type in [ 0, 7 ] if $('.timsChatMessage:last-child .text').is('ul') and lastMessage isnt null and lastMessage.type in [ 0, 7 ]
if lastMessage.type is message.type and lastMessage.sender is message.sender and lastMessage.receiver is message.receiver if lastMessage.type is message.type and lastMessage.sender is message.sender and lastMessage.receiver is message.receiver and lastMessage.isInPrivateChannel is message.isInPrivateChannel
createNewMessage = no createNewMessage = no
if createNewMessage if createNewMessage
@ -454,17 +460,29 @@ Insert the given messages into the chat stream.
li.addClass 'ownMessage' if message.sender is WCF.User.userID li.addClass 'ownMessage' if message.sender is WCF.User.userID
li.append output li.append output
li.appendTo $ '#timsChatMessageContainer > ul' if message.isInPrivateChannel and message.sender is WCF.User.userID
li.appendTo $ "#timsChatMessageContainer#{message.receiver} > ul"
else if message.isInPrivateChannel
li.appendTo $ "#timsChatMessageContainer#{message.sender} > ul"
else
li.appendTo $ '#timsChatMessageContainer0 > ul'
else else
message.isFollowUp = yes message.isFollowUp = yes
output = v.messageTemplate.fetch output = v.messageTemplate.fetch
message: message message: message
messageTypes: v.config.messageTypes messageTypes: v.config.messageTypes
$('.timsChatMessage:last-child .text').append $(output).find('.text li:last-child') if message.isInPrivateChannel and message.sender is WCF.User.userID
messageContainerID = message.receiver
else if message.isInPrivateChannel
messageContainerID = message.sender
else
messageContainerID = 0
$("#timsChatMessageContainer#{messageContainerID} .timsChatMessage:last-child .text").append $(output).find('.text li:last-child')
lastMessage = message lastMessage = message
$('#timsChatMessageContainer').scrollTop $('#timsChatMessageContainer').prop('scrollHeight') if $('#timsChatAutoscroll').data('status') is 1 $('.timsChatMessageContainer.active').scrollTop $('.timsChatMessageContainer.active').prop('scrollHeight') if $('#timsChatAutoscroll').data('status') is 1
Rebuild the userlist based on the given `users`. Rebuild the userlist based on the given `users`.
@ -472,60 +490,64 @@ Rebuild the userlist based on the given `users`.
foundUsers = { } foundUsers = { }
for user in users for user in users
id = "timsChatUser#{user.userID}" do (user) ->
id = "timsChatUser#{user.userID}"
Move the user to the new position if he was found in the old list. Move the user to the new position if he was found in the old list.
if $.wcfIsset id if $.wcfIsset id
console.log "Moving User: '#{user.username}'" console.log "Moving User: '#{user.username}'"
element = $("##{id}").detach() element = $("##{id}").detach()
if user.awayStatus? if user.awayStatus?
element.addClass 'away' element.addClass 'away'
element.attr 'title', user.awayStatus element.attr 'title', user.awayStatus
else else
element.removeClass 'away' element.removeClass 'away'
element.removeAttr 'title' element.removeAttr 'title'
element.data 'tooltip', '' element.data 'tooltip', ''
if user.suspended if user.suspended
element.addClass 'suspended' element.addClass 'suspended'
else else
element.removeClass 'suspended' element.removeClass 'suspended'
$('#timsChatUserList > ul').append element $('#timsChatUserList > ul').append element
Build HTML of the user and insert it into the list, if the users was not found in the chat before. Build HTML of the user and insert it into the list, if the users was not found in the chat before.
else else
console.log "Inserting User: '#{user.username}'" console.log "Inserting User: '#{user.username}'"
li = $ '<li></li>' li = $ '<li></li>'
li.attr 'id', id li.attr 'id', id
li.addClass 'timsChatUser' li.addClass 'timsChatUser'
li.addClass 'jsTooltip' li.addClass 'jsTooltip'
li.addClass 'dropdown' li.addClass 'dropdown'
li.addClass 'you' if user.userID is WCF.User.userID li.addClass 'you' if user.userID is WCF.User.userID
li.addClass 'suspended' if user.suspended li.addClass 'suspended' if user.suspended
if user.awayStatus? if user.awayStatus?
li.addClass 'away' li.addClass 'away'
li.attr 'title', user.awayStatus li.attr 'title', user.awayStatus
li.data 'username', user.username li.data 'username', user.username
li.append v.userTemplate.fetch user li.append v.userTemplate.fetch user
menu = $ '<ul></ul>' menu = $ '<ul></ul>'
menu.addClass 'dropdownMenu' unless user.userID is WCF.User.userID
menu.append $ "<li><a>#{WCF.Language.get('chat.general.query')}</a></li>" menu.append $("<li><a>#{WCF.Language.get('chat.general.query')}</a></li>").click -> openPrivateChannel user.userID
menu.append $ "<li><a>#{WCF.Language.get('chat.general.kick')}</a></li>" menu.append $ "<li><a>#{WCF.Language.get('chat.general.kick')}</a></li>"
menu.append $ "<li><a>#{WCF.Language.get('chat.general.ban')}</a></li>" menu.append $ "<li><a>#{WCF.Language.get('chat.general.ban')}</a></li>"
menu.append $ """<li><a href="#{user.link}">#{WCF.Language.get('chat.general.profile')}</a></li>""" menu.append $ """<li><a href="#{user.link}">#{WCF.Language.get('chat.general.profile')}</a></li>"""
events.userMenu.fire user, menu events.userMenu.fire user, menu
li.append menu if menu.find('li').length
li.appendTo $ '#timsChatUserList > ul' li.append menu
menu.addClass 'dropdownMenu'
foundUsers[id] = true li.appendTo $ '#timsChatUserList > ul'
foundUsers[id] = true
Remove all users that left the chat. Remove all users that left the chat.
@ -559,7 +581,7 @@ Send out notifications for the given `message`. The number of unread messages wi
notify = (message) -> notify = (message) ->
if scrollUpNotifications if scrollUpNotifications
$('#timsChatMessageContainer').addClass 'notification' $('.timsChatMessageContainer.active').addClass 'notification'
return if isActive or $('#timsChatNotify').data('status') is 0 return if isActive or $('#timsChatNotify').data('status') is 0
@ -672,6 +694,31 @@ Joins a room.
failure: -> failure: ->
showError WCF.Language.get 'chat.error.join' showError WCF.Language.get 'chat.error.join'
Open private channel
openPrivateChannel = (userID) ->
unless $.wcfIsset "timsChatMessageContainer#{userID}"
return unless $.wcfIsset "timsChatUser#{userID}"
div = $('<div>')
div.attr 'id', "timsChatMessageContainer#{userID}"
div.addClass 'timsChatMessageContainer'
div.addClass 'marginTop'
div.addClass 'container'
div.data 'username', $("#timsChatUser#{userID}").data 'username'
div.wrapInner '<ul>'
$('#timsChatMessageContainer0').after div
$('.timsChatMessageContainer').removeClass 'active'
$("#timsChatMessageContainer#{userID}").addClass 'active'
openChannel = userID
Close private channel
closePrivateChannel = (userID) ->
do $("#timsChatMessageContainer#{userID}").remove unless userID is 0
openPrivateChannel 0
Bind the given callback to the given event. Bind the given callback to the given event.
addListener = (event, callback) -> addListener = (event, callback) ->
@ -697,6 +744,8 @@ And finally export the public methods and variables.
insertText: insertText insertText: insertText
freeTheFish: freeTheFish freeTheFish: freeTheFish
join: join join: join
closePrivateChannel: closePrivateChannel # TODO: REMOVE AFTER DEBUGGING
openPrivateChannel: openPrivateChannel # TODO: REMOVE AFTER DEBUGGING
listener: listener:
add: addListener add: addListener
remove: removeListener remove: removeListener

View File

@ -75,7 +75,7 @@
<span class="topic">{$room->topic|language}</span> <span class="topic">{$room->topic|language}</span>
</div> </div>
<div id="timsChatMessageContainer" class="timsChatMessageContainer marginTop container active"> <div id="timsChatMessageContainer0" class="timsChatMessageContainer marginTop container active">
<p class="error noJsOnly" style="display: none;">{lang}chat.general.noJs{/lang}</p> <p class="error noJsOnly" style="display: none;">{lang}chat.general.noJs{/lang}</p>
<ul> <ul>
</ul> </ul>