@@ -723,9 +723,13 @@ class Some<T extends AnyDialog = AnyDialog> {
723
723
724
724
public updateDialog ( dialog : T ) {
725
725
const key = this . getDialogKey ( dialog ) ;
726
- if ( ! this . sortedList . has ( key ) && this . loadedDialogsAtLeastOnce ) {
727
- this . sortedList . add ( key ) ;
728
- return ;
726
+ if ( this . canUpdateDialog ( dialog ) ) {
727
+ if ( ! this . sortedList . has ( key ) && this . loadedDialogsAtLeastOnce ) {
728
+ this . sortedList . add ( key ) ;
729
+ return ;
730
+ }
731
+ } else {
732
+ this . deleteDialog ( dialog ) ;
729
733
}
730
734
731
735
const dialogElement = this . getDialogElement ( key ) ;
@@ -741,6 +745,16 @@ class Some<T extends AnyDialog = AnyDialog> {
741
745
this . sortedList . update ( key ) ;
742
746
}
743
747
748
+ protected canUpdateDialog ( dialog : T ) {
749
+ const sortedItems = this . sortedList . getSortedItems ( ) ;
750
+ const last = sortedItems [ sortedItems . length - 1 ] ;
751
+
752
+ const bottomIndex = last ?. index ;
753
+ const dialogIndex = getDialogIndex ( dialog ) ;
754
+
755
+ return ! last || dialogIndex >= bottomIndex ;
756
+ }
757
+
744
758
public onChatsScrollTop ( ) {
745
759
return this . onChatsScroll ( 'top' ) ;
746
760
} ;
@@ -771,7 +785,7 @@ class Some<T extends AnyDialog = AnyDialog> {
771
785
772
786
private loadDialogsDeferred : CancellablePromise < SequentialCursorFetcherResult < number > > ;
773
787
774
- public async loadDialogs ( offsetIndex : number ) {
788
+ public async loadDialogs ( offsetIndex ? : number ) {
775
789
this . loadDialogsDeferred = deferredPromise ( ) ;
776
790
777
791
this . loadDialogsInner ( offsetIndex )
@@ -803,10 +817,14 @@ class Some<T extends AnyDialog = AnyDialog> {
803
817
throw NOT_IMPLEMENTED_ERROR ;
804
818
}
805
819
806
- public async loadDialogsInner ( offsetIndex : number ) : Promise < SequentialCursorFetcherResult < number > > {
820
+ public checkForDialogsPlaceholder ( ) {
821
+ if ( ! this . placeholder && ! this . loadedDialogsAtLeastOnce ) this . placeholder = this . createPlaceholder ( ) ;
822
+ }
823
+
824
+ public async loadDialogsInner ( offsetIndex ?: number ) : Promise < SequentialCursorFetcherResult < number > > {
807
825
console . log ( '[my-debug] loadDialogs offsetIndex :>> ' , offsetIndex ) ;
808
826
809
- if ( ! this . placeholder && ! this . loadedDialogsAtLeastOnce ) this . placeholder = this . createPlaceholder ( ) ;
827
+ this . checkForDialogsPlaceholder ( ) ;
810
828
811
829
const filterId = this . getFilterId ( ) ;
812
830
@@ -819,6 +837,9 @@ class Some<T extends AnyDialog = AnyDialog> {
819
837
820
838
const result = await ackedResult . result ;
821
839
840
+ // if(appDialogsManager.doNotRenderChatList) throw new Error('First load of dialogs canceled');
841
+ // if(appDialogsManager.doNotRenderChatList) await pause(1000);
842
+
822
843
const newOffsetIndex = result . dialogs . reduce ( ( prev , curr ) => {
823
844
const index = getDialogIndex ( curr , this . indexKey )
824
845
return index < prev ? index : prev ;
@@ -1041,6 +1062,11 @@ class Some3 extends Some<ForumTopic> {
1041
1062
protected getFilterId ( ) {
1042
1063
return this . peerId ;
1043
1064
}
1065
+
1066
+ protected canUpdateDialog ( dialog : ForumTopic ) : boolean {
1067
+ if ( dialog . pFlags . hidden ) return false ;
1068
+ return super . canUpdateDialog ( dialog ) ;
1069
+ }
1044
1070
}
1045
1071
1046
1072
export class Some2 extends Some < Dialog > {
@@ -1352,6 +1378,11 @@ export class Some2 extends Some<Dialog> {
1352
1378
public getDialogFromElement ( element : HTMLElement ) {
1353
1379
return rootScope . managers . appMessagesManager . getDialogOnly ( element . dataset . peerId . toPeerId ( ) ) ;
1354
1380
}
1381
+
1382
+ protected canUpdateDialog ( dialog : Dialog ) : boolean {
1383
+ if ( dialog . migratedTo !== undefined || ! this . testDialogForFilter ( dialog ) ) return false ;
1384
+ return super . canUpdateDialog ( dialog ) ;
1385
+ }
1355
1386
}
1356
1387
1357
1388
export class Some4 extends Some < SavedDialog > {
@@ -1926,8 +1957,10 @@ export class AppDialogsManager {
1926
1957
1927
1958
this . doNotRenderChatList = true ;
1928
1959
// const loadDialogsPromise = this.xd.onChatsScroll();
1960
+ // this.xd.checkForDialogsPlaceholder();
1929
1961
const m = middlewarePromise ( middleware ) ;
1930
1962
try {
1963
+ await this . xd . loadDialogs ( ) ;
1931
1964
// await m(loadDialogsPromise);
1932
1965
} catch ( err ) {
1933
1966
0 commit comments