add option to select chat server welcome message

pull/34/head
Zlatin Balevsky 2019-11-19 09:02:42 +00:00
parent 8a47972b10
commit e760e9f600
5 changed files with 42 additions and 6 deletions

View File

@ -34,6 +34,7 @@ class MuWireSettings {
boolean startChatServer
int maxChatConnections
boolean advertiseChat
File chatWelcomeFile
Set<String> watchedDirectories
float downloadSequentialRatio
int hostClearInterval, hostHopelessInterval, hostRejectInterval
@ -85,6 +86,9 @@ class MuWireSettings {
startChatServer = Boolean.valueOf(props.getProperty("startChatServer","false"))
maxChatConnections = Integer.valueOf(props.get("maxChatConnections", "-1"))
advertiseChat = Boolean.valueOf(props.getProperty("advertiseChat","true"))
String chatWelcomeProp = props.getProperty("chatWelcomeFile")
if (chatWelcomeProp != null)
chatWelcomeFile = new File(chatWelcomeProp)
watchedDirectories = DataUtil.readEncodedSet(props, "watchedDirectories")
watchedKeywords = DataUtil.readEncodedSet(props, "watchedKeywords")
@ -136,6 +140,8 @@ class MuWireSettings {
props.setProperty("startChatServer", String.valueOf(startChatServer))
props.setProperty("maxChatConnectios", String.valueOf(maxChatConnections))
props.setProperty("advertiseChat", String.valueOf(advertiseChat))
if (chatWelcomeFile != null)
props.setProperty("chatWelcomeFile", chatWelcomeFile.getAbsolutePath())
DataUtil.writeEncodedSet(watchedDirectories, "watchedDirectories", props)
DataUtil.writeEncodedSet(watchedKeywords, "watchedKeywords", props)

View File

@ -25,6 +25,8 @@ import net.i2p.util.ConcurrentHashSet
@Log
class ChatServer {
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 MuWireSettings settings
private final TrustService trustService
@ -55,7 +57,14 @@ class ChatServer {
connections.put(me.destination, LocalChatLink.INSTANCE)
joinRoom(me, CONSOLE)
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() {
@ -110,7 +119,7 @@ class ChatServer {
joinRoom(client, CONSOLE)
shortNames.put(client.getHumanReadableName(), client)
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) {

View File

@ -155,6 +155,9 @@ class OptionsController {
int maxChatLines = Integer.parseInt(view.maxChatLinesField.text)
model.maxChatLines = maxChatLines
uiSettings.maxChatLines = maxChatLines
if (model.chatWelcomeFile != null)
settings.chatWelcomeFile = new File(model.chatWelcomeFile)
core.saveMuSettings()
@ -237,6 +240,19 @@ class OptionsController {
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
void automaticFont() {
model.automaticFontSize = true

View File

@ -61,6 +61,7 @@ class OptionsModel {
@Observable int maxChatConnections
@Observable boolean advertiseChat
@Observable int maxChatLines
@Observable String chatWelcomeFile
void mvcGroupInit(Map<String, String> args) {
MuWireSettings settings = application.context.get("muwire-settings")
@ -114,5 +115,6 @@ class OptionsModel {
maxChatConnections = settings.maxChatConnections
advertiseChat = settings.advertiseChat
maxChatLines = uiSettings.maxChatLines
chatWelcomeFile = settings.chatWelcomeFile?.getAbsolutePath()
}
}

View File

@ -280,13 +280,16 @@ class OptionsView {
constraints : gbc(gridx : 0, gridy : 0, fill : GridBagConstraints.HORIZONTAL, weightx: 100)) {
gridBagLayout()
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))
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))
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))
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))
}