Skip to content

Commit 312d4b1

Browse files
committed
Merge branch 'master' into redesign
2 parents d208656 + d4b9703 commit 312d4b1

File tree

6 files changed

+36
-12
lines changed

6 files changed

+36
-12
lines changed

Signal-Windows/Controls/VirtualizedMessagesCollection.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Signal_Windows.Models;
1+
using Signal_Windows.Models;
22
using Signal_Windows.Storage;
33
using System;
44
using System.Collections;
@@ -67,16 +67,28 @@ public object this[int index]
6767

6868
public object SyncRoot => this;
6969

70+
/// <summary>
71+
/// "Adds" a SignalMessageContainer to this virtualized collection.</summary>
72+
/// <remarks>
73+
/// The method may (if incoming) or may not (if outgoing) already be present in the database, so we explicitly insert at the correct position in the cache line.
74+
/// Count is mapped to the SignalConversation's MessagesCount, so callers must update appropriately before calling this method, and no async method must be called in between.</remarks>
75+
/// <param name="value">The object to add to the VirtualizedMessagesCollection.</param>
76+
/// <returns>The position into which the new element was inserted, or -1 to indicate that the item was not inserted into the collection.</returns>
7077
public int Add(object value)
7178
{
7279
var message = value as SignalMessageContainer;
7380
int inpageIndex = message.Index % PAGE_SIZE;
7481
int pageIndex = GetPageIndex(message.Index);
82+
Debug.WriteLine($"VirtualizedCollection.Add Id={message.Message.Id} Index={message.Index} PageIndex={pageIndex} InpageIndex={inpageIndex} ");
7583
if (!Cache.ContainsKey(pageIndex))
7684
{
7785
Cache[pageIndex] = SignalDBContext.GetMessagesLocked(Conversation, pageIndex * PAGE_SIZE, PAGE_SIZE);
7886
}
79-
Cache[pageIndex].Add(message);
87+
Cache[pageIndex].Insert(inpageIndex, message);
88+
if (Cache[pageIndex].IndexOf(message) != inpageIndex || message.Index != Count-1)
89+
{
90+
throw new InvalidOperationException("VirtualizedCollection is in an inconsistent state!");
91+
}
8092
CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, message, message.Index));
8193
return message.Index;
8294
}

Signal-Windows/Package.appxmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp">
3-
<Identity Name="d77d01c7-0786-44e4-9ef4-dd3cde64124b" Publisher="CN=Benni" Version="0.1.8.0" />
3+
<Identity Name="d77d01c7-0786-44e4-9ef4-dd3cde64124b" Publisher="CN=Benni" Version="0.1.9.0" />
44
<mp:PhoneIdentity PhoneProductId="d77d01c7-0786-44e4-9ef4-dd3cde64124b" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
55
<Properties>
66
<DisplayName>Signal-Windows</DisplayName>

Signal-Windows/Signal-Windows.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
1919
<WindowsXamlEnableOverview>true</WindowsXamlEnableOverview>
2020
<PackageCertificateKeyFile>Signal-Windows_TemporaryKey.pfx</PackageCertificateKeyFile>
21-
<AppxAutoIncrementPackageRevision>True</AppxAutoIncrementPackageRevision>
21+
<AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
2222
<AppxBundle>Always</AppxBundle>
2323
<AppxBundlePlatforms>x86|x64|arm</AppxBundlePlatforms>
2424
<PackageCertificateThumbprint>853DF1D4DABC27DEEF062DB83D09285BAF95B526</PackageCertificateThumbprint>

Signal-Windows/Storage/DB.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ public static void SaveMessageLocked(SignalMessage message)
780780

