From 42ef646685a5f88808e22843172b71286ac5617b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 23 Jun 2013 19:46:50 +0200 Subject: [PATCH] Merge similar messages together --- file/js/be.bastelstu.Chat.litcoffee | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/file/js/be.bastelstu.Chat.litcoffee b/file/js/be.bastelstu.Chat.litcoffee index 74e9894..e130464 100644 --- a/file/js/be.bastelstu.Chat.litcoffee +++ b/file/js/be.bastelstu.Chat.litcoffee @@ -35,6 +35,8 @@ exposed by a function if necessary. chatSession = Date.now() errorVisible = false + lastMessage = null + remainingFailures = 3 events = @@ -411,16 +413,25 @@ Insert the given messages into the chat stream. for message in messages events.newMessage.fire message - output = v.messageTemplate.fetch message - li = $ '
  • ' - li.addClass 'timsChatMessage' - li.addClass "timsChatMessage#{message.type}" - li.addClass "user#{message.sender}" - li.addClass 'ownMessage' if message.sender is WCF.User.userID - li.append output + 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 + createNewMessage = no - li.appendTo $ '#timsChatMessageContainer > ul' - + output = v.messageTemplate.fetch message + if createNewMessage + li = $ '
  • ' + li.addClass 'timsChatMessage' + li.addClass "timsChatMessage#{message.type}" + li.addClass "user#{message.sender}" + li.addClass 'ownMessage' if message.sender is WCF.User.userID + li.append output + + li.appendTo $ '#timsChatMessageContainer > ul' + else + $('.timsChatMessage:last-child .text').append $(output).find('.text li:last-child') + + lastMessage = message $('#timsChatMessageContainer').scrollTop $('#timsChatMessageContainer').prop('scrollHeight') if $('#timsChatAutoscroll').data('status') is 1 Rebuild the userlist based on the given `users`.