@@ -34,6 +34,7 @@ public sealed partial class Conversation : UserControl, INotifyPropertyChanged
34
34
private Dictionary < long , SignalAttachmentContainer > UnfinishedAttachmentsCache = new Dictionary < long , SignalAttachmentContainer > ( ) ;
35
35
private SignalConversation SignalConversation ;
36
36
public VirtualizedCollection Collection ;
37
+ private CoreWindowActivationState ActivationState = CoreWindowActivationState . Deactivated ;
37
38
private int LastMarkReadRequest ;
38
39
39
40
private string _ThreadDisplayName ;
@@ -99,6 +100,13 @@ public Conversation()
99
100
Separator . Foreground = Utils . ForegroundIncoming ;
100
101
Username . Foreground = Utils . ForegroundIncoming ;
101
102
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 ;
102
110
}
103
111
104
112
public MainPageViewModel GetMainPageVm ( )
@@ -233,9 +241,8 @@ public AppendResult Append(SignalMessageContainer sm)
233
241
{
234
242
UpdateLayout ( ) ;
235
243
ScrollToBottom ( ) ;
236
- if ( Window . Current . CoreWindow . ActivationMode == CoreWindowActivationMode . ActivatedInForeground )
244
+ if ( ActivationState != CoreWindowActivationState . Deactivated )
237
245
{
238
- Logger . LogTrace ( "Append at no-virt-index {0}" , sm . Index ) ;
239
246
result = new AppendResult ( sm . Index + 1 ) ;
240
247
}
241
248
}
@@ -305,7 +312,6 @@ private void ScrollToUnread()
305
312
306
313
private int GetBottommostIndex ( )
307
314
{
308
- Logger . LogTrace ( "GetBottommostIndex()" ) ;
309
315
var sourcePanel = ConversationItemsControl . ItemsPanelRoot as ItemsStackPanel ;
310
316
if ( sourcePanel != null )
311
317
{
@@ -329,34 +335,19 @@ private void ConversationSettingsButton_Click(object sender, RoutedEventArgs e)
329
335
330
336
private void ScrollViewer_ViewChanged ( object sender , ScrollViewerViewChangedEventArgs e )
331
337
{
332
- int bottomIndex = GetBottommostIndex ( ) ;
333
- Logger . LogTrace ( "ScrollViewer_ViewChanged() bottomIndex={0}" , bottomIndex ) ;
334
- try
338
+ if ( ActivationState != CoreWindowActivationState . Deactivated )
335
339
{
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 )
341
343
{
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 ( ) =>
346
346
{
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
+ } ) ;
354
349
}
355
350
}
356
- catch ( Exception ex )
357
- {
358
- Logger . LogError ( "ScrollViewer_ViewChanged() failed: {0}\n {1}" , ex . Message , ex . StackTrace ) ;
359
- }
360
351
}
361
352
}
362
353
0 commit comments