Show and control channel subscriptions
Track the subscription state from the notifychannelsubscribed events, draw subscribed and unsubscribed channels apart with the pack's icons (and the built-in glyph as a hollow cone), and offer subscribe/unsubscribe entries — channel and family — in the channel context menu. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,9 +20,47 @@ final class ChannelMenu {
|
||||
join.addActionListener(a -> actions.joinChannel(channel.id));
|
||||
menu.add(join);
|
||||
menu.addSeparator();
|
||||
addSubscriptionItems(menu, channel, actions);
|
||||
JMenuItem files = new JMenuItem("Browse files", Icons.of("FILETRANSFER"));
|
||||
files.addActionListener(a -> actions.browseFiles(channel));
|
||||
menu.add(files);
|
||||
return menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* The subscription entries, offered the way the official client does: the channel
|
||||
* itself toggles, and the family entries appear only where they would do something.
|
||||
*/
|
||||
private static void addSubscriptionItems(JPopupMenu menu, ChannelNode channel,
|
||||
ServerTreePanel.Actions actions) {
|
||||
if (channel.subscribed) {
|
||||
add(menu, "Unsubscribe from Channel",
|
||||
() -> actions.setChannelSubscribed(channel, false, false),
|
||||
"UNSUBSCRIBE_FROM_CHANNEL");
|
||||
} else {
|
||||
add(menu, "Subscribe to Channel",
|
||||
() -> actions.setChannelSubscribed(channel, false, true),
|
||||
"SUBSCRIBE_TO_CHANNEL");
|
||||
}
|
||||
if (!channel.children.isEmpty()) {
|
||||
if (!channel.allSubscribed()) {
|
||||
add(menu, "Subscribe to Channel Family",
|
||||
() -> actions.setChannelSubscribed(channel, true, true),
|
||||
"SUBSCRIBE_TO_CHANNEL_FAMILY", "SUBSCRIBE_TO_ALL_CHANNELS");
|
||||
}
|
||||
if (channel.anySubscribed()) {
|
||||
add(menu, "Unsubscribe from Channel Family",
|
||||
() -> actions.setChannelSubscribed(channel, true, false),
|
||||
"UNSUBSCRIBE_FROM_CHANNEL_FAMILY", "UNSUBSCRIBE_FROM_ALL_CHANNELS");
|
||||
}
|
||||
}
|
||||
menu.addSeparator();
|
||||
}
|
||||
|
||||
/** Adds an item, icon-less when the pack has none of the given keys. */
|
||||
private static void add(JPopupMenu menu, String text, Runnable action, String... iconKeys) {
|
||||
JMenuItem item = new JMenuItem(text, Icons.ofAny(iconKeys));
|
||||
item.addActionListener(a -> action.run());
|
||||
menu.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user