- handle group chat created msg on client

This commit is contained in:
Richard Alam 2017-09-20 11:59:33 -07:00
parent ff23e66220
commit e651785a4e
6 changed files with 125 additions and 22 deletions

View File

@ -7,16 +7,27 @@ import org.bigbluebutton.core.models.GroupChat
import org.bigbluebutton.core.running.LiveMeeting
trait CreateGroupChatReqMsgHdlr {
this: GroupChatHdlrs =>
def handle(msg: CreateGroupChatReqMsg, state: MeetingState2x,
liveMeeting: LiveMeeting, bus: MessageBus): MeetingState2x = {
log.debug("RECEIVED CREATE CHAT REQ MESSAGE")
val newState = for {
createdBy <- GroupChatApp.findGroupChatUser(msg.header.userId, liveMeeting.users2x)
msgs = msg.body.msg.map(m => GroupChatApp.toGroupChatMessage(createdBy, m))
gc = GroupChatApp.createGroupChat(msg.body.name, msg.body.access, createdBy, msg.body.users, msgs)
} yield {
val msgs = msg.body.msg.map(m => GroupChatApp.toGroupChatMessage(createdBy, m))
val users = {
if (msg.body.access == GroupChatAccess.PRIVATE) {
val cu = msg.body.users.toSet + msg.body.requesterId
cu.flatMap(u => GroupChatApp.findGroupChatUser(u, liveMeeting.users2x)).toVector
} else {
Vector.empty
}
}
log.debug("CREATING CHAT ")
val gc = GroupChatApp.createGroupChat(msg.body.name, msg.body.access, createdBy, users, msgs)
sendMessages(msg, gc, liveMeeting, bus)
val groupChats = state.groupChats.add(gc)
@ -40,24 +51,25 @@ trait CreateGroupChatReqMsgHdlr {
def makeBody(chatId: String, name: String,
access: String, correlationId: String,
createdBy: GroupChatUser, users: Vector[GroupChatUser],
msgs: Vector[GroupChatMsgToUser]): CreateGroupChatRespMsgBody = {
CreateGroupChatRespMsgBody(correlationId, chatId, createdBy,
msgs: Vector[GroupChatMsgToUser]): GroupChatCreatedEvtMsgBody = {
GroupChatCreatedEvtMsgBody(correlationId, chatId, createdBy,
name, access, users, msgs)
}
val meetingId = liveMeeting.props.meetingProp.intId
val correlationId = msg.body.correlationId
val users = gc.users.values.toVector
val users = gc.users
val msgs = gc.msgs.map(m => GroupChatApp.toMessageToUser(m))
if (gc.access == GroupChatAccess.PRIVATE) {
def sendDirectMessage(userId: String): Unit = {
val envelope = makeEnvelope(MessageTypes.DIRECT, CreateGroupChatRespMsg.NAME, meetingId, userId)
val header = makeHeader(CreateGroupChatRespMsg.NAME, meetingId, userId)
val envelope = makeEnvelope(MessageTypes.DIRECT, GroupChatCreatedEvtMsg.NAME, meetingId, userId)
val header = makeHeader(GroupChatCreatedEvtMsg.NAME, meetingId, userId)
val body = makeBody(gc.id, gc.name, gc.access, correlationId, gc.createdBy, users, msgs)
val event = CreateGroupChatRespMsg(header, body)
BbbCommonEnvCoreMsg(envelope, event)
val event = GroupChatCreatedEvtMsg(header, body)
val outEvent = BbbCommonEnvCoreMsg(envelope, event)
bus.outGW.send(outEvent)
}
users.foreach(u => sendDirectMessage(u.id))
@ -65,12 +77,12 @@ trait CreateGroupChatReqMsgHdlr {
} else {
val meetingId = liveMeeting.props.meetingProp.intId
val userId = msg.body.requesterId
val envelope = makeEnvelope(MessageTypes.BROADCAST_TO_MEETING, CreateGroupChatRespMsg.NAME,
val envelope = makeEnvelope(MessageTypes.BROADCAST_TO_MEETING, GroupChatCreatedEvtMsg.NAME,
meetingId, userId)
val header = makeHeader(CreateGroupChatRespMsg.NAME, meetingId, userId)
val header = makeHeader(GroupChatCreatedEvtMsg.NAME, meetingId, userId)
val body = makeBody(gc.id, gc.name, gc.access, correlationId, gc.createdBy, users, msgs)
val event = CreateGroupChatRespMsg(header, body)
val event = GroupChatCreatedEvtMsg(header, body)
val outEvent = BbbCommonEnvCoreMsg(envelope, event)
bus.outGW.send(outEvent)

View File

@ -7,8 +7,7 @@ object GroupChatFactory {
def genId(): String = System.currentTimeMillis() + "-" + RandomStringGenerator.randomAlphanumericString(8)
def create(id: String, name: String, access: String, createdBy: GroupChatUser,
users: Vector[GroupChatUser], msgs: Vector[GroupChatMessage]): GroupChat = {
val cu = users.map(u => u.id -> u).toMap
new GroupChat(id, name, access, createdBy, cu, msgs)
new GroupChat(id, name, access, createdBy, users, msgs)
}
}
@ -23,10 +22,10 @@ case class GroupChats(chats: collection.immutable.Map[String, GroupChat]) {
}
case class GroupChat(id: String, name: String, access: String, createdBy: GroupChatUser,
users: collection.immutable.Map[String, GroupChatUser],
users: Vector[GroupChatUser],
msgs: Vector[GroupChatMessage]) {
def add(user: GroupChatUser): GroupChat = copy(users = users + (user.id -> user))
def remove(userId: String): GroupChat = copy(users = users - userId)
def add(user: GroupChatUser): GroupChat = copy(users = users :+ user)
def remove(userId: String): GroupChat = copy(users = users.filterNot(u => u.id == userId))
def add(msg: GroupChatMessage): GroupChat = copy(msgs = msgs :+ msg)
def delete(msgId: String): GroupChat = copy(msgs = msgs.filterNot(m => m.id == msgId))
def update(msg: GroupChatMessage): GroupChat = add(msg)

View File

@ -87,6 +87,8 @@ class AnalyticsActor extends Actor with ActorLogging {
case m: GroupChatMessageBroadcastEvtMsg => logMessage(msg)
case m: GetGroupChatMsgsReqMsg => logMessage(msg)
case m: GetGroupChatMsgsRespMsg => logMessage(msg)
case m: CreateGroupChatReqMsg => logMessage(msg)
case m: GroupChatCreatedEvtMsg => logMessage(msg)
case m: ClientToServerLatencyTracerMsg => traceMessage(msg)
case m: ServerToClientLatencyTracerMsg => traceMessage(msg)

View File

@ -33,11 +33,11 @@ object CreateGroupChatReqMsg { val NAME = "CreateGroupChatReqMsg"}
case class CreateGroupChatReqMsg(header: BbbClientMsgHeader, body: CreateGroupChatReqMsgBody) extends StandardMsg
case class CreateGroupChatReqMsgBody(correlationId: String, requesterId: String,
name: String, access: String,
users: Vector[GroupChatUser], msg: Vector[GroupChatMsgFromUser])
users: Vector[String], msg: Vector[GroupChatMsgFromUser])
object CreateGroupChatRespMsg { val NAME = "CreateGroupChatRespMsg"}
case class CreateGroupChatRespMsg(header: BbbClientMsgHeader, body: CreateGroupChatRespMsgBody) extends BbbCoreMsg
case class CreateGroupChatRespMsgBody(correlationId: String, chatId: String, createdBy: GroupChatUser,
object GroupChatCreatedEvtMsg { val NAME = "GroupChatCreatedEvtMsg"}
case class GroupChatCreatedEvtMsg(header: BbbClientMsgHeader, body: GroupChatCreatedEvtMsgBody) extends BbbCoreMsg
case class GroupChatCreatedEvtMsgBody(correlationId: String, chatId: String, createdBy: GroupChatUser,
name: String, access: String,
users: Vector[GroupChatUser], msg: Vector[GroupChatMsgToUser])
@ -62,7 +62,7 @@ case class GroupChatAddUserReqMsgBody(requesterId: String, chats: Vector[String]
object GroupChatUserAddedEvtMsg { val NAME = "GroupChatUserAddedEvtMsg"}
case class GroupChatUserAddedEvtMsg(header: BbbClientMsgHeader, body: GroupChatUserAddedEvtMsgBody) extends BbbCoreMsg
case class GroupChatUserAddedEvtMsgBody(requesterId: String, chats: Vector[String])
case class GroupChatUserAddedEvtMsgBody(requesterId: String, chats: Vector[GroupChatUser])
object GroupChatRemoveUserReqMsg { val NAME = "GroupChatRemoveUserReqMsg"}
case class GroupChatRemoveUserReqMsg(header: BbbClientMsgHeader, body: GroupChatRemoveUserReqMsgBody) extends StandardMsg

View File

@ -0,0 +1,51 @@
package org.bigbluebutton.modules.chat.model
{
import mx.collections.ArrayCollection;
import org.bigbluebutton.modules.chat.vo.GroupChatUser;
public class GroupChat
{
private var _id: String;
private var _name: String;
private var _access: String;
private var _createdBy: GroupChatUser;
private var _users: ArrayCollection;
private var _messages: ArrayCollection;
public function GroupChat(id: String, name: String, access: String,
createdBy: GroupChatUser, users: ArrayCollection, msg: ArrayCollection)
{
_id = id;
_name = name;
_access = access;
_createdBy = createdBy;
_users = users;
_messages = msg;
}
public function get id():String {
return _id;
}
public function get name(): String {
return _name;
}
public function get access(): String {
return _access;
}
public function get createdBy():GroupChatUser {
return _createdBy;
}
public function get users():ArrayCollection {
return new ArrayCollection(_users.toArray());
}
public function get messages():ArrayCollection {
return new ArrayCollection(_messages.toArray());
}
}
}

View File

@ -20,8 +20,11 @@ package org.bigbluebutton.modules.chat.services
{
import flash.events.IEventDispatcher;
import mx.collections.ArrayCollection;
import org.as3commons.logging.api.ILogger;
import org.as3commons.logging.api.getClassLogger;
import org.as3commons.logging.util.objectify;
import org.bigbluebutton.core.BBB;
import org.bigbluebutton.core.EventConstants;
import org.bigbluebutton.core.events.CoreEvent;
@ -31,7 +34,9 @@ package org.bigbluebutton.modules.chat.services
import org.bigbluebutton.modules.chat.events.ClearPublicChatEvent;
import org.bigbluebutton.modules.chat.model.ChatConversation;
import org.bigbluebutton.modules.chat.model.ChatModel;
import org.bigbluebutton.modules.chat.model.GroupChat;
import org.bigbluebutton.modules.chat.vo.ChatMessageVO;
import org.bigbluebutton.modules.chat.vo.GroupChatUser;
public class MessageReceiver implements IMessageListener
{
@ -63,11 +68,45 @@ package org.bigbluebutton.modules.chat.services
case "GroupChatMessageBroadcastEvtMsg":
handleGroupChatMessageBroadcastEvtMsg(message);
break;
case "GroupChatCreatedEvtMsg":
handleGroupChatCreatedEvtMsg(message);
break;
default:
// LogUtil.warn("Cannot handle message [" + messageName + "]");
}
}
private function handleGroupChatCreatedEvtMsg(msg:Object):void {
var body: Object = msg.body as Object;
var corrId: String = body.correlationId as String;
var chatId: String = body.chatId as String;
var createdBy: GroupChatUser = new GroupChatUser(body.createdBy.id, body.createdBy.name);
var name: String = body.name as String;
var access: String = body.access as String;
var users: Array = body.users as Array;
var msgs: Array = body.msg as Array;
var chatUsers:Array = new Array();
if (users.length > 0) {
for (var i:int = 0; i < users.length; i++) {
var u: Object = users[i] as Object;
chatUsers.push(new GroupChatUser(u.id, u.name));
}
}
var chatMsgs: Array = new Array();
if (msgs.length > 0) {
for (var j: int = 0; j < msgs.length; j++) {
var m: Object = msgs[i] as Object;
chatMsgs.push(processNewChatMessage(m));
}
}
var groupChat: GroupChat = new GroupChat(chatId, name, access,
createdBy, new ArrayCollection(chatUsers), new ArrayCollection(chatMsgs));
}
private function handleGetChatHistoryRespMsg(message:Object):void {
LOGGER.debug("Handling chat history message [{0}]", [message.body.msgs]);
var rawMessages:Array = message.body.msgs as Array;