Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-11606]: configuration option to disable commands in ch…
…at rooms
  • Loading branch information
kutzi committed Nov 6, 2011
1 parent 16e1c39 commit f2ec606
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
Expand Up @@ -52,4 +52,9 @@ public void removeMessageListener(IMMessageListener listener) {
public boolean isMultiUserChat() {
return false;
}

@Override
public boolean isCommandsAccepted() {
return true;
}
}
Expand Up @@ -459,7 +459,7 @@ private MultiUserChat getOrCreateGroupChat(GroupChatIMMessageTarget chat) throws
while (groupChat.pollMessage() != null) {
}

this.bots.add(new Bot(new JabberMultiUserChat(groupChat, this),
this.bots.add(new Bot(new JabberMultiUserChat(groupChat, this, !chat.isNotificationOnly()),
this.groupChatNick, this.desc.getHost(),
this.botCommandPrefix, this.authentication));

Expand Down
Expand Up @@ -8,14 +8,21 @@
import org.jivesoftware.smackx.muc.MultiUserChat;
import org.jivesoftware.smackx.muc.Occupant;

/**
* Handle for a multi-user chat (aka. conference room) in XMPP/Jabber.
*
* @author kutzi
*/
public class JabberMultiUserChat implements IMChat {

private final MultiUserChat chat;
private final JabberIMConnection connection;
private final boolean commandsAccepted;

public JabberMultiUserChat (MultiUserChat chat, JabberIMConnection connection) {
public JabberMultiUserChat (MultiUserChat chat, JabberIMConnection connection, boolean commandsAccepted) {
this.chat = chat;
this.connection = connection;
this.commandsAccepted = commandsAccepted;
}

public void sendMessage(String msg) throws IMException {
Expand Down Expand Up @@ -62,4 +69,8 @@ public void removeMessageListener(IMMessageListener listener) {
public boolean isMultiUserChat() {
return true;
}

public boolean isCommandsAccepted() {
return this.commandsAccepted;
}
}
Expand Up @@ -248,13 +248,15 @@ private void applyPort(final HttpServletRequest req, boolean check) throws FormE
private void applyInitialGroupChats(final HttpServletRequest req) {
String[] chatNames = req.getParameterValues("jabberPlugin.chat.name");
String[] chatPasswords = req.getParameterValues("jabberPlugin.chat.password");
String[] notifyOnlys = req.getParameterValues("jabberPlugin.chat.notificationOnly");
this.defaultTargets = new ArrayList<IMMessageTarget>();

if (chatNames != null) {
for (int i = 0; i < chatNames.length; i++) {
String chatName = chatNames[i];
String chatPassword = Util.fixEmptyAndTrim(chatPasswords[i]);
this.defaultTargets.add(new GroupChatIMMessageTarget(chatName, chatPassword));
boolean notifyOnly = notifyOnlys != null ? "on".equalsIgnoreCase(notifyOnlys[i]) : false;
this.defaultTargets.add(new GroupChatIMMessageTarget(chatName, chatPassword, notifyOnly));
}
}
}
Expand Down Expand Up @@ -785,7 +787,7 @@ private Object readResolve() {
String[] split = this.initialGroupChats.trim().split("\\s");
this.defaultTargets = new ArrayList<IMMessageTarget>();
for (String chatName : split) {
this.defaultTargets.add(new GroupChatIMMessageTarget(chatName));
this.defaultTargets.add(new GroupChatIMMessageTarget(chatName, null, false));
}
this.initialGroupChats = null;
save();
Expand Down
Expand Up @@ -15,17 +15,23 @@
<f:password name="${descriptor.PARAMETERNAME_PASSWORD}"
value="${descriptor.password}"/>
</f:entry>
<f:entry title="Initial group chats" description="Group chats to automatically join on startup. Name, (optional) password pairs.">
<f:entry title="Initial group chats" description="Group chats to automatically join on startup. Name and (optional) password. Check 'Notification only' if you want to disallow bot commands.">
<!-- Note that this strange separation of the table headers into a separate table is done one purpose. I didn't find another way
without breaking the rendering of the whole config page! -->
<table width="100%">
<tr style="text-align:left"><th width="30%">Name</th><th width="30%">Password</th><th width="10%">Notification only</th><th width="30%"/></tr>
</table>
<f:repeatable name="jabberPlugin.initialChats" var="ch" items="${descriptor.defaultTargets}">
<table width="100%">
<table width="100%">
<tr>
<td><input type="text" width="100%" style="text-align:left" name="jabberPlugin.chat.name" value="${ch.name}" /></td>
<td><input type="password" width="100%" style="text-align:left" name="jabberPlugin.chat.password" value="${ch.password}" /></td>
<td>
<td width="30%"><input type="text" width="100%" style="text-align:left" name="jabberPlugin.chat.name" value="${ch.name}" /></td>
<td width="30%"><input type="password" width="100%" style="text-align:left" name="jabberPlugin.chat.password" value="${ch.password}" /></td>
<td width="10%"><f:checkbox name="jabberPlugin.chat.notificationOnly" checked="${ch.notificationOnly}"/></td>
<td width="30%">
<div align="right"><f:repeatableDeleteButton /></div>
</td>
</tr>
</table>
</table>
</f:repeatable>
</f:entry>
<f:advanced>
Expand Down

0 comments on commit f2ec606

Please sign in to comment.