- display chat messages

This commit is contained in:
Richard Alam 2017-09-14 12:58:00 -07:00
parent 9fb29ac7b2
commit 24be8ff3f3
13 changed files with 155 additions and 119 deletions

View File

@ -1,17 +1,16 @@
package org.bigbluebutton.modules.chat.events
{
import flash.events.Event;
import org.bigbluebutton.modules.chat.model.ChatConversation;
public class ChatCopyEvent extends Event
{
public static const COPY_CHAT_EVENT:String = 'COPY_CHAT_EVENT';
public var chatMessages:ChatConversation;
public var chatId:String;
public function ChatCopyEvent(type:String, bubbles:Boolean=true, cancelable:Boolean=false)
public function ChatCopyEvent(type:String)
{
super(type, bubbles, cancelable);
super(type, true, false);
}
}
}

View File

@ -25,11 +25,11 @@ package org.bigbluebutton.modules.chat.events
public static const REQUEST_HISTORY:String = "REQUEST_HISTORY";
public static const RECEIVED_HISTORY:String = 'RECEIVED_HISTORY';
public var history:Array;
public var chatId:String;
public function ChatHistoryEvent(type:String, bubbles:Boolean=true, cancelable:Boolean=false)
public function ChatHistoryEvent(type:String)
{
super(type, bubbles, cancelable);
super(type, true, false);
}
}

View File

@ -1,18 +1,17 @@
package org.bigbluebutton.modules.chat.events
{
import flash.events.Event;
import org.bigbluebutton.modules.chat.model.ChatConversation;
public class ChatSaveEvent extends Event
{
public static const SAVE_CHAT_EVENT:String = 'SAVE_CHAT_EVENT';
public var chatMessages:ChatConversation;
public var chatId: String;
public var filename:String;
public function ChatSaveEvent(type:String, bubbles:Boolean=true, cancelable:Boolean=false)
public function ChatSaveEvent(type:String)
{
super(type, bubbles, cancelable);
super(type, true, false);
}
}
}

View File

