Skip to content

Commit 425c5f4

Browse files
committed
Check if can update dialog
1 parent 2a2da35 commit 425c5f4

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

‎src/components/deferredSortedVirtualList.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ export const createDeferredSortedVirtualList = <T, >(args: CreateDeferredSortedV
245245

246246
setTotalCount,
247247

248+
sortedItems,
248249
itemsLength,
249250
addItems,
250251
updateItem,

‎src/components/sortedDialogList.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ export default class SortedDialogList {
170170
return this.virtualList.getAll();
171171
}
172172

173+
public getSortedItems() {
174+
return this.virtualList.sortedItems();
175+
}
176+
173177
public async update(key: any) {
174178
const index = await this.getIndexForKey(key);
175179
this.virtualList.updateItem(key, index);

‎src/lib/appManagers/appDialogsManager.ts

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -723,9 +723,13 @@ class Some<T extends AnyDialog = AnyDialog> {
723723

724724
public updateDialog(dialog: T) {
725725
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);
729733
}
730734

731735
const dialogElement = this.getDialogElement(key);
@@ -741,6 +745,16 @@ class Some<T extends AnyDialog = AnyDialog> {
741745
this.sortedList.update(key);
742746
}
743747

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+
744758
public onChatsScrollTop() {
745759
return this.onChatsScroll('top');
746760
};
@@ -771,7 +785,7 @@ class Some<T extends AnyDialog = AnyDialog> {
771785

772786
private loadDialogsDeferred: CancellablePromise<SequentialCursorFetcherResult<number>>;
773787

774-
public async loadDialogs(offsetIndex: number) {
788+
public async loadDialogs(offsetIndex?: number) {
775789
this.loadDialogsDeferred = deferredPromise();
776790

777791
this.loadDialogsInner(offsetIndex)
@@ -803,10 +817,14 @@ class Some<T extends AnyDialog = AnyDialog> {
803817
throw NOT_IMPLEMENTED_ERROR;
804818
}
805819

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>> {
807825
console.log('[my-debug] loadDialogs offsetIndex :>> ', offsetIndex);
808826

809-
if(!this.placeholder && !this.loadedDialogsAtLeastOnce) this.placeholder = this.createPlaceholder();
827+
this.checkForDialogsPlaceholder();
810828

811829
const filterId = this.getFilterId();
812830

@@ -819,6 +837,9 @@ class Some<T extends AnyDialog = AnyDialog> {
819837

820838
const result = await ackedResult.result;
821839

840+
// if(appDialogsManager.doNotRenderChatList) throw new Error('First load of dialogs canceled');
841+
// if(appDialogsManager.doNotRenderChatList) await pause(1000);
842+
822843
const newOffsetIndex = result.dialogs.reduce((prev, curr) => {
823844
const index = getDialogIndex(curr, this.indexKey)
824845
return index < prev ? index : prev;
@@ -1041,6 +1062,11 @@ class Some3 extends Some<ForumTopic> {
10411062
protected getFilterId() {
10421063
return this.peerId;
10431064
}
1065+
1066+
protected canUpdateDialog(dialog: ForumTopic): boolean {
1067+
if(dialog.pFlags.hidden) return false;
1068+
return super.canUpdateDialog(dialog);
1069+
}
10441070
}
10451071

10461072
export class Some2 extends Some<Dialog> {
@@ -1352,6 +1378,11 @@ export class Some2 extends Some<Dialog> {
13521378
public getDialogFromElement(element: HTMLElement) {
13531379
return rootScope.managers.appMessagesManager.getDialogOnly(element.dataset.peerId.toPeerId());
13541380
}
1381+
1382+
protected canUpdateDialog(dialog: Dialog): boolean {
1383+
if(dialog.migratedTo !== undefined || !this.testDialogForFilter(dialog)) return false;
1384+
return super.canUpdateDialog(dialog);
1385+
}
13551386
}
13561387

13571388
export class Some4 extends Some<SavedDialog> {
@@ -1926,8 +1957,10 @@ export class AppDialogsManager {
19261957

19271958
this.doNotRenderChatList = true;
19281959
// const loadDialogsPromise = this.xd.onChatsScroll();
1960+
// this.xd.checkForDialogsPlaceholder();
19291961
const m = middlewarePromise(middleware);
19301962
try {
1963+
await this.xd.loadDialogs();
19311964
// await m(loadDialogsPromise);
19321965
} catch(err) {
19331966

0 commit comments

Comments
 (0)