Skip to content

Commit

Permalink
Merge pull request #503 from csmith/master
Browse files Browse the repository at this point in the history
Replace Channel with GroupChat in commands.
  • Loading branch information
greboid committed Jan 15, 2015
2 parents a82a17c + d629b64 commit 18c6191
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 61 deletions.
12 changes: 4 additions & 8 deletions src/com/dmdirc/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ public void resetWindow() {

// Needs to be published synchronously so that nicklists are cleared before the parser
// is disconnected (which happens synchronously after this method returns).
getEventBus().publish(new NickListClientsChangedEvent(this,
Collections.<GroupChatUser>emptyList()));
getEventBus().publish(
new NickListClientsChangedEvent(this, Collections.<GroupChatUser>emptyList()));
}

@Override
Expand Down Expand Up @@ -327,8 +327,7 @@ public void addClient(final GroupChatUser client) {
public void removeClient(final GroupChatUser client) {
getEventBus().publishAsync(new NickListClientRemovedEvent(this, client));

getTabCompleter().removeEntry(TabCompletionType.CHANNEL_NICK,
client.getNickname());
getTabCompleter().removeEntry(TabCompletionType.CHANNEL_NICK, client.getNickname());

if (client.getUser().equals(connection.getLocalUser().orElse(null))) {
resetWindow();
Expand Down Expand Up @@ -361,10 +360,7 @@ public void renameClient(final String oldName, final String newName) {
refreshClients();
}

/**
* Refreshes the list of clients stored by this channel. Should be called when (visible) user
* modes or nicknames change.
*/
@Override
public void refreshClients() {
if (!isOnChannel) {
return;
Expand Down
8 changes: 4 additions & 4 deletions src/com/dmdirc/commandparser/commands/channel/Ban.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

package com.dmdirc.commandparser.commands.channel;

import com.dmdirc.Channel;
import com.dmdirc.FrameContainer;
import com.dmdirc.commandparser.BaseCommandInfo;
import com.dmdirc.commandparser.CommandArguments;
Expand All @@ -33,6 +32,7 @@
import com.dmdirc.commandparser.commands.context.ChannelCommandContext;
import com.dmdirc.commandparser.commands.context.CommandContext;
import com.dmdirc.interfaces.CommandController;
import com.dmdirc.interfaces.GroupChat;
import com.dmdirc.interfaces.GroupChatUser;
import com.dmdirc.ui.input.AdditionalTabTargets;
import com.dmdirc.ui.input.TabCompletionType;
Expand Down Expand Up @@ -63,7 +63,7 @@ public Ban(final CommandController controller) {
@Override
public void execute(@Nonnull final FrameContainer origin,
final CommandArguments args, final CommandContext context) {
final Channel channel = ((ChannelCommandContext) context).getChannel();
final GroupChat channel = ((ChannelCommandContext) context).getGroupChat();

if (args.getArguments().length == 0) {
showUsage(origin, args.isSilent(), INFO.getName(), INFO.getHelp());
Expand All @@ -79,8 +79,8 @@ public void execute(@Nonnull final FrameContainer origin,
host = "*!*@" + hostname;
}

channel.getChannelInfo().alterMode(true, 'b', host);
channel.getChannelInfo().flushModes();
channel.setMode('b', host);
channel.flushModes();
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/com/dmdirc/commandparser/commands/channel/Cycle.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Cycle(final CommandController controller) {
@Override
public void execute(@Nonnull final FrameContainer origin,
final CommandArguments args, final CommandContext context) {
final GroupChat channel = ((ChannelCommandContext) context).getChannel();
final GroupChat channel = ((ChannelCommandContext) context).getGroupChat();
channel.part(args.getArguments().length > 0 ? args.getArgumentsAsString()
: origin.getConfigManager().getOption("general", "cyclemessage"));
channel.join();
Expand Down
2 changes: 1 addition & 1 deletion src/com/dmdirc/commandparser/commands/channel/Invite.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void execute(@Nonnull final FrameContainer origin,
sendLine(origin, args.isSilent(), FORMAT_ERROR,
"Insufficient arguments: must specify user");
} else {
final GroupChat groupChat = ((ChannelCommandContext) context).getChannel();
final GroupChat groupChat = ((ChannelCommandContext) context).getGroupChat();
groupChat.getConnection().flatMap(Connection::getParser)
.ifPresent(p -> p.sendInvite(groupChat.getName(), args.getArgumentsAsString()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public KickReason(final CommandController controller) {
@Override
public void execute(@Nonnull final FrameContainer origin,
final CommandArguments args, final CommandContext context) {
final GroupChat groupChat = ((ChannelCommandContext) context).getChannel();
final GroupChat groupChat = ((ChannelCommandContext) context).getGroupChat();
if (args.getArguments().length == 0) {
showUsage(origin, args.isSilent(), "kick", "<user> [reason]");
return;
Expand Down
10 changes: 4 additions & 6 deletions src/com/dmdirc/commandparser/commands/channel/Mode.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

package com.dmdirc.commandparser.commands.channel;

import com.dmdirc.Channel;
import com.dmdirc.FrameContainer;
import com.dmdirc.commandparser.BaseCommandInfo;
import com.dmdirc.commandparser.CommandArguments;
Expand All @@ -36,7 +35,7 @@
import com.dmdirc.commandparser.commands.context.CommandContext;
import com.dmdirc.interfaces.CommandController;
import com.dmdirc.interfaces.Connection;
import com.dmdirc.parser.interfaces.ChannelInfo;
import com.dmdirc.interfaces.GroupChat;
import com.dmdirc.ui.input.AdditionalTabTargets;
import com.dmdirc.ui.input.TabCompletionType;

Expand Down Expand Up @@ -68,14 +67,13 @@ public Mode(final CommandController controller) {
@Override
public void execute(@Nonnull final FrameContainer origin,
final CommandArguments args, final CommandContext context) {
final Channel channel = ((ChannelCommandContext) context).getChannel();
final ChannelInfo cChannel = channel.getChannelInfo();
final GroupChat channel = ((ChannelCommandContext) context).getGroupChat();

if (args.getArguments().length == 0) {
sendLine(origin, args.isSilent(), "channelModeDiscovered", cChannel.getModes(), cChannel);
sendLine(origin, args.isSilent(), "channelModeDiscovered", channel.getModes(), channel);
} else {
channel.getConnection().get().getParser().get().sendRawMessage("MODE "
+ cChannel + " " + args.getArgumentsAsString());
+ channel.getName() + ' ' + args.getArgumentsAsString());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/com/dmdirc/commandparser/commands/channel/Names.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Names(final CommandController controller) {
@Override
public void execute(@Nonnull final FrameContainer origin,
final CommandArguments args, final CommandContext context) {
final GroupChat channel = ((ChannelCommandContext) context).getChannel();
final GroupChat channel = ((ChannelCommandContext) context).getGroupChat();
channel.getConnection().get().getParser().get().sendRawMessage("NAMES "
+ channel.getName());
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/dmdirc/commandparser/commands/channel/Part.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Part(final CommandController controller) {
@Override
public void execute(@Nonnull final FrameContainer origin,
final CommandArguments args, final CommandContext context) {
final GroupChat channel = ((ChannelCommandContext) context).getChannel();
final GroupChat channel = ((ChannelCommandContext) context).getGroupChat();
channel.part(args.getArguments().length > 0 ? args.getArgumentsAsString()
: origin.getConfigManager().getOption("general", "partmessage"));
channel.getWindowModel().close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

package com.dmdirc.commandparser.commands.channel;

import com.dmdirc.Channel;
import com.dmdirc.FrameContainer;
import com.dmdirc.commandparser.BaseCommandInfo;
import com.dmdirc.commandparser.CommandArguments;
Expand All @@ -34,6 +33,7 @@
import com.dmdirc.commandparser.commands.context.CommandContext;
import com.dmdirc.events.DisplayProperty;
import com.dmdirc.interfaces.CommandController;
import com.dmdirc.interfaces.GroupChat;
import com.dmdirc.interfaces.GroupChatUser;
import com.dmdirc.ui.input.AdditionalTabTargets;
import com.dmdirc.ui.input.TabCompletionType;
Expand Down Expand Up @@ -73,7 +73,7 @@ public SetNickColour(final CommandController controller,
@Override
public void execute(@Nonnull final FrameContainer origin,
final CommandArguments args, final CommandContext context) {
final Channel channel = ((ChannelCommandContext) context).getChannel();
final GroupChat channel = ((ChannelCommandContext) context).getGroupChat();

if (args.getArguments().length == 0) {
showUsage(origin, args.isSilent(), INFO.getName(), INFO.getHelp());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public ShowTopic(final CommandController controller) {
@Override
public void execute(@Nonnull final FrameContainer origin,
final CommandArguments args, final CommandContext context) {
final GroupChat channel = ((ChannelCommandContext) context).getChannel();
final GroupChat channel = ((ChannelCommandContext) context).getGroupChat();
if (args.getArguments().length == 0) {
final Optional<Topic> topic = channel.getCurrentTopic();
if (topic.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

package com.dmdirc.commandparser.commands.context;

import com.dmdirc.Channel;
import com.dmdirc.FrameContainer;
import com.dmdirc.commandparser.CommandInfo;
import com.dmdirc.interfaces.GroupChat;

/**
* A specialised {@link CommandContext} for commands executed in channels.
Expand All @@ -33,29 +33,29 @@
*/
public class ChannelCommandContext extends ChatCommandContext {

/** The channel associated with the command. */
private final Channel channel;
/** The group chat associated with the command. */
private final GroupChat groupChat;

/**
* Creates a new channel command context.
* Creates a new group chat command context.
*
* @param source The source of the command
* @param commandInfo The command info object which associated the command with the input
* @param channel The channel associated with the command
* @param groupChat The group chat associated with the command
*/
public ChannelCommandContext(final FrameContainer source,
final CommandInfo commandInfo, final Channel channel) {
super(source, commandInfo, channel);
this.channel = channel;
final CommandInfo commandInfo, final GroupChat groupChat) {
super(source, commandInfo, groupChat);
this.groupChat = groupChat;
}

/**
* Retrieves the channel associated with this context.
* Retrieves the group chat associated with this context.
*
* @return This context's channel
* @return This context's group chat
*/
public Channel getChannel() {
return channel;
public GroupChat getGroupChat() {
return groupChat;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void execute(@Nonnull final FrameContainer origin,
return;
}

final GroupChat groupChat = ((ChannelCommandContext) context).getChannel();
final GroupChat groupChat = ((ChannelCommandContext) context).getGroupChat();
identity = identityFactory.createChannelConfig(connection.get().getNetwork(),
groupChat.getName());
manager = groupChat.getWindowModel().getConfigManager();
Expand Down
18 changes: 9 additions & 9 deletions src/com/dmdirc/commandparser/parsers/ChannelCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

package com.dmdirc.commandparser.parsers;

import com.dmdirc.Channel;
import com.dmdirc.DMDircMBassador;
import com.dmdirc.FrameContainer;
import com.dmdirc.commandparser.CommandArguments;
Expand All @@ -32,6 +31,7 @@
import com.dmdirc.commandparser.commands.context.ChannelCommandContext;
import com.dmdirc.commandparser.commands.context.CommandContext;
import com.dmdirc.interfaces.CommandController;
import com.dmdirc.interfaces.GroupChat;

import javax.annotation.Nonnull;

Expand All @@ -42,10 +42,8 @@ public class ChannelCommandParser extends ChatCommandParser {

/** A version number for this class. */
private static final long serialVersionUID = 1;
/**
* The channel instance that this parser is attached to.
*/
private Channel channel;
/** The group chat instance that this parser is attached to. */
private GroupChat groupChat;

/**
* Creates a new instance of ChannelCommandParser.
Expand All @@ -54,15 +52,17 @@ public class ChannelCommandParser extends ChatCommandParser {
* @param commandController The controller to load commands from.
* @param eventBus Event bus to post events on
*/
public ChannelCommandParser(final FrameContainer owner, final CommandController commandController,
public ChannelCommandParser(final FrameContainer owner,
final CommandController commandController,
final DMDircMBassador eventBus) {
super(owner, commandController, eventBus);
}

@Override
public void setOwner(final FrameContainer owner) {
if (channel == null) {
channel = (Channel) owner;
if (groupChat == null) {
// TODO: Can't assume that framecontainers may be group chats.
groupChat = (GroupChat) owner;
}

super.setOwner(owner);
Expand All @@ -80,7 +80,7 @@ protected CommandContext getCommandContext(
final CommandInfo commandInfo,
final Command command,
final CommandArguments args) {
return new ChannelCommandContext(origin, commandInfo, channel);
return new ChannelCommandContext(origin, commandInfo, groupChat);
}

@Override
Expand Down
7 changes: 7 additions & 0 deletions src/com/dmdirc/interfaces/GroupChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ public interface GroupChat extends Chat {
*/
int getMaxTopicLength();

/**
* Refreshes the list of clients stored by this channel. Should be called when (visible) user
* modes or nicknames change.
*/
// TODO: Should probably not need this.
void refreshClients();

/**
* Retrieve the topics that have been seen on this channel.
*
Expand Down
11 changes: 4 additions & 7 deletions test/com/dmdirc/commandparser/commands/channel/BanTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.dmdirc.interfaces.Connection;
import com.dmdirc.interfaces.GroupChatUser;
import com.dmdirc.interfaces.User;
import com.dmdirc.parser.interfaces.ChannelInfo;

import java.util.Optional;

Expand All @@ -56,12 +55,10 @@ public class BanTest {
@Mock private Channel channel;
@Mock private CommandController controller;
@Mock private FrameContainer container;
@Mock private ChannelInfo channelInfo;
private Ban command;

@Before
public void setup() {
when(channel.getChannelInfo()).thenReturn(channelInfo);
when(channel.getConnection()).thenReturn(Optional.of(connection));
when(connection.getUser("user")).thenReturn(user1);
when(connection.getUser("*!*@my.host.name")).thenReturn(user2);
Expand All @@ -87,8 +84,8 @@ public void testKnownUser() {
command.execute(container, new CommandArguments(controller, "/ban user"),
new ChannelCommandContext(null, Ban.INFO, channel));

verify(channelInfo).alterMode(true, 'b', "*!*@HOSTNAME");
verify(channelInfo).flushModes();
verify(channel).setMode('b', "*!*@HOSTNAME");
verify(channel).flushModes();
}

/** Tests that the ban command works if given a mask not a username. */
Expand All @@ -97,7 +94,7 @@ public void testHostmask() {
command.execute(container, new CommandArguments(controller, "/ban *!*@my.host.name"),
new ChannelCommandContext(null, Ban.INFO, channel));

verify(channelInfo).alterMode(true, 'b', "*!*@my.host.name");
verify(channelInfo).flushModes();
verify(channel).setMode('b', "*!*@my.host.name");
verify(channel).flushModes();
}
}
9 changes: 3 additions & 6 deletions test/com/dmdirc/commandparser/commands/channel/ModeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.dmdirc.config.InvalidIdentityFileException;
import com.dmdirc.interfaces.CommandController;
import com.dmdirc.interfaces.Connection;
import com.dmdirc.parser.interfaces.ChannelInfo;
import com.dmdirc.parser.interfaces.Parser;

import java.util.Optional;
Expand All @@ -48,7 +47,6 @@ public class ModeTest {

@Mock private FrameContainer origin;
@Mock private CommandController controller;
@Mock private ChannelInfo channelinfo;
@Mock private Channel channel;
@Mock private Connection connection;
@Mock private Parser parser;
Expand All @@ -58,9 +56,8 @@ public class ModeTest {
public void setUp() throws InvalidIdentityFileException {
when(channel.getConnection()).thenReturn(Optional.of(connection));
when(connection.getParser()).thenReturn(Optional.of(parser));
when(channel.getChannelInfo()).thenReturn(channelinfo);
when(channelinfo.getModes()).thenReturn("my mode string!");
when(channelinfo.toString()).thenReturn("#chan");
when(channel.getModes()).thenReturn("my mode string!");
when(channel.getName()).thenReturn("#chan");

command = new Mode(controller);
}
Expand All @@ -70,7 +67,7 @@ public void testWithoutArgs() {
command.execute(origin, new CommandArguments(controller, "/mode"),
new ChannelCommandContext(null, Mode.INFO, channel));

verify(origin).addLine("channelModeDiscovered", "my mode string!", channelinfo);
verify(origin).addLine("channelModeDiscovered", "my mode string!", channel);
}

@Test
Expand Down

0 comments on commit 18c6191

Please sign in to comment.