[AIR] reset new messages when viewing chat and scroll to bottom

This commit is contained in:
Chad Pilkey 2018-02-07 16:45:38 -05:00
parent cb59793703
commit d0bc56972c
2 changed files with 29 additions and 2 deletions

View File

@ -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 {

View File

@ -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);