@ -20,17 +20,16 @@ package org.bigbluebutton.modules.chat.events
{
import flash.events.Event;
import org.bigbluebutton.modules.chat.vo.ChatMessageVO;
public class PublicChatMessageEvent extends Event
{
public static const PUBLIC_CHAT_MESSAGE_EVENT:String = 'PUBLIC_CHAT_MESSAGE_EVENT';
public var message:ChatMessageVO;
public var id:String;
public var senderId: String;
public function PublicChatMessageEvent(type:String, bubbles:Boolean=true, cancelable:Boolean=false)
{
super(type, bubbles, cancelable);
super(type, true, false);
}
}

View File

@ -19,25 +19,23 @@
package org.bigbluebutton.modules.chat.model
{
import com.adobe.utils.StringUtil;
import com.asfusion.mate.events.Dispatcher;
import flash.system.Capabilities;
import com.asfusion.mate.events.Dispatcher;
import flash.system.Capabilities;
import mx.collections.ArrayCollection;
import org.bigbluebutton.modules.chat.ChatUtil;
import org.bigbluebutton.modules.chat.events.ChatHistoryEvent;
import org.bigbluebutton.modules.chat.events.PublicChatMessageEvent;
import org.bigbluebutton.modules.chat.vo.ChatMessageVO;
import org.bigbluebutton.util.i18n.ResourceUtil;
public class ChatConversation
{
private var _dispatcher:Dispatcher = new Dispatcher();
[Bindable]
public var messages:ArrayCollection = new ArrayCollection();
private var id: String;
public function ChatConversation(id: String) {
@ -51,29 +49,36 @@ package org.bigbluebutton.modules.chat.model
public function numMessages():int {
return messages.length;
}
public function newChatMessage(msg:ChatMessageVO):void {
var newCM:ChatMessage = convertChatMessage(msg);
if (messages.length > 0) {
var previousCM:ChatMessage = messages.getItemAt(messages.length-1) as ChatMessage;
newCM.lastSenderId = previousCM.senderId;
newCM.lastTime = previousCM.time;
}
messages.addItem(newCM);
if (messages.length > 0) {
var previousCM:ChatMessage = messages.getItemAt(messages.length-1) as ChatMessage;
newCM.lastSenderId = previousCM.senderId;
newCM.lastTime = previousCM.time;
}
messages.addItem(newCM);
trace("NUM MESSAGES = " + messages.length);
var pcEvent:PublicChatMessageEvent = new PublicChatMessageEvent(PublicChatMessageEvent.PUBLIC_CHAT_MESSAGE_EVENT);
pcEvent.id = id;
pcEvent.senderId = newCM.senderId;
_dispatcher.dispatchEvent(pcEvent);
}
public function processChatHistory(messageVOs:Array):void {
if (messageVOs.length > 0) {
var previousCM:ChatMessage = convertChatMessage(messageVOs[0] as ChatMessageVO);;
var newCM:ChatMessage;
messages.addItemAt(previousCM, 0);
var newCM:ChatMessage;
messages.addItemAt(previousCM, 0);
for (var i:int=1; i < messageVOs.length; i++) {
newCM = convertChatMessage(messageVOs[i] as ChatMessageVO);
newCM.lastSenderId = previousCM.senderId;
newCM.lastTime = previousCM.time;
messages.addItemAt(newCM, i);
previousCM = newCM;
newCM.lastSenderId = previousCM.senderId;
newCM.lastTime = previousCM.time;
messages.addItemAt(newCM, i);
previousCM = newCM;
}
if (messageVOs.length < messages.length) {
@ -82,36 +87,40 @@ package org.bigbluebutton.modules.chat.model
newCM.lastTime = previousCM.time;
}
}
var chEvent:ChatHistoryEvent = new ChatHistoryEvent(ChatHistoryEvent.RECEIVED_HISTORY);
chEvent.chatId = id;
_dispatcher.dispatchEvent(chEvent);
}
private function convertChatMessage(msgVO:ChatMessageVO):ChatMessage {
var cm:ChatMessage = new ChatMessage();
cm.lastSenderId = "";
cm.lastTime = "";
cm.senderId = msgVO.fromUserId;
cm.text = msgVO.message;
cm.name = msgVO.fromUsername;
cm.senderColor = uint(msgVO.fromColor);
// Welcome message will skip time
if (msgVO.fromTime != -1) {
cm.fromTime = msgVO.fromTime;
cm.fromTimezoneOffset = msgVO.fromTimezoneOffset;
cm.time = convertTimeNumberToString(msgVO.fromTime);
}
return cm
var cm:ChatMessage = new ChatMessage();
cm.lastSenderId = "";
cm.lastTime = "";
cm.senderId = msgVO.fromUserId;
cm.text = msgVO.message;
cm.name = msgVO.fromUsername;
cm.senderColor = uint(msgVO.fromColor);
// Welcome message will skip time
if (msgVO.fromTime != -1) {
cm.fromTime = msgVO.fromTime;
cm.fromTimezoneOffset = msgVO.fromTimezoneOffset;
cm.time = convertTimeNumberToString(msgVO.fromTime);
}
return cm
}
private function convertTimeNumberToString(time:Number):String {
var sentTime:Date = new Date();
sentTime.setTime(time);
return ChatUtil.getHours(sentTime) + ":" + ChatUtil.getMinutes(sentTime);
}
private function convertTimeNumberToString(time:Number):String {
var sentTime:Date = new Date();
sentTime.setTime(time);
return ChatUtil.getHours(sentTime) + ":" + ChatUtil.getMinutes(sentTime);
}
public function getAllMessageAsString():String{
var allText:String = "";
var returnStr:String = (Capabilities.os.indexOf("Windows") >= 0 ? "\r\n" : "\n");
@ -125,17 +134,17 @@ package org.bigbluebutton.modules.chat.model
}
return allText;
}
public function clearPublicChat():void {
var cm:ChatMessage = new ChatMessage();
cm.time = convertTimeNumberToString(new Date().time);
cm.text = "<b><i>"+ResourceUtil.getInstance().getString('bbb.chat.clearBtn.chatMessage')+"</i></b>";
cm.name = "";
cm.senderColor = uint(0x000000);
messages.removeAll();
messages.addItem(cm);
var welcomeEvent:ChatHistoryEvent = new ChatHistoryEvent(ChatHistoryEvent.RECEIVED_HISTORY);
_dispatcher.dispatchEvent(welcomeEvent);
}

View File

@ -43,9 +43,15 @@ package org.bigbluebutton.modules.chat.model
public function getChatConversation(convId:String):ChatConversation {
if (convs.hasOwnProperty(convId)) {
trace("FOUND chatId = " + convId);
return convs[convId];
} else {
trace("NOT FOUND chatId = " + convId);
var conv: ChatConversation = new ChatConversation(convId);
convs[convId] = conv;
return conv;
}
return new ChatConversation(convId);
}
}
}

View File

@ -1,17 +1,19 @@
package org.bigbluebutton.modules.chat.services
{
import flash.system.System;
import mx.controls.Alert;
import org.bigbluebutton.modules.chat.model.ChatConversation;
import org.bigbluebutton.core.model.LiveMeeting;
import org.bigbluebutton.modules.chat.events.ChatCopyEvent;
import org.bigbluebutton.util.i18n.ResourceUtil;
import org.bigbluebutton.modules.chat.model.ChatConversation;
import org.bigbluebutton.util.i18n.ResourceUtil;
public class ChatCopy
{
public function copyAllText(e:ChatCopyEvent):void {
var chat:ChatConversation = e.chatMessages;
var chatId: String = e.chatId;
var chat: ChatConversation = LiveMeeting.inst().chats.getChatConversation(chatId);
System.setClipboard(chat.getAllMessageAsString());
Alert.show(ResourceUtil.getInstance().getString('bbb.chat.copy.complete'), "", Alert.OK);
}

View File

@ -28,6 +28,8 @@ package org.bigbluebutton.modules.chat.services
import org.bigbluebutton.core.model.LiveMeeting;
import org.bigbluebutton.modules.chat.ChatConstants;
import org.bigbluebutton.modules.chat.events.PublicChatMessageEvent;
import org.bigbluebutton.modules.chat.model.ChatConversation;
import org.bigbluebutton.modules.chat.model.ChatModel;
import org.bigbluebutton.modules.chat.vo.ChatMessageVO;
import org.bigbluebutton.util.i18n.ResourceUtil;
@ -104,10 +106,10 @@ package org.bigbluebutton.modules.chat.services
welcomeMsg.toUserId = SPACE;
welcomeMsg.toUsername = SPACE;
welcomeMsg.message = welcome;
var publicChat: ChatConversation = LiveMeeting.inst().chats.getChatConversation(ChatModel.PUBLIC_CHAT_USERID);
publicChat.newChatMessage(welcomeMsg);
var welcomeMsgEvent:PublicChatMessageEvent = new PublicChatMessageEvent(PublicChatMessageEvent.PUBLIC_CHAT_MESSAGE_EVENT);
welcomeMsgEvent.message = welcomeMsg;
dispatcher.dispatchEvent(welcomeMsgEvent);
//Say that client is ready when sending the welcome message
ExternalInterface.call("clientReady", ResourceUtil.getInstance().getString('bbb.accessibility.clientReady'));
@ -124,10 +126,10 @@ package org.bigbluebutton.modules.chat.services
moderatorOnlyMsg.toUserId = SPACE;
moderatorOnlyMsg.toUsername = SPACE;
moderatorOnlyMsg.message = LiveMeeting.inst().meeting.modOnlyMessage;
var pChat: ChatConversation = LiveMeeting.inst().chats.getChatConversation(ChatModel.PUBLIC_CHAT_USERID);
pChat.newChatMessage(moderatorOnlyMsg);
var moderatorOnlyMsgEvent:PublicChatMessageEvent = new PublicChatMessageEvent(PublicChatMessageEvent.PUBLIC_CHAT_MESSAGE_EVENT);
moderatorOnlyMsgEvent.message = moderatorOnlyMsg;
dispatcher.dispatchEvent(moderatorOnlyMsgEvent);
}
}
}

