Viewing Issue Advanced Details

ID 0003600 Category [DMDirc] *Unsorted Severity minor
Reproducibility always Date Submitted 2010-01-24 01:54 Last Update 2010-03-07 19:16
Reporter Greboid Assigned To MD87 View Status public
Priority normal Status resolved Resolution fixed
Platform Fixed in Version Target Version 0.6.4
Product Version Product Build
Summary 0003600: /join should use parser joinChannels so it doesnt join things individually
Description
/join should use parser joinChannels so it doesnt join things individually
Needs unit test no
Upstream Bug URL

Relationships

depends on 0003641resolvedMD87 Implement/expose parser method to join multiple channels with keys 

Notes

A patchset (1) related to this change has been added to gerrit by Chris Smith

Add joinChannels method and repurpose updateURI()

Fixes issue 3582
Issue 3623
Issue 3600

Change-Id: Ia0b147cfe1af5d5d5d1eae34c82e50ce23578d10
Depends-On: I1dac30977798780148eb27b8279a56a86b3bf890

A patchset (1) related to this change has been added to gerrit by Chris Smith

New join channels methods

Fixes issue 3623
Issue 3600

Change-Id: I4e83082eeb7ad38a5c992510c8ac6fdad88ce6f2
Depends-On: Ia0b147cfe1af5d5d5d1eae34c82e50ce23578d10

A patchset (1) related to this change has been added to gerrit by Chris Smith

/join command now allows parsers to batch joins together

Fixes issue 3600

Change-Id: Ia44ade3dcdad8b6ac831289b3e098b64380190a9

A patchset (2) related to this change has been added to gerrit by Chris Smith

Add joinChannels method and repurpose updateURI()

Fixes issue 3582
Fixes issue 3641
Issue 3623
Issue 3600

Change-Id: Ia0b147cfe1af5d5d5d1eae34c82e50ce23578d10
Depends-On: I1dac30977798780148eb27b8279a56a86b3bf890

A patchset (3) related to this change has been added to gerrit by Chris Smith

Add joinChannels method and repurpose updateURI()

Fixes issue 3582
Fixes issue 3641
Fixes issue 3863 (dev error)
Issue 3623
Issue 3600

