Skip to content

Commit 7ca3f31

Browse files
committed
Stop using ActivationMode because W10m does not support it
1 parent c1b2723 commit 7ca3f31

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

Signal-Windows/Controls/Conversation.xaml.cs

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public sealed partial class Conversation : UserControl, INotifyPropertyChanged
3434
private Dictionary<long, SignalAttachmentContainer> UnfinishedAttachmentsCache = new Dictionary<long, SignalAttachmentContainer>();
3535
private SignalConversation SignalConversation;
3636
public VirtualizedCollection Collection;
37+
private CoreWindowActivationState ActivationState = CoreWindowActivationState.Deactivated;
3738
private int LastMarkReadRequest;
3839

3940
private string _ThreadDisplayName;
@@ -99,6 +100,13 @@ public Conversation()
99100
Separator.Foreground = Utils.ForegroundIncoming;
100101
Username.Foreground = Utils.ForegroundIncoming;
101102
SendButtonEnabled = false;
103+
Window.Current.Activated += HandleWindowActivated;
104+
}
105+
106+
private void HandleWindowActivated(object sender, WindowActivatedEventArgs e)
107+
{
108+
Logger.LogTrace("HandleWindowActivated() new activation state {0}", e.WindowActivationState);
109+
ActivationState = e.WindowActivationState;
102110
}
103111

104112
public MainPageViewModel GetMainPageVm()
@@ -233,9 +241,8 @@ public AppendResult Append(SignalMessageContainer sm)
233241
{
234242
UpdateLayout();
235243
ScrollToBottom();
236-
if (Window.Current.CoreWindow.ActivationMode == CoreWindowActivationMode.ActivatedInForeground)
244+
if (ActivationState != CoreWindowActivationState.Deactivated)
237245
{
238-
Logger.LogTrace("Append at no-virt-index {0}", sm.Index);
239246
result = new AppendResult(sm.Index + 1);
240247
}
241248
}
@@ -305,7 +312,6 @@ private void ScrollToUnread()
305312

306313
private int GetBottommostIndex()
307314
{
308-
Logger.LogTrace("GetBottommostIndex()");
309315
var sourcePanel = ConversationItemsControl.ItemsPanelRoot as ItemsStackPanel;
310316
if (sourcePanel != null)
311317
{
@@ -329,34 +335,19 @@ private void ConversationSettingsButton_Click(object sender, RoutedEventArgs e)
329335

330336
private void ScrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
331337
{
332-
int bottomIndex = GetBottommostIndex();
333-
Logger.LogTrace("ScrollViewer_ViewChanged() bottomIndex={0}", bottomIndex);
334-
try
338+
if (ActivationState != CoreWindowActivationState.Deactivated)
335339
{
336-
CoreWindow window = Window.Current.CoreWindow;
337-
Logger.LogTrace("ScrollViewer_ViewChanged() window={0}", window);
338-
CoreWindowActivationMode mode = window.ActivationMode;
339-
Logger.LogTrace("ScrollViewer_ViewChanged() mode={0}", mode);
340-
if (mode == CoreWindowActivationMode.ActivatedInForeground)
340+
int bottomIndex = GetBottommostIndex();
341+
long lastSeenIndex = SignalConversation.LastSeenMessageIndex;
342+
if (lastSeenIndex < bottomIndex && LastMarkReadRequest < bottomIndex)
341343
{
342-
Logger.LogTrace("ScrollViewer_ViewChanged() mode == CoreWindowActivationMode.ActivatedInForeground");
343-
long lastSeenIndex = SignalConversation.LastSeenMessageIndex;
344-
Logger.LogTrace("ScrollViewer_ViewChanged() lastSeenIndex={0} LastMarkReadRequest={1}", lastSeenIndex, LastMarkReadRequest);
345-
if (lastSeenIndex < bottomIndex && LastMarkReadRequest < bottomIndex)
344+
LastMarkReadRequest = bottomIndex;
345+
Task.Run(async () =>
346346
{
347-
Logger.LogTrace("ScrollViewer_ViewChanged() setting index {0} as read", bottomIndex);
348-
LastMarkReadRequest = bottomIndex;
349-
Task.Run(async () =>
350-
{
351-
await App.Handle.SetMessageRead(bottomIndex, SignalConversation);
352-
});
353-
}
347+
await App.Handle.SetMessageRead(bottomIndex, SignalConversation);
348+
});
354349
}
355350
}
356-
catch(Exception ex)
357-
{
358-
Logger.LogError("ScrollViewer_ViewChanged() failed: {0}\n{1}", ex.Message, ex.StackTrace);
359-
}
360351
}
361352
}
362353

0 commit comments

Comments
 (0)