View File

@ -1,20 +1,25 @@
package org.bigbluebutton.modules.chat.services
{
import flash.events.Event;
import mx.controls.Alert;
import flash.net.FileReference;
import org.bigbluebutton.modules.chat.model.ChatConversation;
import mx.controls.Alert;
import org.bigbluebutton.core.model.LiveMeeting;
import org.bigbluebutton.modules.chat.events.ChatSaveEvent;
import org.bigbluebutton.util.i18n.ResourceUtil;
import org.bigbluebutton.modules.chat.model.ChatConversation;
import org.bigbluebutton.util.i18n.ResourceUtil;
public class ChatSaver
{
public function ChatSaver(){}
public function saveChatToFile(e:ChatSaveEvent):void{
var chat:ChatConversation = e.chatMessages;
var chatId: String = e.chatId;
var filename:String = e.filename;
var chat: ChatConversation = LiveMeeting.inst().chats.getChatConversation(chatId);
var textToExport:String = chat.getAllMessageAsString();
var fileRef:FileReference = new FileReference();

View File

@ -27,10 +27,8 @@ package org.bigbluebutton.modules.chat.services
import org.bigbluebutton.core.events.CoreEvent;
import org.bigbluebutton.core.model.LiveMeeting;
import org.bigbluebutton.main.model.users.IMessageListener;
import org.bigbluebutton.modules.chat.events.ChatHistoryEvent;
import org.bigbluebutton.modules.chat.events.ClearPublicChatEvent;
import org.bigbluebutton.modules.chat.events.PrivateChatMessageEvent;
import org.bigbluebutton.modules.chat.events.PublicChatMessageEvent;
import org.bigbluebutton.modules.chat.model.ChatConversation;
import org.bigbluebutton.modules.chat.model.ChatModel;
import org.bigbluebutton.modules.chat.vo.ChatMessageVO;
@ -79,22 +77,19 @@ package org.bigbluebutton.modules.chat.services
var publicChat: ChatConversation = LiveMeeting.inst().chats.getChatConversation(ChatModel.PUBLIC_CHAT_USERID);
publicChat.processChatHistory(processedMessages);
var chEvent:ChatHistoryEvent = new ChatHistoryEvent(ChatHistoryEvent.RECEIVED_HISTORY);
chEvent.history = processedMessages;
dispatcher.dispatchEvent(chEvent);
}
private function handleSendPublicMessageEvtMsg(message:Object, history:Boolean = false):void {
LOGGER.debug("Handling public chat message [{0}]", [message.message]);
LOGGER.debug("onMessageFromServer2x - " + JSON.stringify(message));
var msg:ChatMessageVO = processIncomingChatMessage(message.body.message);
var publicChat: ChatConversation = LiveMeeting.inst().chats.getChatConversation(ChatModel.PUBLIC_CHAT_USERID);
publicChat.newChatMessage(msg);
LOGGER.debug("Handling public chat message [{0}]", [publicChat.getId()]);
var pcEvent:PublicChatMessageEvent = new PublicChatMessageEvent(PublicChatMessageEvent.PUBLIC_CHAT_MESSAGE_EVENT);
pcEvent.message = msg;
dispatcher.dispatchEvent(pcEvent);
publicChat.newChatMessage(msg);
LOGGER.debug("Num messages [{0}]", [publicChat.messages.length]);
var pcCoreEvent:CoreEvent = new CoreEvent(EventConstants.NEW_PUBLIC_CHAT);
pcCoreEvent.message = message;

View File

@ -48,12 +48,10 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
<fx:Script>
<![CDATA[
import com.asfusion.mate.events.Dispatcher;
import flash.events.TextEvent;
import com.asfusion.mate.events.Dispatcher;
import flash.events.TextEvent;
import mx.binding.utils.BindingUtils;
import mx.collections.ArrayCollection;
import org.as3commons.lang.StringUtils;
import org.as3commons.logging.api.ILogger;
import org.as3commons.logging.api.getClassLogger;
@ -100,7 +98,7 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
private var lastTime:String = "";
[Bindable]
private var chatMessages:ChatConversation;
private var chatMessages: ArrayCollection = new ArrayCollection();
private var lastCount:Number = 0;
private var scrollTimer:Timer;
@ -125,8 +123,7 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
private var ctrlPressed:Boolean = false;
private function onCreationComplete():void {
chatMessages = LiveMeeting.inst().chats.getChatConversation(id);
chatOptions = Options.getOptions(ChatOptions) as ChatOptions;
bindToHeightToDetermineHeightOfMessageList();
@ -253,7 +250,10 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
private function refreshChat(e:BBBEvent):void {
if (e.payload.type == "BIGBLUEBUTTON_CONNECTION") {
if (publicChat) chatMessages = LiveMeeting.inst().chats.getChatConversation("PUBLIC_CHAT");
if (publicChat) {
var myChat: ChatConversation = LiveMeeting.inst().chats.getChatConversation(id);
chatMessages = myChat.messages;
}
}
}
@ -278,7 +278,8 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
msg.toUsername = SPACE;
msg.message = "<b><i>"+ResourceUtil.getInstance().getString('bbb.chat.private.userLeft')+"</b></i>";
chatMessages.newChatMessage(msg);
var myChat: ChatConversation = LiveMeeting.inst().chats.getChatConversation(id);
myChat.newChatMessage(msg);
}
private function displayUserHasJoinedMessage():void {
@ -292,7 +293,8 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
msg.toUsername = SPACE;
msg.message = "<b><i>"+ResourceUtil.getInstance().getString('bbb.chat.private.userJoined')+"</b></i>";
chatMessages.newChatMessage(msg);
var myChat: ChatConversation = LiveMeeting.inst().chats.getChatConversation(id);
myChat.newChatMessage(msg);
}
public function focusToTextMessageArea():void {
@ -302,14 +304,25 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
private function handlePublicChatMessageEvent(event:PublicChatMessageEvent):void {
if (publicChat) {
LOGGER.debug("GOT PUBLIC CHAT for id=" + id);
// chatMessages.newChatMessage(event.message);
var chat: ChatConversation = LiveMeeting.inst().chats.getChatConversation(id);
LOGGER.debug("FOUND PUBLIC CHAT for id=" + chat.getId());
LOGGER.debug("NUM CHAT MESSAGES = " + chat.messages.length);
chatMessages = chat.messages;
scrollToEndOfMessage();
}
}
private function handleRecievedChatHistoryEvent(event:ChatHistoryEvent):void {
if (publicChat && event.history != null) {
if (publicChat) {
// chatMessages.processChatHistory(event.history);
LOGGER.debug("GOT PUBLIC CHAT HISTORY for id=" + id);
var chat: ChatConversation = LiveMeeting.inst().chats.getChatConversation(id);
LOGGER.debug("FOUND PUBLIC CHAT HISTORY for id=" + chat.getId());
LOGGER.debug("NUM CHAT HISTORY MESSAGES = " + chat.messages.length);
chatMessages = chat.messages;
scrollToEndOfMessage();
}
}
@ -348,7 +361,8 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
msg.toUsername = SPACE;
msg.message = "<b><i>"+ResourceUtil.getInstance().getString('bbb.chat.private.closeMessage', [keyCombo])+"</b></i>";
chatMessages.newChatMessage(msg);
var myChat: ChatConversation = LiveMeeting.inst().chats.getChatConversation(id);
myChat.newChatMessage(msg);
}
public function scrollToEndOfMessage():void {
@ -394,11 +408,12 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
}
private function copyAllText():void{
System.setClipboard(chatMessages.getAllMessageAsString());
var myChat: ChatConversation = LiveMeeting.inst().chats.getChatConversation(id);
System.setClipboard(myChat.getAllMessageAsString());
}
public function getChatMessages():ChatConversation {
return chatMessages;
public function getChatId():String {
return id;
}
private function addContextMenuItems():void {
@ -414,7 +429,8 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
private function menuItemHandler(e:ContextMenuEvent):void{
if (e.target.caption == ResourceUtil.getInstance().getString("bbb.chat.contextmenu.copyalltext")){
System.setClipboard(chatMessages.getAllMessageAsString());
var myChat: ChatConversation = LiveMeeting.inst().chats.getChatConversation(id);
System.setClipboard(myChat.getAllMessageAsString());
}
}
@ -598,7 +614,8 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
private function handleClearPublicChatBoxMessages(event:ClearPublicChatEvent):void {
if(publicChat){
chatMessages.clearPublicChat();
var myChat: ChatConversation = LiveMeeting.inst().chats.getChatConversation(id);
myChat.clearPublicChat();
invalidateDisplayList();
validateNow();
}
@ -632,7 +649,7 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
<mx:Canvas id="chatMessagesCanvas" width="100%" height="{chatListHeight}" horizontalScrollPolicy="off" verticalScrollPolicy="off" >
<chat:AdvancedList width="100%" height="{chatListHeight}" id="chatMessagesList" selectable="true" variableRowHeight="true"
itemRenderer="org.bigbluebutton.modules.chat.views.ChatMessageRenderer" verticalScrollPolicy="on" horizontalScrollPolicy="off" wordWrap="true"
dataProvider="{chatMessages.messages}"
dataProvider="{chatMessages}"
styleName="chatMessageListStyle"
accessibilityName="{ResourceUtil.getInstance().getString('bbb.chat.messageList')}" />
<!--chat:ChatToolbar id="chatToolbar" /-->

View File

@ -135,7 +135,7 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
saveEvent.filename = chatBox.chatWithUsername;
}
saveEvent.chatMessages = chatBox.getChatMessages();
saveEvent.chatId = chatBox.id;
globalDispatcher.dispatchEvent(saveEvent);
}
@ -143,7 +143,7 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
var chatBox:ChatBox = getPublicChatBox();
var copyEvent:ChatCopyEvent = new ChatCopyEvent(ChatCopyEvent.COPY_CHAT_EVENT);
copyEvent.chatMessages = chatBox.getChatMessages();
copyEvent.chatId = chatBox.getChatId();
globalDispatcher.dispatchEvent(copyEvent);
}
@ -172,7 +172,7 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
private function handlePublicChatMessageEvent(event:PublicChatMessageEvent):void {
notifyUserOfNewMessage(ChatModel.PUBLIC_CHAT_USERID);
if (!UsersUtil.isMe(event.message.fromUserId)) {
if (!UsersUtil.isMe(event.senderId)) {
publicNotification();
}
}

View File

@ -6,8 +6,11 @@ package org.bigbluebutton.modules.polling.service
import org.as3commons.logging.api.ILogger;
import org.as3commons.logging.api.getClassLogger;
import org.bigbluebutton.core.model.LiveMeeting;
import org.bigbluebutton.modules.chat.ChatConstants;
import org.bigbluebutton.modules.chat.events.PublicChatMessageEvent;
import org.bigbluebutton.modules.chat.model.ChatConversation;
import org.bigbluebutton.modules.chat.model.ChatModel;
import org.bigbluebutton.modules.chat.vo.ChatMessageVO;
import org.bigbluebutton.modules.polling.events.PollShowResultEvent;
import org.bigbluebutton.modules.polling.events.PollStartedEvent;
@ -93,9 +96,9 @@ package org.bigbluebutton.modules.polling.service
pollResultMessage.toUsername = ResourceUtil.getInstance().getString("bbb.chat.chatMessage.systemMessage");
pollResultMessage.message = accessibleAnswers;
var pollResultMessageEvent:PublicChatMessageEvent = new PublicChatMessageEvent(PublicChatMessageEvent.PUBLIC_CHAT_MESSAGE_EVENT);
pollResultMessageEvent.message = pollResultMessage;
dispatcher.dispatchEvent(pollResultMessageEvent);
var pubChat: ChatConversation = LiveMeeting.inst().chats.getChatConversation(ChatModel.PUBLIC_CHAT_USERID);
pubChat.newChatMessage(pollResultMessage);
}
}