Skip to content
This repository was archived by the owner on Apr 30, 2024. It is now read-only.

Commit 38ead3f

Browse files
committed
Improve message history loading.
1 parent 04678f7 commit 38ead3f

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src/Quarrel.ViewModels/Extensions/System.Collections.ObjectModel/ObservableRangeCollection.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ public void InsertRange(int index, IEnumerable<T> collection, NotifyCollectionCh
7878
OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
7979
if (changedItems.Count > 0)
8080
{
81-
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, changedItems, index));
81+
for (int i = changedItems.Count-1; i >= 0; i--)
82+
{
83+
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, new List<T>{ changedItems[i] }, index));
84+
}
8285
}
8386
}
8487

src/Quarrel.ViewModels/ViewModels/Panels/MessagesViewModel.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,28 @@ public bool IsLoading
8181
public async void LoadOlderMessages()
8282
{
8383
if (Source.Count == 0) return;
84-
84+
if (IsLoading) return;
8585
await _semaphore.WaitAsync();
86+
IsLoading = true;
8687
try
8788
{
8889
ulong beforeId = Source[0].Message.Id;
8990
IBindableMessageChannel? channel = SelectedChannel as IBindableMessageChannel;
9091
Guard.IsNotNull(channel, nameof(channel));
9192

9293
// Load messages
93-
IsLoading = true;
9494
var messages = await _discordService.GetChannelMessagesAsync(channel, beforeId);
95-
var bindableMessages = ParseMessages(messages);
95+
if (messages.Length > 0)
96+
{
97+
var bindableMessages = ParseMessages(messages);
9698

97-
// Add messages to the UI and mark loading as finished
98-
Source.InsertRange(0, bindableMessages);
99-
IsLoading = false;
99+
// Add messages to the UI and mark loading as finished
100+
Source.InsertRange(0, bindableMessages);
101+
}
100102
}
101103
finally
102104
{
105+
IsLoading = false;
103106
_semaphore.Release();
104107
}
105108
}

src/Quarrel/DataTemplates/MessageTemplates.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
</StackPanel>
7575

7676
<StackPanel Grid.Row="1">
77-
<markdown:MessageRenderer Text="{x:Bind Message.Content, Mode=OneWay}" Context="{x:Bind}"
77+
<markdown:MessageRenderer Text="{x:Bind Content, Mode=OneWay}" Context="{x:Bind Mode=OneWay}"
7878
HorizontalAlignment="Left"/>
7979

8080
<ItemsControl ItemsSource="{x:Bind Message.Attachments}"

0 commit comments

Comments
 (0)