|
41 | 41 | import net.silthus.schat.message.Message; |
42 | 42 | import net.silthus.schat.pointer.Setting; |
43 | 43 | import net.silthus.schat.pointer.Settings; |
44 | | -import net.silthus.schat.ui.format.ChannelFormat; |
45 | 44 | import net.silthus.schat.ui.format.Format; |
46 | | -import net.silthus.schat.ui.format.MessageFormat; |
47 | 45 | import net.silthus.schat.ui.model.ChatterViewModel; |
48 | 46 | import net.silthus.schat.ui.view.View; |
49 | 47 | import org.jetbrains.annotations.NotNull; |
@@ -88,40 +86,40 @@ public final class TabbedChannelsView implements View { |
88 | 86 | .suffix(text(" |")) |
89 | 87 | .build()); |
90 | 88 |
|
91 | | - public static final Setting<MessageFormat> MESSAGE_FORMAT = setting(MessageFormat.class, "message", (view, msg) -> |
| 89 | + public static final Setting<Format> MESSAGE_FORMAT = setting(Format.class, "message", (view, msg) -> |
92 | 90 | msg.get(Message.SOURCE) |
93 | 91 | .filter(Identity.IS_NOT_NIL) |
94 | 92 | .map(identity -> identity.displayName().append(text(": "))) |
95 | 93 | .orElse(Component.empty()) |
96 | 94 | .append(msg.getOrDefault(Message.TEXT, Component.empty()))); |
97 | 95 |
|
98 | | - public static final Setting<ChannelFormat> ACTIVE_CHANNEL_FORMAT = setting(ChannelFormat.class, "active_channel", (view, channel) -> |
99 | | - channel.get(DISPLAY_NAME) |
| 96 | + public static final Setting<Format> ACTIVE_CHANNEL_FORMAT = setting(Format.class, "active_channel", (view, channel) -> |
| 97 | + channel.getOrDefault(DISPLAY_NAME, Component.empty()) |
100 | 98 | .colorIfAbsent(GREEN) |
101 | 99 | .decorate(UNDERLINED) |
102 | 100 | ); |
103 | 101 |
|
104 | | - public static final Setting<ChannelFormat> INACTIVE_CHANNEL_FORMAT = setting(ChannelFormat.class, "inactive_channel", (view, channel) -> |
105 | | - channel.getOrDefault(DISPLAY_NAME, text(channel.key())) |
| 102 | + public static final Setting<Format> INACTIVE_CHANNEL_FORMAT = setting(Format.class, "inactive_channel", (view, channel) -> |
| 103 | + channel.getOrDefault(DISPLAY_NAME, Component.empty()) |
106 | 104 | .colorIfAbsent(GRAY) |
107 | 105 | .hoverEvent(translatable("schat.hover.join-channel") |
108 | | - .args(channel.get(DISPLAY_NAME)) |
| 106 | + .args(channel.getOrDefault(DISPLAY_NAME, Component.empty())) |
109 | 107 | .color(GRAY) |
110 | 108 | ).clickEvent( |
111 | | - clickEvent(RUN_COMMAND, "/channel join " + channel.key()) |
| 109 | + clickEvent(RUN_COMMAND, "/channel join " + channel.getOrDefault(Channel.KEY, "unknown")) |
112 | 110 | ) |
113 | 111 | ); |
114 | 112 |
|
115 | 113 | public static final Settings.Builder DEFAULT_FORMAT_SETTINGS = Settings.settingsBuilder() |
116 | 114 | .withStatic(MESSAGE_FORMAT, MESSAGE_FORMAT.defaultValue()) |
117 | | - .withStatic(ACTIVE_CHANNEL_FORMAT, (view, channel) -> ACTIVE_CHANNEL_DECORATION.apply(channel.displayName())) |
118 | | - .withStatic(INACTIVE_CHANNEL_FORMAT, (view, channel) -> INACTIVE_CHANNEL_DECORATION.apply(channel, channel.displayName())); |
| 115 | + .withStatic(ACTIVE_CHANNEL_FORMAT, (view, channel) -> ACTIVE_CHANNEL_DECORATION.apply(channel.getOrDefault(DISPLAY_NAME, Component.empty()))) |
| 116 | + .withStatic(INACTIVE_CHANNEL_FORMAT, (view, channel) -> INACTIVE_CHANNEL_DECORATION.apply((Channel) channel, channel.getOrDefault(DISPLAY_NAME, Component.empty()))); |
119 | 117 |
|
120 | 118 | public static final Setting<Settings> CHANNEL_FORMAT = setting(Settings.class, "format", DEFAULT_FORMAT_SETTINGS.create()); |
121 | 119 | public static final Setting<Settings> PRIVATE_CHANNEL_FORMAT = setting(Settings.class, "private_channel_format", Settings.settingsBuilder() |
122 | | - .withStatic(MESSAGE_FORMAT, (view, message) -> renderPrivateMessage(((TabbedChannelsView) view).chatter(), message)) |
123 | | - .withStatic(ACTIVE_CHANNEL_FORMAT, (view, channel) -> ACTIVE_CHANNEL_DECORATION.apply(renderPrivateChannelName(((TabbedChannelsView) view).chatter(), channel))) |
124 | | - .withStatic(INACTIVE_CHANNEL_FORMAT, (view, channel) -> INACTIVE_CHANNEL_DECORATION.apply(channel, renderPrivateChannelName(((TabbedChannelsView) view).chatter(), channel))) |
| 120 | + .withStatic(MESSAGE_FORMAT, (view, message) -> renderPrivateMessage(((TabbedChannelsView) view).chatter(), (Message) message)) |
| 121 | + .withStatic(ACTIVE_CHANNEL_FORMAT, (view, channel) -> ACTIVE_CHANNEL_DECORATION.apply(renderPrivateChannelName(((TabbedChannelsView) view).chatter(), (Channel) channel))) |
| 122 | + .withStatic(INACTIVE_CHANNEL_FORMAT, (view, channel) -> INACTIVE_CHANNEL_DECORATION.apply((Channel) channel, renderPrivateChannelName(((TabbedChannelsView) view).chatter(), (Channel) channel))) |
125 | 123 | .create() |
126 | 124 | ); |
127 | 125 |
|
@@ -218,11 +216,11 @@ private boolean isMessageDisplayed(Message message) { |
218 | 216 | public class Tab { |
219 | 217 | private final Channel channel; |
220 | 218 |
|
221 | | - private Format<Message> messageFormat; |
222 | | - private Format<Channel> activeFormat; |
223 | | - private Format<Channel> inactiveFormat; |
| 219 | + private Format messageFormat; |
| 220 | + private Format activeFormat; |
| 221 | + private Format inactiveFormat; |
224 | 222 |
|
225 | | - protected Tab(Channel channel, Format<Message> messageFormat, Format<Channel> activeFormat, Format<Channel> inactiveFormat) { |
| 223 | + protected Tab(Channel channel, Format messageFormat, Format activeFormat, Format inactiveFormat) { |
226 | 224 | this.channel = channel; |
227 | 225 |
|
228 | 226 | this.messageFormat = messageFormat; |
|
0 commit comments