Skip to content

Commit

Permalink
fix: unsubscribe all from channel when removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Silthus committed Nov 13, 2021
1 parent 31db6dc commit f6e3ed1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public boolean contains(Channel channel) {
}

public void clear() {
channels.values().forEach(channel -> channel.getTargets().forEach(target -> target.unsubscribe(channel)));
channels.clear();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.silthus.chat.TestBase;
import net.silthus.chat.config.ChannelConfig;
import net.silthus.chat.config.PluginConfig;
import net.silthus.chat.identities.Chatter;
import org.bukkit.configuration.MemoryConfiguration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
Expand Down Expand Up @@ -268,6 +269,18 @@ private Channel addChannel(String identifier) {
return channel;
}

@Test
void clear_unsubscribesAllFromChannel() {
final Channel foobar = createChannel("foobar");
registry.add(foobar);
final Chatter chatter = Chatter.of(server.addPlayer());
chatter.subscribe(foobar);

assertThat(chatter.getConversations()).contains(foobar);
registry.clear();
assertThat(chatter.getConversations()).doesNotContain(foobar);
}

@Nested
class Load {

Expand Down

0 comments on commit f6e3ed1

Please sign in to comment.