Change-Id: Ia0b147cfe1af5d5d5d1eae34c82e50ce23578d10
Depends-On: I1dac30977798780148eb27b8279a56a86b3bf890
authorChris Smith <chris@dmdirc.com>2010-03-07 14:16:00 (GMT)
committer Gregory Holmes <greg@dmdirc.com>2010-03-07 19:14:10 (GMT)
commitec962daa8bbdd58ce2d7625d02fbd59ac93eb22b (patch) (side-by-side diff)
New join channels methods
Fixes issue 3623 Issue 3600 Change-Id: I4e83082eeb7ad38a5c992510c8ac6fdad88ce6f2 Depends-On: Ia0b147cfe1af5d5d5d1eae34c82e50ce23578d10 Reviewed-on: http://gerrit.dmdirc.com/981 Automatic-Compile: Chris Smith <chris@dmdirc.com> Reviewed-by: Gregory Holmes <greg@dmdirc.com>
-rw-r--r--src/com/dmdirc/Server.java59
-rw-r--r--src/com/dmdirc/ServerManager.java7
2 files changed, 43 insertions, 23 deletions
Click to Expand/Collapse
diff src/com/dmdirc/Server.java
@@ -36,6 +36,7 @@ import com.dmdirc.interfaces.ConfigChangeListener;
import com.dmdirc.interfaces.InviteListener;
import com.dmdirc.logger.ErrorLevel;
import com.dmdirc.logger.Logger;
+import com.dmdirc.parser.common.ChannelJoinRequest;
import com.dmdirc.parser.common.DefaultStringConverter;
import com.dmdirc.parser.common.IgnoreList;
import com.dmdirc.parser.common.ParserError;
@@ -801,19 +802,46 @@ public class Server extends WritableFrameContainer implements ConfigChangeListen
* @since 0.6.3m1
* @param channel The channel to be joined
* @param key The key for the channel
+ * @deprecated Use {@link #join(com.dmdirc.parser.common.ChannelJoinRequest[])}
*/
+ @Deprecated
public void join(final String channel, final String key) {
+ join(new ChannelJoinRequest(channel, key));
+ }
+
+ /**
+ * Attempts to join the specified channels. If channels with the same name
+ * already exist, they are (re)joined and their windows activated.
+ *
+ * @param requests The channel join requests to process
+ * @since 0.6.4
+ */
+ public void join(final ChannelJoinRequest ... requests) {
synchronized (myStateLock) {
if (myState.getState() == ServerState.CONNECTED) {
- removeInvites(channel);
+ final List<ChannelJoinRequest> pending = new ArrayList<ChannelJoinRequest>();
- if (hasChannel(channel)) {
- // TODO: Need to pass key?
- getChannel(channel).join();
- getChannel(channel).activateFrame();
- } else {
- parser.joinChannel(channel, key);
+ for (ChannelJoinRequest request : requests) {
+ removeInvites(request.getName());
+
+ final String name;
+ if (parser.isValidChannelName(request.getName())) {
+ name = request.getName();
+ } else {
+ name = parser.getChannelPrefixes().substring(0, 1)
+ + request.getName();
+ }
+
+ if (hasChannel(name)) {
+ // TODO: Need to pass key
+ getChannel(name).join();
+ getChannel(name).activateFrame();
+ } else {
+ pending.add(request);
+ }
}
+
+ parser.joinChannels(pending.toArray(new ChannelJoinRequest[0]));
} else {
// TODO: Need to pass key
// TODO (uris): address.getChannels().add(channel);
@@ -826,22 +854,11 @@ public class Server extends WritableFrameContainer implements ConfigChangeListen
* server is not connected.
*
* @param channel The channel to be joined
+ * @deprecated Use {@link #join(com.dmdirc.parser.common.ChannelJoinRequest[])}
*/
+ @Deprecated
public void join(final String channel) {
- synchronized (myStateLock) {
- if (myState.getState() == ServerState.CONNECTED) {
- removeInvites(channel);
-
- if (hasChannel(channel)) {
- getChannel(channel).join();
- getChannel(channel).activateFrame();
- } else {
- parser.joinChannel(channel);
- }
- } else {
- // TODO(uris): address.getChannels().add(channel);
- }
- }
+ join(new ChannelJoinRequest(channel));
}
/** {@inheritDoc} */
Click to Expand/Collapse
diff src/com/dmdirc/ServerManager.java
@@ -26,6 +26,7 @@ import com.dmdirc.config.Identity;
import com.dmdirc.config.IdentityManager;
import com.dmdirc.logger.ErrorLevel;
import com.dmdirc.logger.Logger;
+import com.dmdirc.parser.common.ChannelJoinRequest;
import com.dmdirc.ui.interfaces.Window;
import java.net.URI;
@@ -246,13 +247,15 @@ public final class ServerManager {
return server;
}
+ server.activateFrame();
+
if (server.getState().isDisconnected()) {
server.connect(uri, profile );
} else {
- server.getParser().updateURI(uri);
+ server.join(server.getParser().extractChannels(uri)
+ .toArray(new ChannelJoinRequest[0]));
}
- server.activateFrame();
return server;
}
authorChris Smith <chris@dmdirc.com>2010-03-07 14:23:17 (GMT)
committer Gregory Holmes <greg@dmdirc.com>2010-03-07 19:14:34 (GMT)
commit3fb6768e27cba29fbc4120ac0318ee454e91ba00 (patch) (side-by-side diff)
/join command now allows parsers to batch joins together
Fixes issue 3600 Change-Id: Ia44ade3dcdad8b6ac831289b3e098b64380190a9 Reviewed-on: http://gerrit.dmdirc.com/982 Automatic-Compile: Chris Smith <chris@dmdirc.com> Reviewed-by: Gregory Holmes <greg@dmdirc.com>
-rw-r--r--src/com/dmdirc/commandparser/commands/server/JoinChannelCommand.java12
1 files changed, 9 insertions, 3 deletions
Click to Expand/Collapse
diff src/com/dmdirc/commandparser/commands/server/JoinChannelCommand.java
@@ -32,9 +32,11 @@ import com.dmdirc.commandparser.CommandManager;
import com.dmdirc.commandparser.commands.IntelligentCommand;
import com.dmdirc.commandparser.commands.ServerCommand;
import com.dmdirc.interfaces.ActionListener;
+import com.dmdirc.parser.common.ChannelJoinRequest;
import com.dmdirc.ui.input.AdditionalTabTargets;
import com.dmdirc.ui.interfaces.InputWindow;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -66,15 +68,20 @@ public final class JoinChannelCommand extends ServerCommand implements
return;
}
+ final List<ChannelJoinRequest> channels = new ArrayList<ChannelJoinRequest>();
+
for (String pair : args.getArgumentsAsString().split(",")) {
int index = pair.trim().indexOf(' ');
if (index == -1) {
- server.join(pair);
+ channels.add(new ChannelJoinRequest(pair));
} else {
- server.join(pair.substring(0, index), pair.substring(index + 1));
+ channels.add(new ChannelJoinRequest(pair.substring(0, index),
+ pair.substring(index + 1)));
}
}
+
+ server.join(channels.toArray(new ChannelJoinRequest[0]));
}
@@ -109,7 +116,6 @@ public final class JoinChannelCommand extends ServerCommand implements
public AdditionalTabTargets getSuggestions(final int arg,
final List<String> previousArgs) {
return new AdditionalTabTargets();
- //throw new UnsupportedOperationException("Not supported yet.");
}
}
authorChris Smith <chris@dmdirc.com>2010-03-07 14:12:42 (GMT)
committer Gregory Holmes <greg@dmdirc.com>2010-03-07 19:15:36 (GMT)
commit5c89ed6898c8db4c9bd52942146831b2a885a1fe (patch) (side-by-side diff)
Add joinChannels method and repurpose updateURI()
Fixes issue 3582 Fixes issue 3641 Fixes issue 3863 (dev error) Issue 3623 Issue 3600 Change-Id: Ia0b147cfe1af5d5d5d1eae34c82e50ce23578d10 Depends-On: I1dac30977798780148eb27b8279a56a86b3bf890 Reviewed-on: http://gerrit.dmdirc.com/979 Automatic-Compile: Chris Smith <chris@dmdirc.com> Reviewed-by: Gregory Holmes <greg@dmdirc.com>
-rw-r--r--src/com/dmdirc/parser/common/ChannelJoinRequest.java78
-rw-r--r--src/com/dmdirc/parser/interfaces/Parser.java31
-rw-r--r--src/com/dmdirc/parser/irc/IRCParser.java74
-rw-r--r--src/com/dmdirc/parser/irc/Process001.java2
4 files changed, 132 insertions, 53 deletions
Click to Expand/Collapse
diff src/com/dmdirc/parser/common/ChannelJoinRequest.java
new file mode 100644
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package com.dmdirc.parser.common;
+
+/**
+ * Describes the information needed to try and join a channel.
+ *
+ * @author chris
+ * @since 0.6.4
+ */
+public class ChannelJoinRequest {
+
+ /** The name of the channel to join (required). */
+ private final String name;
+ /** The name of the password to use (optional). */
+ private final String password;
+
+ /**
+ * Creates a new ChannelJoinRequest for a password-less channel with
+ * the specified name.
+ *
+ * @param name The name of the channel to join
+ */
+ public ChannelJoinRequest(final String name) {
+ this(name, null);
+ }
+
+ /**
+ * Creates a new ChannelJoinRequest for a channel with the specified
+ * password.
+ *
+ * @param name The name of the channel to join
+ * @param password The password to use
+ */
+ public ChannelJoinRequest(final String name, final String password) {
+ this.name = name;
+ this.password = password;
+ }
+
+ /**
+ * Retrieves the name of the channel this request will try to join.
+ *
+ * @return The name of the channel in this request
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Retrieves the password which will be used to try to join the channel.
+ *
+ * @return The password to use, or null if none specified
+ */
+ public String getPassword() {
+ return password;
+ }
+
+}
Click to Expand/Collapse
diff src/com/dmdirc/parser/interfaces/Parser.java
@@ -24,6 +24,7 @@ package com.dmdirc.parser.interfaces;
import com.dmdirc.parser.common.IgnoreList;
import com.dmdirc.parser.common.CallbackManager;
+import com.dmdirc.parser.common.ChannelJoinRequest;
import com.dmdirc.parser.common.QueuePriority;
import java.net.URI;
@@ -63,6 +64,14 @@ public interface Parser extends Runnable {
void joinChannel(String channel, String key);
/**
+ * Joins the specified channels.
+ *
+ * @since 0.6.4
+ * @param channels The channels to be joined
+ */
+ void joinChannels(ChannelJoinRequest ... channels);
+
+ /**
* Retrieves a channel information object for the specified channel.
*
* @param channel Name of the channel to retrieve an information object for
@@ -187,24 +196,12 @@ public interface Parser extends Runnable {
boolean compareURI(final URI uri);
/**
- * Updates this parser with a new URI. The new URI should be fundamentally
- * the same as the one the parser connected to (to the extent that
- * {@link #compareURI(java.net.URI)} returns true), but it may contain
- * extra information (such as an additional list of channels to join).
- * This operation should be non-destructive; that is, if the URI provided
- * contains less information than a previous URI, the 'missing' information
- * should not be treated as an instruction to remove it.
- * <p>
- * For example, if the parser was originally constructed with a URI
- * <code>irc://irc.quakenet.org/chan1,chan2</code>, and this method was
- * subsequently called with an argument of
- * <code>irc://irc.quakenet.org/chan3</code>, the IRC parser should join
- * the channel "chan3" and would also remain in chan1 and chan2.
- *
- * @param uri The URI to update this parser with
- * @since 0.6.3
+ * Extracts any channels present in the specified URI.
+ *
+ * @param uri The URI to extract channels from
+ * @since 0.6.4
*/
- void updateURI(final URI uri);
+ Collection<? extends ChannelJoinRequest> extractChannels(final URI uri);
/**
* Retrieves the name of the server that this parser is connected to.
Click to Expand/Collapse
diff src/com/dmdirc/parser/irc/IRCParser.java
@@ -39,6 +39,7 @@ import com.dmdirc.parser.interfaces.callbacks.Post005Listener;
import com.dmdirc.parser.interfaces.callbacks.ServerErrorListener;
import com.dmdirc.parser.interfaces.callbacks.SocketCloseListener;
import com.dmdirc.parser.common.CallbackManager;
+import com.dmdirc.parser.common.ChannelJoinRequest;
import com.dmdirc.parser.common.QueuePriority;
import java.io.BufferedReader;
@@ -53,6 +54,7 @@ import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
@@ -357,11 +359,33 @@ public class IRCParser implements SecureParser, Runnable {
/** {@inheritDoc} */
@Override
- public void updateURI(final URI uri) {
- final String channels = new ServerInfo(uri).getChannels();
- if (channels != null) {
- joinChannel(channels, true);
+ public Collection<? extends ChannelJoinRequest> extractChannels(final URI uri) {
+ return extractChannels(new ServerInfo(uri).getChannels());
+ }
+
+ /**
+ * Extracts a set of channels and optional keys from the specified String.
+ * Channels are separated by commas, and keys are separated from their
+ * channels by a space.
+ *
+ * @since 0.6.4
+ * @param channels The string of channels to parse
+ * @return A corresponding collection of join request objects
+ */
+ protected Collection<? extends ChannelJoinRequest> extractChannels(final String channels) {
+ final List<ChannelJoinRequest> res = new ArrayList<ChannelJoinRequest>();
+
+ for (String channel : channels.split(",")) {
+ final String[] parts = channel.split(" ", 2);
+
+ if (parts.length == 2) {
+ res.add(new ChannelJoinRequest(parts[0], parts[1]));
+ } else {
+ res.add(new ChannelJoinRequest(parts[0]));
+ }
}
+
+ return res;
}
/** {@inheritDoc} */
@@ -1468,24 +1492,13 @@ public class IRCParser implements SecureParser, Runnable {
/** {@inheritDoc} */
@Override
public void joinChannel(final String channel) {
- joinChannel(channel, "", true);
- }
-
- /**
- * Join a Channel.
- *
- * @param sChannelName Name of channel to join
- * @param autoPrefix Automatically prepend the first channel prefix defined
- * in 005 if sChannelName is an invalid channel.
- */
- public void joinChannel(final String sChannelName, final boolean autoPrefix) {
- joinChannel(sChannelName, "", autoPrefix);
+ joinChannels(extractChannels(channel).toArray(new ChannelJoinRequest[0]));
}
/** {@inheritDoc} */
@Override
public void joinChannel(final String channel, final String key) {
- joinChannel(channel, key, true);
+ joinChannels(new ChannelJoinRequest(channel, key));
}
/**
@@ -1497,35 +1510,26 @@ public class IRCParser implements SecureParser, Runnable {
* @param key Key to use to try and join the channel (If a list is given
* then this key will be used for any channels that do not
* specify one themselves.
- * @param autoPrefix Automatically prepend the first channel prefix defined
- * in 005 to any of the channels passsed if they are
- * otherwise invalid channels.
*/
- public void joinChannel(final String channel, final String key, final boolean autoPrefix) {
- final String[] bits = channel.split(",");
-
+ @Override
+ public void joinChannels(final ChannelJoinRequest ... channels) {
// We store a map from key->channels to allow intelligent joining of
// channels using as few JOIN commands as needed.
final Map<String, StringBuffer> joinMap = new HashMap<String, StringBuffer>();
- for (String bit : bits) {
- // Find any key for this channel
- final String[] keybits = bit.split(" ", 2);
- final String channelName = keybits[0];
- final String thisKey = (keybits.length > 1) ? keybits[1] : key;
-
+ for (ChannelJoinRequest channel : channels) {
// Make sure we have a list to put stuff in.
- StringBuffer list = joinMap.get(thisKey);
+ StringBuffer list = joinMap.get(channel.getPassword());
if (list == null) {
list = new StringBuffer();
- joinMap.put(thisKey, list);
+ joinMap.put(channel.getPassword(), list);
}
// Add the channel to the list. If the name is invalid and
// autoprefix is off we will just skip this channel.
- if (channelName.length() > 0 && (isValidChannelName(channelName) || autoPrefix)) {
+ if (!channel.getName().isEmpty()) {
if (list.length() > 0) { list.append(","); }
- if (!isValidChannelName(channelName) && autoPrefix) {
+ if (!isValidChannelName(channel.getName())) {
if (h005Info.containsKey("CHANTYPES")) {
final String chantypes = h005Info.get("CHANTYPES");
if (chantypes.isEmpty()) {
@@ -1537,7 +1541,7 @@ public class IRCParser implements SecureParser, Runnable {
list.append('#');
}
}
- list.append(channelName);
+ list.append(channel.getName());
}
}
@@ -1545,7 +1549,7 @@ public class IRCParser implements SecureParser, Runnable {
final String thisKey = entrySet.getKey();
final String channelString = entrySet.getValue().toString();
if (!channelString.isEmpty()) {
- if (thisKey.isEmpty()) {
+ if (thisKey == null || thisKey.isEmpty()) {
sendString("JOIN " + channelString);
} else {
sendString("JOIN " + channelString + " " + thisKey);
Click to Expand/Collapse
diff src/com/dmdirc/parser/irc/Process001.java
@@ -71,7 +71,7 @@ public class Process001 extends IRCProcessor {
final String channels = myParser.server.getChannels();
if (channels != null) {
- myParser.joinChannel(channels, true);
+ myParser.joinChannel(channels);
}
}

Issue History

Date Modified Username Field Change
2010-01-24 01:54 Greboid New Issue
2010-01-24 01:54 Greboid Status new => assigned
2010-01-24 01:54 Greboid Assigned To => MD87
2010-01-27 21:52 MD87 Relationship added depends on 0003641
2010-01-27 21:52 MD87 Needs unit test => no
2010-01-27 21:52 MD87 Target Version 0.6.3 => 0.6.4
2010-03-07 14:15 Version Control Checkin
2010-03-07 14:15 Version Control Note Added: 0010161
2010-03-07 14:16 Version Control Checkin
2010-03-07 14:16 Version Control Note Added: 0010163
2010-03-07 14:24 Version Control Checkin
2010-03-07 14:24 Version Control Note Added: 0010167
2010-03-07 14:24 Version Control Status assigned => fix pending
2010-03-07 14:24 Version Control Checkin
2010-03-07 14:24 Version Control Note Added: 0010171
2010-03-07 14:31 Version Control Checkin
2010-03-07 14:31 Version Control Note Added: 0010178
2010-03-07 19:15 MD87 Checkin
2010-03-07 19:15 MD87 Note Added: 0010191
2010-03-07 19:15 MD87 Checkin
2010-03-07 19:15 MD87 Note Added: 0010192
2010-03-07 19:15 MD87 Status fix pending => resolved
2010-03-07 19:15 MD87 Resolution open => fixed
2010-03-07 19:16 MD87 Checkin
2010-03-07 19:16 MD87 Note Added: 0010198