Skip to content

Commit 18c9dd9

Browse files
committed
Don't add duplicate Threads to Thread list
This happens when coming back to the MainPage
1 parent 2c0b7e0 commit 18c9dd9

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Signal-Windows/ViewModels/MainPageViewModel.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ public bool ThreadListAlignRight
6565

6666
public void AddThread(SignalConversation contact)
6767
{
68+
// only add a contact to Threads if it isn't already there
69+
foreach (var thread in Threads)
70+
{
71+
if (thread.ThreadId == contact.ThreadId)
72+
{
73+
return;
74+
}
75+
}
6876
Threads.Add(contact);
6977
ThreadsDictionary[contact.ThreadId] = contact;
7078
}
@@ -186,6 +194,12 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch
186194
Debug.WriteLine("Init lock released");
187195
}
188196

197+
public async Task OnNavigatingFrom()
198+
{
199+
SelectedThread = null;
200+
View.Thread.DisposeCurrentThread();
201+
}
202+
189203
public async Task Shutdown()
190204
{
191205
Running = false;

Signal-Windows/Views/MainPage.xaml.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ protected override async void OnNavigatedTo(NavigationEventArgs e)
9393
await Vm.Init();
9494
}
9595

96+
protected override async void OnNavigatingFrom(NavigatingCancelEventArgs e)
97+
{
98+
base.OnNavigatingFrom(e);
99+
ContactsList.SelectedItem = null;
100+
await Vm.OnNavigatingFrom();
101+
}
102+
96103
private void Frame_SizeChanged(object sender, SizeChangedEventArgs e)
97104
{
98105
var oldStyle = Utils.GetViewStyle(e.PreviousSize);

0 commit comments

Comments
 (0)