mirror of https://github.com/zlatinb/muwire
wip on joining and leaving rooms
parent
29e499fe9d
commit
18d19ca75e
|
@ -195,7 +195,7 @@ class ChatServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processJoin(String room, ChatMessageEvent e) {
|
private void processJoin(String room, ChatMessageEvent e) {
|
||||||
joinRoom(room, e.sender)
|
joinRoom(e.sender, room)
|
||||||
rooms[room].each {
|
rooms[room].each {
|
||||||
if (it == e.sender)
|
if (it == e.sender)
|
||||||
return
|
return
|
||||||
|
|
|
@ -29,6 +29,8 @@ class ChatRoomController {
|
||||||
@MVCMember @Nonnull
|
@MVCMember @Nonnull
|
||||||
ChatRoomView view
|
ChatRoomView view
|
||||||
|
|
||||||
|
boolean leftRoom
|
||||||
|
|
||||||
@ControllerAction
|
@ControllerAction
|
||||||
void say() {
|
void say() {
|
||||||
String words = view.sayField.text
|
String words = view.sayField.text
|
||||||
|
@ -45,23 +47,58 @@ class ChatRoomController {
|
||||||
UUID uuid = UUID.randomUUID()
|
UUID uuid = UUID.randomUUID()
|
||||||
String room = model.console ? ChatServer.CONSOLE : model.room
|
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,
|
def event = new ChatMessageEvent(uuid : uuid,
|
||||||
payload : command.source,
|
payload : command.source,
|
||||||
sender : model.core.me,
|
sender : model.core.me,
|
||||||
host : mvcGroup.parentGroup.model.host,
|
host : model.host,
|
||||||
room : room,
|
room : room,
|
||||||
chatTime : now,
|
chatTime : now,
|
||||||
sig : sig)
|
sig : sig)
|
||||||
|
|
||||||
model.core.eventBus.publish(event)
|
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
|
String toShow = DataHelper.formatTime(now) + " <" + model.core.me.getHumanReadableName() + "> "+command.payload
|
||||||
|
|
||||||
view.roomTextArea.append(toShow)
|
view.roomTextArea.append(toShow)
|
||||||
view.roomTextArea.append('\n')
|
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) {
|
void handleChatMessage(ChatMessageEvent e) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.muwire.gui
|
package com.muwire.gui
|
||||||
|
|
||||||
import com.muwire.core.Core
|
import com.muwire.core.Core
|
||||||
|
import com.muwire.core.Persona
|
||||||
|
|
||||||
import griffon.core.artifact.GriffonModel
|
import griffon.core.artifact.GriffonModel
|
||||||
import griffon.transform.Observable
|
import griffon.transform.Observable
|
||||||
|
@ -9,6 +10,7 @@ import griffon.metadata.ArtifactProviderFor
|
||||||
@ArtifactProviderFor(GriffonModel)
|
@ArtifactProviderFor(GriffonModel)
|
||||||
class ChatRoomModel {
|
class ChatRoomModel {
|
||||||
Core core
|
Core core
|
||||||
|
Persona host
|
||||||
String tabName
|
String tabName
|
||||||
String room
|
String room
|
||||||
boolean console
|
boolean console
|
||||||
|
|
|
@ -44,7 +44,8 @@ class ChatRoomView {
|
||||||
pane = builder.panel {
|
pane = builder.panel {
|
||||||
borderLayout()
|
borderLayout()
|
||||||
panel(constraints : BorderLayout.CENTER) {
|
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 {
|
panel {
|
||||||
table(autoCreateRowSorter : true, rowHeight : rowHeight) {
|
table(autoCreateRowSorter : true, rowHeight : rowHeight) {
|
||||||
tableModel(list : model.members) {
|
tableModel(list : model.members) {
|
||||||
|
@ -90,6 +91,7 @@ class ChatRoomView {
|
||||||
def closeTab = {
|
def closeTab = {
|
||||||
int index = parent.indexOfComponent(pane)
|
int index = parent.indexOfComponent(pane)
|
||||||
parent.removeTabAt(index)
|
parent.removeTabAt(index)
|
||||||
|
controller.leaveRoom()
|
||||||
mvcGroup.destroy()
|
mvcGroup.destroy()
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -60,6 +60,7 @@ class ChatServerView {
|
||||||
params['tabName'] = model.host.getHumanReadableName() + "-chat-rooms"
|
params['tabName'] = model.host.getHumanReadableName() + "-chat-rooms"
|
||||||
params['room'] = 'Console'
|
params['room'] = 'Console'
|
||||||
params['console'] = true
|
params['console'] = true
|
||||||
|
params['host'] = model.host
|
||||||
mvcGroup.createMVCGroup("chat-room",ChatServer.CONSOLE, params)
|
mvcGroup.createMVCGroup("chat-room",ChatServer.CONSOLE, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue