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:
commit
51c5aed800
@ -38,6 +38,7 @@ exposed by a function if necessary.
|
||||
inputErrorHidingTimer = null
|
||||
|
||||
lastMessage = null
|
||||
openChannel = 0
|
||||
|
||||
remainingFailures = 3
|
||||
|
||||
@ -123,6 +124,9 @@ and afterwards sent to the server by an AJAX request.
|
||||
|
||||
return false if text.length is 0
|
||||
|
||||
unless openChannel is 0
|
||||
text = "/whisper #{$("#timsChatMessageContainer#{openChannel}").data 'username'}, #{text}"
|
||||
|
||||
# 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) ->
|
||||
do event.preventDefault
|
||||
do $('.timsChatMessage').remove
|
||||
$('#timsChatMessageContainer').scrollTop $('#timsChatMessageContainer').prop 'scrollHeight'
|
||||
do $('.timsChatMessageContainer.active .timsChatMessage').remove
|
||||
$('.timsChatMessageContainer.active').scrollTop $('.timsChatMessageContainer.active').prop 'scrollHeight'
|
||||
|
||||
Handle toggling of the toggleable buttons.
|
||||
|
||||
@ -277,9 +281,9 @@ Scroll down when autoscroll is being activated.
|
||||
|
||||
$('#timsChatAutoscroll').click (event) ->
|
||||
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 = $ @
|
||||
scrollTop = element.scrollTop()
|
||||
scrollHeight = element.prop 'scrollHeight'
|
||||
@ -431,14 +435,16 @@ Prevent loading messages in parallel.
|
||||
Insert the given messages into the chat stream.
|
||||
|
||||
handleMessages = (messages) ->
|
||||
$('#timsChatMessageContainer').trigger 'scroll'
|
||||
$('.timsChatMessageContainer.active').trigger 'scroll'
|
||||
|
||||
for message in messages
|
||||
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
|
||||
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
|
||||
|
||||
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.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
|
||||
message.isFollowUp = yes
|
||||
output = v.messageTemplate.fetch
|
||||
message: message
|
||||
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
|
||||
$('#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`.
|
||||
|
||||
@ -472,6 +490,7 @@ Rebuild the userlist based on the given `users`.
|
||||
foundUsers = { }
|
||||
|
||||
for user in users
|
||||
do (user) ->
|
||||
id = "timsChatUser#{user.userID}"
|
||||
|
||||
Move the user to the new position if he was found in the old list.
|
||||
@ -514,15 +533,18 @@ Build HTML of the user and insert it into the list, if the users was not found i
|
||||
li.append v.userTemplate.fetch user
|
||||
|
||||
menu = $ '<ul></ul>'
|
||||
menu.addClass 'dropdownMenu'
|
||||
menu.append $ "<li><a>#{WCF.Language.get('chat.general.query')}</a></li>"
|
||||
unless user.userID is WCF.User.userID
|
||||
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.ban')}</a></li>"
|
||||
menu.append $ """<li><a href="#{user.link}">#{WCF.Language.get('chat.general.profile')}</a></li>"""
|
||||
|
||||
events.userMenu.fire user, menu
|
||||
|
||||
if menu.find('li').length
|
||||
li.append menu
|
||||
menu.addClass 'dropdownMenu'
|
||||
|
||||
li.appendTo $ '#timsChatUserList > ul'
|
||||
|
||||
foundUsers[id] = true
|
||||
@ -559,7 +581,7 @@ Send out notifications for the given `message`. The number of unread messages wi
|
||||
|
||||
notify = (message) ->
|
||||
if scrollUpNotifications
|
||||
$('#timsChatMessageContainer').addClass 'notification'
|
||||
$('.timsChatMessageContainer.active').addClass 'notification'
|
||||
|
||||
return if isActive or $('#timsChatNotify').data('status') is 0
|
||||
|
||||
@ -672,6 +694,31 @@ Joins a room.
|
||||
failure: ->
|
||||
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.
|
||||
|
||||
addListener = (event, callback) ->
|
||||
@ -697,6 +744,8 @@ And finally export the public methods and variables.
|
||||
insertText: insertText
|
||||
freeTheFish: freeTheFish
|
||||
join: join
|
||||
closePrivateChannel: closePrivateChannel # TODO: REMOVE AFTER DEBUGGING
|
||||
openPrivateChannel: openPrivateChannel # TODO: REMOVE AFTER DEBUGGING
|
||||
listener:
|
||||
add: addListener
|
||||
remove: removeListener
|
||||
|
@ -75,7 +75,7 @@
|
||||
<span class="topic">{$room->topic|language}</span>
|
||||
</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>
|
||||
<ul>
|
||||
</ul>
|
||||
|
Loading…
Reference in New Issue
Block a user