Skip to content

Commit

Permalink
fix: isActiveChannel is false if channel is auto selected
Browse files Browse the repository at this point in the history
  • Loading branch information
Silthus committed Feb 17, 2022
1 parent 567eedb commit 0c00efe
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion core/src/main/java/net/silthus/schat/chatter/Chatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ static Builder chatter(@NonNull Identity identity) {

void activeChannel(@Nullable Channel activeChannel);

boolean isActiveChannel(@Nullable Channel channel);
default boolean isActiveChannel(@Nullable Channel channel) {
return activeChannel().map(c -> c.equals(channel)).orElse(false);
}

void join(@NonNull Channel channel);

Expand Down
5 changes: 0 additions & 5 deletions core/src/main/java/net/silthus/schat/chatter/ChatterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@ public void activeChannel(@Nullable Channel activeChannel) {
.or(Iterators.tryGetFirstIn(channels));
}

@Override
public boolean isActiveChannel(@Nullable Channel channel) {
return activeChannel != null && activeChannel.equals(channel);
}

@Override
public @NotNull @Unmodifiable List<Channel> channels() {
return List.copyOf(channels);
Expand Down
5 changes: 5 additions & 0 deletions core/src/test/java/net/silthus/schat/chatter/ChatterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ void then_active_channel_returns_first_channel() {
.isPresent()
.get().isEqualTo(channel);
}

@Test
void then_isActive_returns_true_for_selected_channel() {
assertThat(chatter.isActiveChannel(channel)).isTrue();
}
}

@Nested class given_valid_channel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.junit.jupiter.api.Test;

import static net.silthus.schat.channel.ChannelHelper.channelWith;
import static net.silthus.schat.channel.ChannelHelper.randomChannel;
import static net.silthus.schat.channel.ChannelRepository.createInMemoryChannelRepository;
import static net.silthus.schat.channel.ChannelSettings.GLOBAL;
import static net.silthus.schat.channel.ChannelSettings.PRIVATE;
Expand Down Expand Up @@ -124,8 +125,10 @@ void private_channel_is_set_active() {

@Test
void given_setActive_is_false_then_private_channel_is_not_set_as_active() {
final Channel channel = randomChannel();
source.activeChannel(channel);
sendPrivateMessageBuilder(source, target, randomText()).setActive(false).execute();
assertThat(source.activeChannel()).isEmpty();
assertThat(source.isActiveChannel(channel)).isTrue();
source.assertJoinedChannel(privateChannel().key());
}

Expand Down

0 comments on commit 0c00efe

Please sign in to comment.