From 7cb15e5e9c6d0685e8c24568a83a96375c6622b5 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Tue, 9 Jul 2013 19:41:14 +0200 Subject: [PATCH 1/5] First working draft of private channels --- file/js/be.bastelstu.Chat.litcoffee | 50 +++++++++++++++++++++++------ template/chat.tpl | 2 +- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/file/js/be.bastelstu.Chat.litcoffee b/file/js/be.bastelstu.Chat.litcoffee index faa1071..dd9a09d 100644 --- a/file/js/be.bastelstu.Chat.litcoffee +++ b/file/js/be.bastelstu.Chat.litcoffee @@ -216,8 +216,8 @@ Clear the chat by removing every single message once the clear button is `clicke $('#timsChatClear').click (event) -> event.preventDefault() - $('.timsChatMessage').remove() - $('#timsChatMessageContainer').scrollTop $('#timsChatMessageContainer').prop('scrollHeight') + $('.timsChatMessageContainer.active .timsChatMessage').remove() + $('.timsChatMessageContainer.active').scrollTop $('.timsChatMessageContainer.active').prop('scrollHeight') Handle toggling of the toggleable buttons. @@ -278,9 +278,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' @@ -413,7 +413,7 @@ 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 @@ -435,8 +435,16 @@ Insert the given messages into the chat stream. li.addClass "user#{message.sender}" li.addClass 'ownMessage' if message.sender is WCF.User.userID li.append output - - li.appendTo $ '#timsChatMessageContainer > ul' + + if message.type is parseInt v.config.messageTypes.WHISPER + if message.sender is WCF.User.userID && $.wcfIsset "timsChatMessageContainer#{message.receiver}" + li.appendTo $ "#timsChatMessageContainer#{message.receiver} > ul" + else if $.wcfIsset "timsChatMessageContainer#{message.sender}" + li.appendTo $ "#timsChatMessageContainer#{message.sender} > ul" + else + li.appendTo $ '#timsChatMessageContainer0 > ul' + else + li.appendTo $ '#timsChatMessageContainer0 > ul' else message.isFollowUp = yes output = v.messageTemplate.fetch @@ -446,7 +454,7 @@ Insert the given messages into the chat stream. $('.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`. @@ -541,7 +549,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 @@ -654,6 +662,28 @@ Joins a room. failure: -> showError WCF.Language.get 'chat.error.join' +Open private channel + + openPrivateChannel = (userID) -> + $('.timsChatMessageContainer').removeClass 'active' + + if !$.wcfIsset "timsChatMessageContainer#{userID}" + div = $('
') + div.attr 'id', "timsChatMessageContainer#{userID}" + div.addClass 'timsChatMessageContainer' + div.addClass 'marginTop' + div.addClass 'container' + div.wrapInner '
-
+
From fa03296908c78c46907e2f66d8a557e47a28a205 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Tue, 9 Jul 2013 20:30:46 +0200 Subject: [PATCH 2/5] Improve private channels Follow up messages will be shown in opened private channels --- file/js/be.bastelstu.Chat.litcoffee | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/file/js/be.bastelstu.Chat.litcoffee b/file/js/be.bastelstu.Chat.litcoffee index dd9a09d..48ff867 100644 --- a/file/js/be.bastelstu.Chat.litcoffee +++ b/file/js/be.bastelstu.Chat.litcoffee @@ -418,9 +418,11 @@ Insert the given messages into the chat stream. for message in messages events.newMessage.fire message + message.private = (message.type is parseInt v.config.messageTypes.WHISPER) and ($.wcfIsset("timsChatMessageContainer#{message.receiver}") || $.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.private is message.private createNewMessage = no if createNewMessage @@ -436,13 +438,10 @@ Insert the given messages into the chat stream. li.addClass 'ownMessage' if message.sender is WCF.User.userID li.append output - if message.type is parseInt v.config.messageTypes.WHISPER - if message.sender is WCF.User.userID && $.wcfIsset "timsChatMessageContainer#{message.receiver}" - li.appendTo $ "#timsChatMessageContainer#{message.receiver} > ul" - else if $.wcfIsset "timsChatMessageContainer#{message.sender}" - li.appendTo $ "#timsChatMessageContainer#{message.sender} > ul" - else - li.appendTo $ '#timsChatMessageContainer0 > ul' + if message.private and message.sender is WCF.User.userID + li.appendTo $ "#timsChatMessageContainer#{message.receiver} > ul" + else if message.private + li.appendTo $ "#timsChatMessageContainer#{message.sender} > ul" else li.appendTo $ '#timsChatMessageContainer0 > ul' else @@ -451,7 +450,14 @@ Insert the given messages into the chat stream. message: message messageTypes: v.config.messageTypes - $('.timsChatMessage:last-child .text').append $(output).find('.text li:last-child') + if message.private and message.sender is WCF.User.userID + messageContainerID = message.receiver + else if message.private + messageContainerID = message.sender + else + messageContainerID = 0 + + $("#timsChatMessageContainer#{messageContainerID} .timsChatMessage:last-child .text").append $(output).find('.text li:last-child') lastMessage = message $('.timsChatMessageContainer.active').scrollTop $('.timsChatMessageContainer.active').prop('scrollHeight') if $('#timsChatAutoscroll').data('status') is 1 From 9bb171b4d962a33e8da01e9560e8676b27c4f05d Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Tue, 9 Jul 2013 20:45:35 +0200 Subject: [PATCH 3/5] Rename variable and fix closing of private channels --- file/js/be.bastelstu.Chat.litcoffee | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/file/js/be.bastelstu.Chat.litcoffee b/file/js/be.bastelstu.Chat.litcoffee index 48ff867..c46f5c9 100644 --- a/file/js/be.bastelstu.Chat.litcoffee +++ b/file/js/be.bastelstu.Chat.litcoffee @@ -418,11 +418,11 @@ Insert the given messages into the chat stream. for message in messages events.newMessage.fire message - message.private = (message.type is parseInt v.config.messageTypes.WHISPER) and ($.wcfIsset("timsChatMessageContainer#{message.receiver}") || $.wcfIsset("timsChatMessageContainer#{message.sender}")) + 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 and lastMessage.private is message.private + 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 @@ -438,9 +438,9 @@ Insert the given messages into the chat stream. li.addClass 'ownMessage' if message.sender is WCF.User.userID li.append output - if message.private and message.sender is WCF.User.userID + if message.isInPrivateChannel and message.sender is WCF.User.userID li.appendTo $ "#timsChatMessageContainer#{message.receiver} > ul" - else if message.private + else if message.isInPrivateChannel li.appendTo $ "#timsChatMessageContainer#{message.sender} > ul" else li.appendTo $ '#timsChatMessageContainer0 > ul' @@ -450,9 +450,9 @@ Insert the given messages into the chat stream. message: message messageTypes: v.config.messageTypes - if message.private and message.sender is WCF.User.userID + if message.isInPrivateChannel and message.sender is WCF.User.userID messageContainerID = message.receiver - else if message.private + else if message.isInPrivateChannel messageContainerID = message.sender else messageContainerID = 0 @@ -687,8 +687,8 @@ Open private channel Close private channel closePrivateChannel = (userID) -> - $("#timsChatMessageContainer#{userID}").remove() unless userID isnt 0 - $("#timsChatMessageContainer0").addClass('active') + $("#timsChatMessageContainer#{userID}").remove() unless userID is 0 + openPrivateChannel 0 Bind the given callback to the given event. From 6c5911d42b206670c78b0d7fdec90ea89ce4ea8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 9 Jul 2013 21:39:31 +0200 Subject: [PATCH 4/5] Convert messages to whisper when in private channel --- file/js/be.bastelstu.Chat.litcoffee | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/file/js/be.bastelstu.Chat.litcoffee b/file/js/be.bastelstu.Chat.litcoffee index c46f5c9..d2c704f 100644 --- a/file/js/be.bastelstu.Chat.litcoffee +++ b/file/js/be.bastelstu.Chat.litcoffee @@ -36,6 +36,7 @@ exposed by a function if necessary. errorVisible = false lastMessage = null + openChannel = 0 remainingFailures = 3 @@ -121,6 +122,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! freeTheFish() if text.toLowerCase() is '/free the fish' @@ -671,18 +675,21 @@ Joins a room. Open private channel openPrivateChannel = (userID) -> - $('.timsChatMessageContainer').removeClass 'active' - if !$.wcfIsset "timsChatMessageContainer#{userID}" + return unless $.wcfIsset "timsChatUser#{userID}" + div = $('
') div.attr 'id', "timsChatMessageContainer#{userID}" div.addClass 'timsChatMessageContainer' div.addClass 'marginTop' div.addClass 'container' + div.data 'username', $("#timsChatUser#{userID}").data 'username' div.wrapInner '
    ' $('#timsChatMessageContainer0').after div - - $("#timsChatMessageContainer#{userID}").addClass('active') + + $('.timsChatMessageContainer').removeClass 'active' + $("#timsChatMessageContainer#{userID}").addClass 'active' + openChannel = userID Close private channel From 476954fe8d51a1217e980d34115ec39db9e58a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 9 Jul 2013 22:02:47 +0200 Subject: [PATCH 5/5] Allow the user to open a privat channel --- file/js/be.bastelstu.Chat.litcoffee | 98 +++++++++++++++-------------- 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/file/js/be.bastelstu.Chat.litcoffee b/file/js/be.bastelstu.Chat.litcoffee index a429fb6..5776b7a 100644 --- a/file/js/be.bastelstu.Chat.litcoffee +++ b/file/js/be.bastelstu.Chat.litcoffee @@ -490,60 +490,64 @@ Rebuild the userlist based on the given `users`. foundUsers = { } 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. - if $.wcfIsset id - console.log "Moving User: '#{user.username}'" - element = $("##{id}").detach() - - if user.awayStatus? - element.addClass 'away' - element.attr 'title', user.awayStatus - else - element.removeClass 'away' - element.removeAttr 'title' - element.data 'tooltip', '' - - if user.suspended - element.addClass 'suspended' - else - element.removeClass 'suspended' - - $('#timsChatUserList > ul').append element + if $.wcfIsset id + console.log "Moving User: '#{user.username}'" + element = $("##{id}").detach() + + if user.awayStatus? + element.addClass 'away' + element.attr 'title', user.awayStatus + else + element.removeClass 'away' + element.removeAttr 'title' + element.data 'tooltip', '' + + if user.suspended + element.addClass 'suspended' + else + element.removeClass 'suspended' + + $('#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. - else - console.log "Inserting User: '#{user.username}'" - li = $ '
  • ' - li.attr 'id', id - li.addClass 'timsChatUser' - li.addClass 'jsTooltip' - li.addClass 'dropdown' - li.addClass 'you' if user.userID is WCF.User.userID - li.addClass 'suspended' if user.suspended - if user.awayStatus? - li.addClass 'away' - li.attr 'title', user.awayStatus - li.data 'username', user.username + else + console.log "Inserting User: '#{user.username}'" + li = $ '
  • ' + li.attr 'id', id + li.addClass 'timsChatUser' + li.addClass 'jsTooltip' + li.addClass 'dropdown' + li.addClass 'you' if user.userID is WCF.User.userID + li.addClass 'suspended' if user.suspended + if user.awayStatus? + li.addClass 'away' + li.attr 'title', user.awayStatus + li.data 'username', user.username + + li.append v.userTemplate.fetch user + + menu = $ '
      ' + unless user.userID is WCF.User.userID + menu.append $("
    • #{WCF.Language.get('chat.general.query')}
    • ").click -> openPrivateChannel user.userID + menu.append $ "
    • #{WCF.Language.get('chat.general.kick')}
    • " + menu.append $ "
    • #{WCF.Language.get('chat.general.ban')}
    • " + menu.append $ """
    • #{WCF.Language.get('chat.general.profile')}
    • """ + + events.userMenu.fire user, menu + + if menu.find('li').length + li.append menu + menu.addClass 'dropdownMenu' + + li.appendTo $ '#timsChatUserList > ul' - li.append v.userTemplate.fetch user - - menu = $ '
        ' - menu.addClass 'dropdownMenu' - menu.append $ "
      • #{WCF.Language.get('chat.general.query')}
      • " - menu.append $ "
      • #{WCF.Language.get('chat.general.kick')}
      • " - menu.append $ "
      • #{WCF.Language.get('chat.general.ban')}
      • " - menu.append $ """
      • #{WCF.Language.get('chat.general.profile')}
      • """ - - events.userMenu.fire user, menu - - li.append menu - li.appendTo $ '#timsChatUserList > ul' - - foundUsers[id] = true + foundUsers[id] = true Remove all users that left the chat.