From d0bc56972ca8c73db60e180548baeb291f6308e9 Mon Sep 17 00:00:00 2001 From: Chad Pilkey Date: Wed, 7 Feb 2018 16:45:38 -0500 Subject: [PATCH] [AIR] reset new messages when viewing chat and scroll to bottom --- .../lib/chat/models/GroupChat.as | 5 ++++ .../lib/chat/views/ChatViewMediatorBase.as | 26 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/clients/flash/common-library/src/main/actionscript/org/bigbluebutton/lib/chat/models/GroupChat.as b/clients/flash/common-library/src/main/actionscript/org/bigbluebutton/lib/chat/models/GroupChat.as index 43429099cf..5582bfdec9 100755 --- a/clients/flash/common-library/src/main/actionscript/org/bigbluebutton/lib/chat/models/GroupChat.as +++ b/clients/flash/common-library/src/main/actionscript/org/bigbluebutton/lib/chat/models/GroupChat.as @@ -2,6 +2,7 @@ package org.bigbluebutton.lib.chat.models { import mx.collections.ArrayCollection; import org.bigbluebutton.lib.chat.utils.ChatUtil; + import org.osflash.signals.Signal; [Bindable] public class GroupChat { @@ -21,6 +22,8 @@ package org.bigbluebutton.lib.chat.models { public var newMessages:Number = 0; + public var newMessageSignal:Signal = new Signal(); + public function GroupChat(chatId:String, name:String, isPublic:Boolean, partnerId:String) { this.chatId = chatId; this.name = name; @@ -33,6 +36,7 @@ package org.bigbluebutton.lib.chat.models { convertAndAddChatMessage(message); } newMessages += messages.length; + newMessageSignal.dispatch(chatId); } public function clearMessages():void { @@ -44,6 +48,7 @@ package org.bigbluebutton.lib.chat.models { public function newChatMessage(message:ChatMessageVO):void { convertAndAddChatMessage(message); newMessages++; + newMessageSignal.dispatch(chatId); } private function convertAndAddChatMessage(message:ChatMessageVO):void { diff --git a/clients/flash/common-library/src/main/actionscript/org/bigbluebutton/lib/chat/views/ChatViewMediatorBase.as b/clients/flash/common-library/src/main/actionscript/org/bigbluebutton/lib/chat/views/ChatViewMediatorBase.as index 2d7465ed26..ba498416a3 100755 --- a/clients/flash/common-library/src/main/actionscript/org/bigbluebutton/lib/chat/views/ChatViewMediatorBase.as +++ b/clients/flash/common-library/src/main/actionscript/org/bigbluebutton/lib/chat/views/ChatViewMediatorBase.as @@ -15,6 +15,8 @@ package org.bigbluebutton.lib.chat.views { import robotlegs.bender.bundles.mvcs.Mediator; + import spark.core.NavigationUnit; + public class ChatViewMediatorBase extends Mediator { [Inject] @@ -41,9 +43,25 @@ package org.bigbluebutton.lib.chat.views { } protected function openChat(chat:GroupChat):void { + if (_chat) { + _chat.newMessageSignal.remove(onNewMessage); + } + _chat = chat; - _chat.newMessages = 0; //resetNewMessages(); - view.chatList.dataProvider = _chat.messages; + if (_chat) { + _chat.newMessages = 0; //resetNewMessages(); + view.chatList.dataProvider = _chat.messages; + _chat.newMessageSignal.add(onNewMessage); + } + } + + protected function onNewMessage(chatId:String):void { + if (_chat && _chat.chatId == chatId) { + if (view) { + view.chatList.scroller.verticalScrollBar.value = view.chatList.scroller.verticalScrollBar.maximum; + } + _chat.newMessages = 0; + } } private function onSendSuccess(result:String):void { @@ -117,6 +135,10 @@ package org.bigbluebutton.lib.chat.views { chatMessageService.sendMessageOnFailureSignal.remove(onSendFailure); meetingData.users.userChangeSignal.remove(onUserChange); + if (_chat) { + _chat.newMessageSignal.remove(onNewMessage); + } + view.textInput.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler); view.sendButton.removeEventListener(MouseEvent.CLICK, sendButtonClickHandler);