Merge pull request #2770 from riadvice/chat-message-limit

Add a maximum allowed length to chat message
This commit is contained in:
Richard Alam 2015-09-16 15:04:26 -04:00
commit c13e17a7d4
6 changed files with 106 additions and 36 deletions

View File

@ -21,16 +21,18 @@ package org.bigbluebutton.red5.service;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.bigbluebutton.red5.BigBlueButtonSession;
import org.bigbluebutton.red5.Constants;
import org.bigbluebutton.red5.pubsub.MessagePublisher;
import org.red5.logging.Red5LoggerFactory; import org.red5.server.api.Red5;
import org.red5.logging.Red5LoggerFactory;
import org.red5.server.api.Red5;
import org.slf4j.Logger;
public class ChatService {
private static Logger log = Red5LoggerFactory.getLogger( ChatService.class, "bigbluebutton" );
private MessagePublisher red5BBBInGw;
private int maxMessageLength;
public void sendPublicChatHistory() {
String meetingID = Red5.getConnectionLocal().getScope().getName();
@ -70,14 +72,24 @@ public class ChatService {
String meetingID = Red5.getConnectionLocal().getScope().getName();
String requesterID = getBbbSession().getInternalUserID();
red5BBBInGw.sendPublicMessage(meetingID, requesterID, message);
// The message is being ignored in the red5 application to avoid copying it to any another application which that may cause a memory issue
if (chatText.length() <= maxMessageLength) {
red5BBBInGw.sendPublicMessage(meetingID, requesterID, message);
}
else {
log.warn("sendPublicMessage maximum allowed message length exceeded (length: [" + chatText.length() + "], message: [" + chatText + "])");
}
}
public void setRed5Publisher(MessagePublisher inGW) {
red5BBBInGw = inGW;
}
public void setMaxMessageLength(int maxLength) {
maxMessageLength = maxLength;
}
public void sendPrivateMessage(Map<String, Object> msg){
String chatType = msg.get(ChatKeyUtil.CHAT_TYPE).toString();
@ -103,7 +115,13 @@ public class ChatService {
String meetingID = Red5.getConnectionLocal().getScope().getName();
String requesterID = getBbbSession().getInternalUserID();
red5BBBInGw.sendPrivateMessage(meetingID, requesterID, message);
// The message is being ignored in the red5 application to avoid copying it to any another application which that may cause a memory issue
if (chatText.length() <= maxMessageLength) {
red5BBBInGw.sendPrivateMessage(meetingID, requesterID, message);
}
else {
log.warn("sendPrivateMessage maximum allowed message length exceeded (length: [" + chatText.length() + "], message: [" + chatText + "])");
}
}
}

View File

@ -69,6 +69,7 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
<bean id="chat.service" class="org.bigbluebutton.red5.service.ChatService">
<property name="red5Publisher"> <ref bean="red5Publisher"/></property>
<property name="maxMessageLength" value="1024"/>
</bean>
<bean id="participants.service" class="org.bigbluebutton.red5.service.ParticipantsService">

View File

@ -249,6 +249,7 @@ bbb.chat.maximizeRestoreBtn.accessibilityName = Maximize the Chat Window
bbb.chat.closeBtn.accessibilityName = Close the Chat Window
bbb.chat.chatTabs.accessibleNotice = New messages in this tab.
bbb.chat.chatMessage.systemMessage = System
bbb.chat.chatMessage.tooLong = The message is {0} character(s) too long
bbb.publishVideo.changeCameraBtn.labelText = Change Webcam
bbb.publishVideo.changeCameraBtn.toolTip = Open the change webcam dialog box
bbb.publishVideo.cmbResolution.tooltip = Select a webcam resolution

View File

@ -30,6 +30,7 @@
position="top-right"
baseTabIndex="701"
colorPickerIsVisible="false"
maxMessageLength="1024"
/>
<module name="UsersModule" url="http://HOST/client/UsersModule.swf?v=VERSION"

View File

@ -1,13 +1,13 @@
/**
* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
*
*
* Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
@ -16,12 +16,12 @@
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*
*/
package org.bigbluebutton.modules.chat.model
{
package org.bigbluebutton.modules.chat.model {
import org.bigbluebutton.core.BBB;
public class ChatOptions
{
public class ChatOptions {
[Bindable]
public var privateEnabled:Boolean = true;
@ -31,13 +31,17 @@ package org.bigbluebutton.modules.chat.model
[Bindable]
public var position:String = "top-right";
[Bindable] public var baseTabIndex:int;
[Bindable]
public var baseTabIndex:int;
[Bindable]
public var colorPickerIsVisible:Boolean = false;
[Bindable]
public var maxMessageLength:uint;
public function ChatOptions() {
var cxml:XML = BBB.getConfigForModule("ChatModule");
var cxml:XML = BBB.getConfigForModule("ChatModule");
if (cxml != null) {
if (cxml.@privateEnabled != undefined) {
privateEnabled = (cxml.@privateEnabled.toString().toUpperCase() == "TRUE") ? true : false;
@ -50,18 +54,20 @@ package org.bigbluebutton.modules.chat.model
}
if (cxml.@baseTabIndex != undefined) {
baseTabIndex = cxml.@baseTabIndex;
}
else{
} else {
baseTabIndex = 701;
}
if(cxml.@colorPickerIsVisible != undefined) {
if (cxml.@colorPickerIsVisible != undefined) {
colorPickerIsVisible = (cxml.@colorPickerIsVisible.toString().toUpperCase() == "TRUE") ? true : false;
}
}
if (cxml.@maxMessageLength != undefined) {
maxMessageLength = parseInt(cxml.@maxMessageLength.toString());
}
}
}
public function getBaseIndex():int{
public function getBaseIndex():int {
return baseTabIndex;
}
}
}
}

View File

@ -69,7 +69,6 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
<mx:Script>
<![CDATA[
import com.adobe.utils.StringUtil;
import com.asfusion.mate.events.Dispatcher;
import flash.accessibility.AccessibilityProperties;
@ -77,6 +76,7 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
import mx.binding.utils.BindingUtils;
import org.as3commons.lang.StringUtils;
import org.as3commons.logging.api.ILogger;
import org.as3commons.logging.api.getClassLogger;
import org.bigbluebutton.core.UsersUtil;
@ -584,7 +584,7 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
var answers:Array = new Array();
for (var i:int = 0; i < tmpAnswers.length; i++) {
var t:String = tmpAnswers[i] as String;
answers.push(StringUtil.trim(t));
answers.push(StringUtils.trim(t));
}
sendStartCustomPollEvent(answers);
} else {
@ -634,7 +634,7 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
}
private function handleTextInput(e:TextEvent):void {
if ((e.text.length == 1) && (e.text.charCodeAt(0) == 10) /*ENTER-KEY*/) {
if ((e.text.length == 1) && (e.text.charCodeAt(0) == 10) /*ENTER-KEY*/ && messageCanBeSent) {
sendMessages();
e.preventDefault();
}
@ -649,25 +649,50 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
private function sendMessages():void {
if(!sendBtn.enabled) {
txtMsgArea.text = StringUtil.trim(txtMsgArea.text);
txtMsgArea.text = StringUtils.trim(txtMsgArea.text);
return;
}
// Trim the message. This will trim the '/n' char so we don't send a message when the
// user just hits the enter key
var msgToSend:String = StringUtil.trim(txtMsgArea.text);
var msgToSend:String = StringUtils.trim(txtMsgArea.text);
if (msgToSend != ""){
if (publicChat) {
if (!StringUtils.isBlank(msgToSend)){
if (publicChat) {
sendPublicChatMessage(msgToSend);
} else{
} else {
sendPrivateChatMessage(msgToSend);
}
}
txtMsgArea.text = "";
txtMsgArea.validateNow();
txtMsgArea.setSelection(0, 0);
}
}
private function showMessageTooLong(messageLength : int):void {
msgTooLongLabel.text = ResourceUtil.getInstance().getString('bbb.chat.chatMessage.tooLong', [(messageLength - chatOptions.maxMessageLength).toString()]);
msgTooLongLabel.includeInLayout = msgTooLongLabel.visible = true;
if (chatCtrlBar.height != 80) {
chatCtrlBar.height = 80;
chatListHeight -= 20;
}
// The case where lock settings are set
if (txtMsgArea.enabled) {
sendBtn.enabled = false;
}
}
private function hideMessageTooLong():void {
msgTooLongLabel.includeInLayout = msgTooLongLabel.visible = false;
if (chatCtrlBar.height != 60) {
chatCtrlBar.height = 60;
chatListHeight += 20;
}
// The case where lock settings are set
if (txtMsgArea.enabled) {
sendBtn.enabled = true;
}
}
private function focusChatInput(e:ShortcutEvent):void{
txtMsgArea.setFocus();
@ -687,7 +712,21 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
txtMsgArea.enabled = sendBtn.enabled = !me.disableMyPrivateChat;
}
}
]]>
private function get messageCanBeSent() : Boolean {
return StringUtils.trim(txtMsgArea.text).length <= chatOptions.maxMessageLength;
}
protected function txtMsgAreaChangeHandler(event:Event):void
{
if (!messageCanBeSent) {
showMessageTooLong(StringUtils.trim(txtMsgArea.text).length);
}
else {
hideMessageTooLong();
}
}
]]>
</mx:Script>
@ -701,11 +740,15 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
</mx:HBox>
<mx:HBox id="chatCtrlBar" width="100%" height="60" styleName="chatControlBarStyle" verticalScrollPolicy="off"
paddingLeft="5" paddingRight="5">
<mx:TextArea id="txtMsgArea" width="100%" height="100%"
styleName="chatControlBarTextMsgStyle"
toolTip="{ResourceUtil.getInstance().getString('bbb.accessibility.chat.chatwindow.input')}"
accessibilityName="{ResourceUtil.getInstance().getString('bbb.chat.input.accessibilityName')}" />
paddingLeft="5" paddingRight="5">
<mx:VBox width="100%" height="100%">
<mx:TextArea id="txtMsgArea" width="100%" height="100%"
styleName="chatControlBarTextMsgStyle"
change="txtMsgAreaChangeHandler(event)"
toolTip="{ResourceUtil.getInstance().getString('bbb.accessibility.chat.chatwindow.input')}"
accessibilityName="{ResourceUtil.getInstance().getString('bbb.chat.input.accessibilityName')}" />
<mx:Label id="msgTooLongLabel" width="100%" height="100%" includeInLayout="false" visible="false"/>
</mx:VBox>
<mx:VBox verticalScrollPolicy="off" verticalAlign="middle" height="100%" >
<mx:Button label="{ResourceUtil.getInstance().getString('bbb.chat.sendBtn')}" id="sendBtn"
styleName="chatControlBarSendButtonStyle"