- Support locked channels

- Implement render limit for webinterface [default 1000]
This commit is contained in:
Infi
2024-09-02 12:46:09 +02:00
parent a9da2cafc2
commit 725fe449f8
9 changed files with 60 additions and 14 deletions
@@ -6,9 +6,10 @@ namespace ChatTwo.Http.MessageProtocol;
/// <summary>
/// Contains the current channel name
/// </summary>
public struct SwitchChannel(MessageTemplate[] channelName)
public struct SwitchChannel((MessageTemplate[] ChannelName, bool Locked) channel)
{
[JsonProperty("channelName")] public MessageTemplate[] ChannelName = channelName;
[JsonProperty("channelName")] public MessageTemplate[] ChannelName = channel.ChannelName;
[JsonProperty("channelLocked")] public bool Locked = channel.Locked;
}
/// <summary>
+6 -5
View File
@@ -15,15 +15,16 @@ public class Processing
Plugin = plugin;
}
internal MessageTemplate[] ReadChannelName(Chunk[] channelName)
internal (MessageTemplate[] ChannelName, bool Locked) ReadChannelName(Chunk[] channelName)
{
return channelName.Select(ProcessChunk).ToArray();
var locked = Plugin.ChatLogWindow.CurrentTab is not { Channel: null };
return (channelName.Select(ProcessChunk).ToArray(), locked);
}
internal async Task<MessageResponse[]> ReadMessageList()
{
var tabMessages = await Plugin.ChatLogWindow.CurrentTab!.Messages.GetCopy();
return tabMessages.Select(ReadMessageContent).ToArray();
return tabMessages.TakeLast(Plugin.Config.WebinterfaceMaxLinesToSend).Select(ReadMessageContent).ToArray();
}
internal MessageResponse ReadMessageContent(Message message)
@@ -44,11 +45,11 @@ public class Processing
{
var messages = await WebserverUtil.FrameworkWrapper(ReadMessageList);
var channels = await Plugin.Framework.RunOnTick(Plugin.ChatLogWindow.GetAvailableChannels);
var channelName = await Plugin.Framework.RunOnTick(() => ReadChannelName(Plugin.ChatLogWindow.PreviousChannel));
var channel = await Plugin.Framework.RunOnTick(() => ReadChannelName(Plugin.ChatLogWindow.PreviousChannel));
// Using the bulk message event to clear everything on the client side that may still exist
sse.OutboundQueue.Enqueue(new BulkMessagesEvent(new Messages(messages)));
sse.OutboundQueue.Enqueue(new SwitchChannelEvent(new SwitchChannel(channelName)));
sse.OutboundQueue.Enqueue(new SwitchChannelEvent(new SwitchChannel(channel)));
sse.OutboundQueue.Enqueue(new ChannelListEvent(new ChannelList(channels.ToDictionary(pair => pair.Key, pair => (uint)pair.Value))));
}
+16 -3
View File
@@ -20,6 +20,7 @@
};
this.maxTimestampWidth = 0;
this.scrolledToBottom = true;
this.channelLocked = false;
// channel selector
@@ -72,9 +73,21 @@
});
}
updateChannelHint(templates) {
updateChannelHint(channel) {
this.elements.channelHint.innerHTML = '';
this.elements.channelHint.appendChild(this.processTemplate(templates));
const channelElement = this.processTemplate(channel.channelName);
// Makes the channel selector unclickable if the channel is fixed
this.channelLocked = channel.channelLocked;
if (this.channelLocked) {
channelElement.firstChild.innerText = `(Locked) ${channelElement.firstChild.innerText}`;
this.elements.channelSelect.style.pointerEvents = 'none';
} else {
this.elements.channelSelect.style.pointerEvents = 'auto';
}
this.elements.channelHint.appendChild(channelElement);
}
updateChannels(channels) {
@@ -228,7 +241,7 @@
this.sse.addEventListener('switch-channel', (event) => {
try {
this.updateChannelHint(JSON.parse(event.data).channelName);
this.updateChannelHint(JSON.parse(event.data));
} catch (error) {
console.error(error);
}