781781
public static List<SignalMessageContainer> GetMessagesLocked(SignalConversation thread, int startIndex, int count)
782782
{
783+
Debug.WriteLine($"GetMessagesLocked {thread.ThreadId} Skip({startIndex}) Take({count})");
783784
lock (DBLock)
784785
{
785786
using (var ctx = new SignalDBContext())
@@ -793,7 +794,7 @@ public static List<SignalMessageContainer> GetMessagesLocked(SignalConversation
793794
.Skip(startIndex)
794795
.Take(count);
795796

796-
var containers = new List<SignalMessageContainer>();
797+
var containers = new List<SignalMessageContainer>(count);
797798
foreach (var message in messages)
798799
{
799800
containers.Add(new SignalMessageContainer(message, startIndex));

Signal-Windows/ViewModels/MainPageViewModel.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ public bool ThreadListAlignRight
5151
private AsyncLock ActionInProgress = new AsyncLock();
5252
public MainPage View;
5353
public SignalConversation SelectedThread;
54-
private volatile bool Running = true;
54+
private volatile bool Running = false;
5555
private Task IncomingMessagesTask;
5656
private Task OutgoingMessagesTask;
57-
private CancellationTokenSource CancelSource;
57+
private CancellationTokenSource CancelSource = new CancellationTokenSource();
5858
private SignalServiceMessagePipe Pipe;
5959
private SignalServiceMessageSender MessageSender;
6060
private SignalServiceMessageReceiver MessageReceiver;
@@ -113,13 +113,22 @@ public MainPageViewModel()
113113
App.MainPageActive = true;
114114
}
115115

116+
public async Task OnNavigatedTo()
117+
{
118+
if (!Running)
119+
{
120+
await Init();
121+
}
122+
}
123+
116124
public async Task Init()
117125
{
118-
CancelSource = new CancellationTokenSource();
119126
Debug.WriteLine("Init lock wait");
120127
using (await ActionInProgress.LockAsync(CancelSource.Token))
121128
{
122129
Debug.WriteLine("Init lock grabbed");
130+
Running = true;
131+
CancelSource = new CancellationTokenSource();
123132
try
124133
{
125134
await Task.Run(async () =>
@@ -184,6 +193,8 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch
184193
catch (AuthorizationFailedException)
185194
{
186195
Debug.WriteLine("OWS server rejected our credentials - redirecting to StartPage");
196+
Running = false;
197+
CancelSource.Cancel();
187198
View.Frame.Navigate(typeof(StartPage));
188199
}
189200
catch (Exception e)
@@ -203,11 +214,11 @@ public async Task OnNavigatingFrom()
203214

204215
public async Task Shutdown()
205216
{
206-
Running = false;
207-
App.MainPageActive = false;
208217
Debug.WriteLine("Shutdown lock await");
209218
using (await ActionInProgress.LockAsync())
210219
{
220+
Running = false;
221+
App.MainPageActive = false;
211222
Debug.WriteLine("Shutdown lock grabbed");
212223
CancelSource.Cancel();
213224
await IncomingMessagesTask;
@@ -370,7 +381,6 @@ public async Task UIHandleIncomingMessage(SignalMessage message)
370381
{
371382
Debug.WriteLine("incoming lock grabbed");
372383
var thread = ThreadsDictionary[message.ThreadId];
373-
thread.MessagesCount += 1;
374384
uint unreadCount = thread.UnreadCount;
375385
if (SelectedThread == thread)
376386
{
@@ -381,6 +391,7 @@ await Task.Run(() =>
381391
SignalDBContext.SaveMessageLocked(message);
382392
});
383393
long? seenId = null;
394+
thread.MessagesCount += 1;
384395
if (SelectedThread == thread)
385396
{
386397
var container = new SignalMessageContainer(message, (int) thread.MessagesCount - 1);

Signal-Windows/Views/MainPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public PageStyle GetCurrentViewStyle()
9090
protected override async void OnNavigatedTo(NavigationEventArgs e)
9191
{
9292
base.OnNavigatedTo(e);
93-
await Vm.Init();
93+
await Vm.OnNavigatedTo();
9494
}
9595

9696
protected override async void OnNavigatingFrom(NavigatingCancelEventArgs e)

0 commit comments

Comments
 (0)