mirror of https://github.com/zlatinb/muwire
add option to select chat server welcome message
parent
8a47972b10
commit
e760e9f600
|
@ -34,6 +34,7 @@ class MuWireSettings {
|
||||||
boolean startChatServer
|
boolean startChatServer
|
||||||
int maxChatConnections
|
int maxChatConnections
|
||||||
boolean advertiseChat
|
boolean advertiseChat
|
||||||
|
File chatWelcomeFile
|
||||||
Set<String> watchedDirectories
|
Set<String> watchedDirectories
|
||||||
float downloadSequentialRatio
|
float downloadSequentialRatio
|
||||||
int hostClearInterval, hostHopelessInterval, hostRejectInterval
|
int hostClearInterval, hostHopelessInterval, hostRejectInterval
|
||||||
|
@ -85,6 +86,9 @@ class MuWireSettings {
|
||||||
startChatServer = Boolean.valueOf(props.getProperty("startChatServer","false"))
|
startChatServer = Boolean.valueOf(props.getProperty("startChatServer","false"))
|
||||||
maxChatConnections = Integer.valueOf(props.get("maxChatConnections", "-1"))
|
maxChatConnections = Integer.valueOf(props.get("maxChatConnections", "-1"))
|
||||||
advertiseChat = Boolean.valueOf(props.getProperty("advertiseChat","true"))
|
advertiseChat = Boolean.valueOf(props.getProperty("advertiseChat","true"))
|
||||||
|
String chatWelcomeProp = props.getProperty("chatWelcomeFile")
|
||||||
|
if (chatWelcomeProp != null)
|
||||||
|
chatWelcomeFile = new File(chatWelcomeProp)
|
||||||
|
|
||||||
watchedDirectories = DataUtil.readEncodedSet(props, "watchedDirectories")
|
watchedDirectories = DataUtil.readEncodedSet(props, "watchedDirectories")
|
||||||
watchedKeywords = DataUtil.readEncodedSet(props, "watchedKeywords")
|
watchedKeywords = DataUtil.readEncodedSet(props, "watchedKeywords")
|
||||||
|
@ -136,6 +140,8 @@ class MuWireSettings {
|
||||||
props.setProperty("startChatServer", String.valueOf(startChatServer))
|
props.setProperty("startChatServer", String.valueOf(startChatServer))
|
||||||
props.setProperty("maxChatConnectios", String.valueOf(maxChatConnections))
|
props.setProperty("maxChatConnectios", String.valueOf(maxChatConnections))
|
||||||
props.setProperty("advertiseChat", String.valueOf(advertiseChat))
|
props.setProperty("advertiseChat", String.valueOf(advertiseChat))
|
||||||
|
if (chatWelcomeFile != null)
|
||||||
|
props.setProperty("chatWelcomeFile", chatWelcomeFile.getAbsolutePath())
|
||||||
|
|
||||||
DataUtil.writeEncodedSet(watchedDirectories, "watchedDirectories", props)
|
DataUtil.writeEncodedSet(watchedDirectories, "watchedDirectories", props)
|
||||||
DataUtil.writeEncodedSet(watchedKeywords, "watchedKeywords", props)
|
DataUtil.writeEncodedSet(watchedKeywords, "watchedKeywords", props)
|
||||||
|
|
|
@ -25,6 +25,8 @@ import net.i2p.util.ConcurrentHashSet
|
||||||
@Log
|
@Log
|
||||||
class ChatServer {
|
class ChatServer {
|
||||||
public static final String CONSOLE = "__CONSOLE__"
|
public static final String CONSOLE = "__CONSOLE__"
|
||||||
|
private static final String DEFAULT_WELCOME = "Welcome to my chat server! Type /HELP for list of available commands"
|
||||||
|
|
||||||
private final EventBus eventBus
|
private final EventBus eventBus
|
||||||
private final MuWireSettings settings
|
private final MuWireSettings settings
|
||||||
private final TrustService trustService
|
private final TrustService trustService
|
||||||
|
@ -55,7 +57,14 @@ class ChatServer {
|
||||||
connections.put(me.destination, LocalChatLink.INSTANCE)
|
connections.put(me.destination, LocalChatLink.INSTANCE)
|
||||||
joinRoom(me, CONSOLE)
|
joinRoom(me, CONSOLE)
|
||||||
shortNames.put(me.getHumanReadableName(), me)
|
shortNames.put(me.getHumanReadableName(), me)
|
||||||
echo("/SAY Welcome to my chat server! Type /HELP for list of available commands.",me.destination)
|
echo(getWelcome(),me.destination)
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getWelcome() {
|
||||||
|
String welcome = DEFAULT_WELCOME
|
||||||
|
if (settings.chatWelcomeFile != null)
|
||||||
|
welcome = settings.chatWelcomeFile.text
|
||||||
|
"/SAY $welcome"
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendPings() {
|
private void sendPings() {
|
||||||
|
@ -110,7 +119,7 @@ class ChatServer {
|
||||||
joinRoom(client, CONSOLE)
|
joinRoom(client, CONSOLE)
|
||||||
shortNames.put(client.getHumanReadableName(), client)
|
shortNames.put(client.getHumanReadableName(), client)
|
||||||
connection.start()
|
connection.start()
|
||||||
echo("/SAY Welcome to my chat server! Type /HELP for help on available commands",connection.endpoint.destination)
|
echo(getWelcome(),connection.endpoint.destination)
|
||||||
}
|
}
|
||||||
|
|
||||||
void onChatDisconnectionEvent(ChatDisconnectionEvent e) {
|
void onChatDisconnectionEvent(ChatDisconnectionEvent e) {
|
||||||
|
|
|
@ -155,6 +155,9 @@ class OptionsController {
|
||||||
int maxChatLines = Integer.parseInt(view.maxChatLinesField.text)
|
int maxChatLines = Integer.parseInt(view.maxChatLinesField.text)
|
||||||
model.maxChatLines = maxChatLines
|
model.maxChatLines = maxChatLines
|
||||||
uiSettings.maxChatLines = maxChatLines
|
uiSettings.maxChatLines = maxChatLines
|
||||||
|
|
||||||
|
if (model.chatWelcomeFile != null)
|
||||||
|
settings.chatWelcomeFile = new File(model.chatWelcomeFile)
|
||||||
|
|
||||||
core.saveMuSettings()
|
core.saveMuSettings()
|
||||||
|
|
||||||
|
@ -237,6 +240,19 @@ class OptionsController {
|
||||||
model.incompleteLocation = chooser.getSelectedFile().getAbsolutePath()
|
model.incompleteLocation = chooser.getSelectedFile().getAbsolutePath()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void chooseChatFile() {
|
||||||
|
def chooser = new JFileChooser()
|
||||||
|
chooser.with {
|
||||||
|
setFileHidingEnabled(false)
|
||||||
|
setDialogTitle("Select location of chat server welcome file")
|
||||||
|
setFileSelectionMode(JFileChooser.FILES_ONLY)
|
||||||
|
int rv = chooser.showOpenDialog(null)
|
||||||
|
if (rv == JFileChooser.APPROVE_OPTION)
|
||||||
|
model.chatWelcomeFile = getSelectedFile().getAbsolutePath()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ControllerAction
|
@ControllerAction
|
||||||
void automaticFont() {
|
void automaticFont() {
|
||||||
model.automaticFontSize = true
|
model.automaticFontSize = true
|
||||||
|
|
|
@ -61,6 +61,7 @@ class OptionsModel {
|
||||||
@Observable int maxChatConnections
|
@Observable int maxChatConnections
|
||||||
@Observable boolean advertiseChat
|
@Observable boolean advertiseChat
|
||||||
@Observable int maxChatLines
|
@Observable int maxChatLines
|
||||||
|
@Observable String chatWelcomeFile
|
||||||
|
|
||||||
void mvcGroupInit(Map<String, String> args) {
|
void mvcGroupInit(Map<String, String> args) {
|
||||||
MuWireSettings settings = application.context.get("muwire-settings")
|
MuWireSettings settings = application.context.get("muwire-settings")
|
||||||
|
@ -114,5 +115,6 @@ class OptionsModel {
|
||||||
maxChatConnections = settings.maxChatConnections
|
maxChatConnections = settings.maxChatConnections
|
||||||
advertiseChat = settings.advertiseChat
|
advertiseChat = settings.advertiseChat
|
||||||
maxChatLines = uiSettings.maxChatLines
|
maxChatLines = uiSettings.maxChatLines
|
||||||
|
chatWelcomeFile = settings.chatWelcomeFile?.getAbsolutePath()
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -280,13 +280,16 @@ class OptionsView {
|
||||||
constraints : gbc(gridx : 0, gridy : 0, fill : GridBagConstraints.HORIZONTAL, weightx: 100)) {
|
constraints : gbc(gridx : 0, gridy : 0, fill : GridBagConstraints.HORIZONTAL, weightx: 100)) {
|
||||||
gridBagLayout()
|
gridBagLayout()
|
||||||
label(text : "Start chat server on startup", constraints : gbc(gridx: 0, gridy: 0, anchor: GridBagConstraints.LINE_START, weightx: 100))
|
label(text : "Start chat server on startup", constraints : gbc(gridx: 0, gridy: 0, anchor: GridBagConstraints.LINE_START, weightx: 100))
|
||||||
startChatServerCheckbox = checkBox(selected : bind{model.startChatServer}, constraints : gbc(gridx:1, gridy:0, anchor:GridBagConstraints.LINE_END))
|
startChatServerCheckbox = checkBox(selected : bind{model.startChatServer}, constraints : gbc(gridx:2, gridy:0, anchor:GridBagConstraints.LINE_END))
|
||||||
label(text : "Maximum chat connections (-1 means unlimited)", constraints : gbc(gridx: 0, gridy:1, anchor:GridBagConstraints.LINE_START, weightx:100))
|
label(text : "Maximum chat connections (-1 means unlimited)", constraints : gbc(gridx: 0, gridy:1, anchor:GridBagConstraints.LINE_START, weightx:100))
|
||||||
maxChatConnectionsField = textField(text : bind {model.maxChatConnections}, constraints : gbc(gridx: 1, gridy : 1, anchor:GridBagConstraints.LINE_END))
|
maxChatConnectionsField = textField(text : bind {model.maxChatConnections}, constraints : gbc(gridx: 2, gridy : 1, anchor:GridBagConstraints.LINE_END))
|
||||||
label(text : "Advertise chat ability in search results", constraints : gbc(gridx: 0, gridy:2, anchor:GridBagConstraints.LINE_START, weightx:100))
|
label(text : "Advertise chat ability in search results", constraints : gbc(gridx: 0, gridy:2, anchor:GridBagConstraints.LINE_START, weightx:100))
|
||||||
advertiseChatCheckbox = checkBox(selected : bind{model.advertiseChat}, constraints : gbc(gridx:1, gridy:2, anchor:GridBagConstraints.LINE_END))
|
advertiseChatCheckbox = checkBox(selected : bind{model.advertiseChat}, constraints : gbc(gridx:2, gridy:2, anchor:GridBagConstraints.LINE_END))
|
||||||
label(text : "Maximum lines of scrollback (-1 means unlimited)", constraints : gbc(gridx:0, gridy:3, anchor : GridBagConstraints.LINE_START, weightx: 100))
|
label(text : "Maximum lines of scrollback (-1 means unlimited)", constraints : gbc(gridx:0, gridy:3, anchor : GridBagConstraints.LINE_START, weightx: 100))
|
||||||
maxChatLinesField = textField(text : bind{model.maxChatLines}, constraints : gbc(gridx:1, gridy: 3, anchor: GridBagConstraints.LINE_END))
|
maxChatLinesField = textField(text : bind{model.maxChatLines}, constraints : gbc(gridx:2, gridy: 3, anchor: GridBagConstraints.LINE_END))
|
||||||
|
label(text : "Welcome message file", constraints : gbc(gridx : 0, gridy : 4, anchor : GridBagConstraints.LINE_START, weightx: 100))
|
||||||
|
label(text : bind {model.chatWelcomeFile}, constraints : gbc(gridx : 1, gridy : 4))
|
||||||
|
button(text : "Choose", constraints : gbc(gridx : 2, gridy : 4, anchor : GridBagConstraints.LINE_END), chooseChatFileAction)
|
||||||
}
|
}
|
||||||
panel(constraints : gbc(gridx: 0, gridy : 1, weighty: 100))
|
panel(constraints : gbc(gridx: 0, gridy : 1, weighty: 100))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue