mirror of https://github.com/zlatinb/muwire
wip on hooking UI with core
parent
1fbb1e7932
commit
bfe0ab7867
|
@ -20,6 +20,7 @@ import groovy.util.logging.Log
|
|||
import net.i2p.crypto.DSAEngine
|
||||
import net.i2p.data.Base64
|
||||
import net.i2p.data.Signature
|
||||
import net.i2p.data.SigningPrivateKey
|
||||
|
||||
@Log
|
||||
class ChatConnection implements Closeable {
|
||||
|
@ -220,6 +221,23 @@ class ChatConnection implements Closeable {
|
|||
DSAEngine.getInstance().verifySignature(signature, signed, spk)
|
||||
}
|
||||
|
||||
public static byte[] sign(UUID uuid, long chatTime, String room, String words, Persona sender, Persona host, SigningPrivateKey spk) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream()
|
||||
DataOutputStream daos = new DataOutputStream(baos)
|
||||
daos.with {
|
||||
write(uuid.toString().bytes)
|
||||
host.write(daos)
|
||||
sender.write(daos)
|
||||
writeLong(chatTime)
|
||||
write(room.getBytes(StandardCharsets.UTF_8))
|
||||
write(words.getBytes(StandardCharsets.UTF_8))
|
||||
close()
|
||||
}
|
||||
byte [] payload = baos.toByteArray()
|
||||
Signature sig = DSAEngine.getInstance().sign(payload, spk)
|
||||
sig.getData()
|
||||
}
|
||||
|
||||
void sendChat(ChatMessageEvent e) {
|
||||
def chat = [:]
|
||||
chat.type = "Chat"
|
||||
|
|
|
@ -4,14 +4,49 @@ import griffon.core.artifact.GriffonController
|
|||
import griffon.core.controller.ControllerAction
|
||||
import griffon.inject.MVCMember
|
||||
import griffon.metadata.ArtifactProviderFor
|
||||
import net.i2p.crypto.DSAEngine
|
||||
import net.i2p.data.DataHelper
|
||||
import net.i2p.data.Signature
|
||||
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
import javax.annotation.Nonnull
|
||||
|
||||
import com.muwire.core.chat.ChatConnection
|
||||
import com.muwire.core.chat.ChatMessageEvent
|
||||
import com.muwire.core.chat.ChatServer
|
||||
|
||||
@ArtifactProviderFor(GriffonController)
|
||||
class ChatRoomController {
|
||||
@MVCMember @Nonnull
|
||||
ChatRoomModel model
|
||||
@MVCMember @Nonnull
|
||||
ChatRoomView view
|
||||
|
||||
@ControllerAction
|
||||
void say() {
|
||||
String words = view.sayField.text
|
||||
view.sayField.setText(null)
|
||||
|
||||
long now = System.currentTimeMillis()
|
||||
UUID uuid = UUID.randomUUID()
|
||||
String room = model.console ? ChatServer.CONSOLE : model.room
|
||||
|
||||
byte [] sig = ChatConnection.sign(uuid, now, room, words, model.core.me, mvcGroup.parentGroup.model.host, model.core.spk)
|
||||
|
||||
def event = new ChatMessageEvent(uuid : uuid,
|
||||
payload : words,
|
||||
sender : model.core.me,
|
||||
host : mvcGroup.parentGroup.model.host,
|
||||
room : room,
|
||||
chatTime : now,
|
||||
sig : sig)
|
||||
|
||||
model.core.eventBus.publish(event)
|
||||
|
||||
String toShow = DataHelper.formatTime(now) + " <" + model.core.me.getHumanReadableName() + "> "+words
|
||||
|
||||
view.roomTextArea.append(toShow)
|
||||
view.roomTextArea.append('\n')
|
||||
}
|
||||
}
|
|
@ -11,4 +11,7 @@ class ChatRoomModel {
|
|||
Core core
|
||||
String tabName
|
||||
String room
|
||||
boolean console
|
||||
|
||||
def members = []
|
||||
}
|
|
@ -3,6 +3,8 @@ package com.muwire.gui
|
|||
import griffon.core.artifact.GriffonView
|
||||
import griffon.inject.MVCMember
|
||||
import griffon.metadata.ArtifactProviderFor
|
||||
|
||||
import javax.swing.JSplitPane
|
||||
import javax.swing.SwingConstants
|
||||
|
||||
import java.awt.BorderLayout
|
||||
|
@ -20,19 +22,50 @@ class ChatRoomView {
|
|||
|
||||
def pane
|
||||
def parent
|
||||
def sayField
|
||||
def roomTextArea
|
||||
|
||||
void initUI() {
|
||||
int rowHeight = application.context.get("row-height")
|
||||
if (model.console) {
|
||||
pane = builder.panel {
|
||||
borderLayout()
|
||||
panel(constraints : BorderLayout.CENTER) {
|
||||
textArea(editable : false)
|
||||
gridLayout(rows : 1, cols : 1)
|
||||
roomTextArea = textArea(editable : false, lineWrap : true, wrapStyleWord : true)
|
||||
}
|
||||
panel(constraints : BorderLayout.SOUTH) {
|
||||
borderLayout()
|
||||
textField(actionPerformed : {controller.say()}, constraints : BorderLayout.CENTER)
|
||||
sayField = textField(actionPerformed : {controller.say()}, constraints : BorderLayout.CENTER)
|
||||
button(text : "Say", constraints : BorderLayout.EAST, sayAction)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pane = builder.panel {
|
||||
borderLayout()
|
||||
panel(constraints : BorderLayout.CENTER) {
|
||||
splitPane(orientation : JSplitPane.HORIZONTAL_SPLIT, continuousLayout : true, dividerLocation : 200)
|
||||
panel {
|
||||
table(autoCreateRowSorter : true, rowHeight : rowHeight) {
|
||||
tableModel(list : model.members) {
|
||||
closureColumn(header : "Name", type: String, read : {it.getHumanReadableName()})
|
||||
closureColumn(header : "Trust Status", type : String, read : {String.valueOf(model.core.trustService.getLevel(it.destination))})
|
||||
}
|
||||
}
|
||||
}
|
||||
panel {
|
||||
gridLayout(rows : 1, cols : 1)
|
||||
roomTextArea = textArea(editable : false, lineWrap : true, wrapStyleWord : true)
|
||||
}
|
||||
}
|
||||
panel(constraints : BorderLayout.SOUTH) {
|
||||
borderLayout()
|
||||
sayField = textField(actionPerformed : {controller.say()}, constraints : BorderLayout.CENTER)
|
||||
button(text : "Say", constraints : BorderLayout.EAST, sayAction)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mvcGroupInit(Map<String,String> args) {
|
||||
|
@ -50,6 +83,7 @@ class ChatRoomView {
|
|||
button(icon : imageIcon("/close_tab.png"), preferredSize: [20, 20], constraints : BorderLayout.EAST,
|
||||
actionPerformed : closeTab )
|
||||
}
|
||||
if (!model.console)
|
||||
parent.setTabComponentAt(index, tabPanel)
|
||||
}
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ class ChatServerView {
|
|||
params['core'] = model.core
|
||||
params['tabName'] = model.host.getHumanReadableName() + "-chat-rooms"
|
||||
params['room'] = 'Console'
|
||||
params['console'] = true
|
||||
mvcGroup.createMVCGroup("chat-room","Console", params)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue