feat(desktop): limit local messages stored
This commit is contained in:
parent
900fa642a0
commit
033d4add13
|
@ -8,6 +8,7 @@
|
|||
<ResourceDictionary>
|
||||
<local:DoubleConverter x:Key="DoubleConverter" />
|
||||
<local:UShortConverter x:Key="UShortConverter" />
|
||||
<local:UIntConverter x:Key="UIntConverter" />
|
||||
<local:SenderPlayerConverter x:Key="SenderPlayerConverter" />
|
||||
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<TabItem Header="Window">
|
||||
<Grid Margin="8">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
|
@ -43,8 +44,15 @@
|
|||
Text="{Binding Config.FontSize, Converter={StaticResource DoubleConverter}}"
|
||||
ui:ControlHelper.Header="Log font size"
|
||||
Width="200" />
|
||||
<TextBox Grid.Row="2"
|
||||
Grid.Column="0"
|
||||
ui:ControlHelper.Header="Messages to store locally"
|
||||
HorizontalAlignment="Left"
|
||||
PreviewTextInput="NumericInputFilter"
|
||||
Text="{Binding Config.LocalBacklogMessages, Converter={StaticResource UIntConverter}}"
|
||||
Width="200" />
|
||||
|
||||
<Button Grid.Row="3"
|
||||
<Button Grid.Row="4"
|
||||
HorizontalAlignment="Right"
|
||||
Click="Save_Click">
|
||||
Save
|
||||
|
|
|
@ -37,6 +37,8 @@ namespace XIVChat_Desktop {
|
|||
|
||||
public ushort BacklogMessages { get; set; } = 500;
|
||||
|
||||
public uint LocalBacklogMessages { get; set; } = 10_000;
|
||||
|
||||
#region io
|
||||
|
||||
private static string FilePath() => Path.Join(
|
||||
|
@ -156,6 +158,10 @@ namespace XIVChat_Desktop {
|
|||
this.CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, messages, index));
|
||||
}
|
||||
|
||||
private void NotifyRemoveItemsAt(IList messages, int index) {
|
||||
this.CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, messages, index));
|
||||
}
|
||||
|
||||
public void RepopulateMessages(IEnumerable<ServerMessage> mainMessages) {
|
||||
this.Messages.Clear();
|
||||
|
||||
|
@ -170,7 +176,7 @@ namespace XIVChat_Desktop {
|
|||
private int lastSequence = -1;
|
||||
private int insertAt;
|
||||
|
||||
public void AddReversedChunk(ServerMessage[] messages, int sequence) {
|
||||
public void AddReversedChunk(ServerMessage[] messages, int sequence, Configuration config) {
|
||||
if (sequence != this.lastSequence) {
|
||||
this.lastSequence = sequence;
|
||||
this.insertAt = this.Messages.Count;
|
||||
|
@ -181,17 +187,31 @@ namespace XIVChat_Desktop {
|
|||
.ToList();
|
||||
|
||||
this.Messages.InsertRange(this.insertAt, filtered);
|
||||
|
||||
this.NotifyAddItemsAt(filtered, this.insertAt);
|
||||
|
||||
this.Prune(config);
|
||||
}
|
||||
|
||||
public void AddMessage(ServerMessage message) {
|
||||
public void AddMessage(ServerMessage message, Configuration config) {
|
||||
if (message.Channel != 0 && !this.Filter.Allowed(message)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.Messages.Add(message);
|
||||
this.NotifyAdd(message);
|
||||
|
||||
this.Prune(config);
|
||||
}
|
||||
|
||||
private void Prune(Configuration config) {
|
||||
var diff = this.Messages.Count - config.LocalBacklogMessages;
|
||||
if (diff <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var removed = this.Messages.Take((int)diff).ToList();
|
||||
this.Messages.RemoveRange(0, (int)diff);
|
||||
this.NotifyRemoveItemsAt(removed, 0);
|
||||
}
|
||||
|
||||
public void ClearMessages() {
|
||||
|
|
|
@ -33,6 +33,20 @@ namespace XIVChat_Desktop {
|
|||
}
|
||||
}
|
||||
|
||||
public class UIntConverter : IValueConverter {
|
||||
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
return value.ToString();
|
||||
}
|
||||
|
||||
public object? ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (uint.TryParse(value.ToString(), out var res)) {
|
||||
return res;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class SenderPlayerConverter : IValueConverter {
|
||||
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (!(value is ServerMessage.SenderPlayer sender)) {
|
||||
|
|
|
@ -87,7 +87,12 @@ namespace XIVChat_Desktop {
|
|||
this.Messages.InsertRange(this.insertAt, messages);
|
||||
// add message to each tab if the filter allows for it
|
||||
foreach (var tab in this.App.Config.Tabs) {
|
||||
tab.AddReversedChunk(messages, sequence);
|
||||
tab.AddReversedChunk(messages, sequence, this.App.Config);
|
||||
}
|
||||
|
||||
var diff = this.Messages.Count - this.App.Config.LocalBacklogMessages;
|
||||
if (diff > 0) {
|
||||
this.Messages.RemoveRange(0, (int)diff);
|
||||
}
|
||||
|
||||
// scroll to the bottom if previously at the bottom
|
||||
|
@ -105,7 +110,12 @@ namespace XIVChat_Desktop {
|
|||
this.Messages.Add(message);
|
||||
// add message to each tab if the filter allows for it
|
||||
foreach (var tab in this.App.Config.Tabs) {
|
||||
tab.AddMessage(message);
|
||||
tab.AddMessage(message, this.App.Config);
|
||||
}
|
||||
|
||||
var diff = this.Messages.Count - this.App.Config.LocalBacklogMessages;
|
||||
if (diff > 0) {
|
||||
this.Messages.RemoveRange(0, (int)diff);
|
||||
}
|
||||
|
||||
// scroll to the bottom if previously at the bottom
|
||||
|
|
Loading…
Reference in New Issue
Block a user