wip on joining and leaving rooms
This commit is contained in:
@ -195,7 +195,7 @@ class ChatServer {
|
||||
}
|
||||
|
||||
private void processJoin(String room, ChatMessageEvent e) {
|
||||
joinRoom(room, e.sender)
|
||||
joinRoom(e.sender, room)
|
||||
rooms[room].each {
|
||||
if (it == e.sender)
|
||||
return
|
||||
|
@ -29,6 +29,8 @@ class ChatRoomController {
|
||||
@MVCMember @Nonnull
|
||||
ChatRoomView view
|
||||
|
||||
boolean leftRoom
|
||||
|
||||
@ControllerAction
|
||||
void say() {
|
||||
String words = view.sayField.text
|
||||
@ -45,23 +47,58 @@ class ChatRoomController {
|
||||
UUID uuid = UUID.randomUUID()
|
||||
String room = model.console ? ChatServer.CONSOLE : model.room
|
||||
|
||||
byte [] sig = ChatConnection.sign(uuid, now, room, command.source, model.core.me, mvcGroup.parentGroup.model.host, model.core.spk)
|
||||
byte [] sig = ChatConnection.sign(uuid, now, room, command.source, model.core.me, model.host, model.core.spk)
|
||||
|
||||
def event = new ChatMessageEvent(uuid : uuid,
|
||||
payload : command.source,
|
||||
sender : model.core.me,
|
||||
host : mvcGroup.parentGroup.model.host,
|
||||
host : model.host,
|
||||
room : room,
|
||||
chatTime : now,
|
||||
sig : sig)
|
||||
|
||||
model.core.eventBus.publish(event)
|
||||
if (command.payload.length() > 0) {
|
||||
if (command.action == ChatAction.SAY && command.payload.length() > 0) {
|
||||
String toShow = DataHelper.formatTime(now) + " <" + model.core.me.getHumanReadableName() + "> "+command.payload
|
||||
|
||||
view.roomTextArea.append(toShow)
|
||||
view.roomTextArea.append('\n')
|
||||
}
|
||||
|
||||
if (command.action == ChatAction.JOIN) {
|
||||
String newRoom = command.payload
|
||||
if (mvcGroup.parentGroup.childrenGroups.containsKey(newRoom))
|
||||
return
|
||||
def params = [:]
|
||||
params['core'] = model.core
|
||||
params['tabName'] = model.host.getHumanReadableName() + "-chat-rooms"
|
||||
params['room'] = newRoom
|
||||
params['console'] = false
|
||||
params['host'] = model.host
|
||||
|
||||
mvcGroup.parentGroup.createMVCGroup("chat-room", newRoom, params)
|
||||
}
|
||||
if (command.action == ChatAction.LEAVE && !model.console) {
|
||||
leftRoom = true
|
||||
view.closeTab.call()
|
||||
}
|
||||
}
|
||||
|
||||
void leaveRoom() {
|
||||
if (leftRoom)
|
||||
return
|
||||
leftRoom = true
|
||||
long now = System.currentTimeMillis()
|
||||
UUID uuid = UUID.randomUUID()
|
||||
byte [] sig = ChatConnection.sign(uuid, now, model.room, "/LEAVE", model.core.me, model.host, model.core.spk)
|
||||
def event = new ChatMessageEvent(uuid : uuid,
|
||||
payload : "/LEAVE",
|
||||
sender : model.core.me,
|
||||
host : model.host,
|
||||
room : model.room,
|
||||
chatTime : now,
|
||||
sig : sig)
|
||||
model.core.eventBus.publish(event)
|
||||
}
|
||||
|
||||
void handleChatMessage(ChatMessageEvent e) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.muwire.gui
|
||||
|
||||
import com.muwire.core.Core
|
||||
import com.muwire.core.Persona
|
||||
|
||||
import griffon.core.artifact.GriffonModel
|
||||
import griffon.transform.Observable
|
||||
@ -9,6 +10,7 @@ import griffon.metadata.ArtifactProviderFor
|
||||
@ArtifactProviderFor(GriffonModel)
|
||||
class ChatRoomModel {
|
||||
Core core
|
||||
Persona host
|
||||
String tabName
|
||||
String room
|
||||
boolean console
|
||||
|
@ -44,7 +44,8 @@ class ChatRoomView {
|
||||
pane = builder.panel {
|
||||
borderLayout()
|
||||
panel(constraints : BorderLayout.CENTER) {
|
||||
splitPane(orientation : JSplitPane.HORIZONTAL_SPLIT, continuousLayout : true, dividerLocation : 200)
|
||||
gridLayout(rows : 1, cols : 1)
|
||||
splitPane(orientation : JSplitPane.HORIZONTAL_SPLIT, continuousLayout : true, dividerLocation : 100)
|
||||
panel {
|
||||
table(autoCreateRowSorter : true, rowHeight : rowHeight) {
|
||||
tableModel(list : model.members) {
|
||||
@ -90,6 +91,7 @@ class ChatRoomView {
|
||||
def closeTab = {
|
||||
int index = parent.indexOfComponent(pane)
|
||||
parent.removeTabAt(index)
|
||||
controller.leaveRoom()
|
||||
mvcGroup.destroy()
|
||||
}
|
||||
}
|
@ -60,6 +60,7 @@ class ChatServerView {
|
||||
params['tabName'] = model.host.getHumanReadableName() + "-chat-rooms"
|
||||
params['room'] = 'Console'
|
||||
params['console'] = true
|
||||
params['host'] = model.host
|
||||
mvcGroup.createMVCGroup("chat-room",ChatServer.CONSOLE, params)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user