From 96531d36e96926a6136c624bcac3a9ef5d9eb14f Mon Sep 17 00:00:00 2001 From: morethanwords Date: Sun, 19 Sep 2021 16:17:55 +0400 Subject: [PATCH] Drop local dialog when draft is emptied --- src/components/chat/autocompletePeerHelper.ts | 2 +- src/lib/appManagers/appDialogsManager.ts | 12 ++++++++- src/lib/appManagers/appMessagesManager.ts | 26 ++++++++++++------- src/lib/storages/dialogs.ts | 17 ++++++------ .../partials/_autocompletePeerHelper.scss | 6 +++++ 5 files changed, 44 insertions(+), 19 deletions(-) diff --git a/src/components/chat/autocompletePeerHelper.ts b/src/components/chat/autocompletePeerHelper.ts index 44f55b30..6d80c1a8 100644 --- a/src/components/chat/autocompletePeerHelper.ts +++ b/src/components/chat/autocompletePeerHelper.ts @@ -83,7 +83,7 @@ export default class AutocompletePeerHelper extends AutocompleteHelper { div.dataset.peerId = '' + options.peerId; const avatar = new AvatarElement(); - avatar.classList.add('avatar-30', options.className + '-avatar'); + avatar.classList.add('avatar-30', BASE + '-avatar', options.className + '-avatar'); avatar.setAttribute('dialog', '0'); avatar.setAttribute('peer', '' + options.peerId); diff --git a/src/lib/appManagers/appDialogsManager.ts b/src/lib/appManagers/appDialogsManager.ts index ec4c6c27..4257971d 100644 --- a/src/lib/appManagers/appDialogsManager.ts +++ b/src/lib/appManagers/appDialogsManager.ts @@ -558,7 +558,10 @@ export class AppDialogsManager { private updateDialog(dialog: Dialog) { if(this.isDialogMustBeInViewport(dialog)) { - this.sortedList.add(dialog.peerId); + if(!this.sortedList.has(dialog.peerId)) { + this.sortedList.add(dialog.peerId); + return; + } } else { this.deleteDialog(dialog.peerId); return; @@ -1286,6 +1289,11 @@ export class AppDialogsManager { dom.lastMessageSpan.innerHTML = ''; dom.lastTimeSpan.innerHTML = ''; delete dom.listEl.dataset.mid; + + if(setUnread) { + this.setUnreadMessages(dialog, dom, isBatch); + } + return; } @@ -1334,6 +1342,8 @@ export class AppDialogsManager { fragment = appMessagesManager.wrapMessageForReply(draftMessage); } else if(!lastMessage.deleted) { fragment = appMessagesManager.wrapMessageForReply(lastMessage, undefined, undefined, false, undefined, withoutMediaType); + } else { // rare case + fragment = document.createDocumentFragment(); } if(mediaContainer) { diff --git a/src/lib/appManagers/appMessagesManager.ts b/src/lib/appManagers/appMessagesManager.ts index 2bf63cd6..1d5f6f6f 100644 --- a/src/lib/appManagers/appMessagesManager.ts +++ b/src/lib/appManagers/appMessagesManager.ts @@ -295,16 +295,24 @@ export class AppMessagesManager { if(threadId) return; const dialog = this.getDialogOnly(peerId); - if(dialog && !threadId) { - dialog.draft = draft; - this.dialogsStorage.generateIndexForDialog(dialog); - this.dialogsStorage.pushDialog(dialog); + if(dialog) { + if(!threadId) { + dialog.draft = draft; - rootScope.dispatchEvent('dialog_draft', { - peerId, - draft, - index: dialog.index - }); + if(!draft && !appMessagesIdsManager.getServerMessageId(dialog.top_message)) { + this.dialogsStorage.dropDialogWithEvent(peerId); + return; + } + + this.dialogsStorage.generateIndexForDialog(dialog); + this.dialogsStorage.pushDialog(dialog); + + rootScope.dispatchEvent('dialog_draft', { + peerId, + draft, + index: dialog.index + }); + } } else { this.reloadConversation(peerId); } diff --git a/src/lib/storages/dialogs.ts b/src/lib/storages/dialogs.ts index 99893e38..5c8f6acd 100644 --- a/src/lib/storages/dialogs.ts +++ b/src/lib/storages/dialogs.ts @@ -98,10 +98,7 @@ export default class DialogsStorage { const peerId = -chatId; if(chat.pFlags.left && this.getDialogOnly(peerId)) { - const dropped = this.dropDialog(peerId); - if(dropped.length) { - rootScope.dispatchEvent('dialog_drop', {peerId, dialog: dropped[0]}); - } + this.dropDialogWithEvent(peerId); } }); @@ -450,6 +447,13 @@ export default class DialogsStorage { return foundDialog; } + public dropDialogWithEvent(peerId: number) { + const dropped = this.dropDialog(peerId); + if(dropped.length) { + rootScope.dispatchEvent('dialog_drop', {peerId, dialog: dropped[0]}); + } + } + public applyDialogs(dialogsResult: MessagesPeerDialogs.messagesPeerDialogs) { // * В эту функцию попадут только те диалоги, в которых есть read_inbox_max_id и read_outbox_max_id, в отличие от тех, что будут в getTopMessages @@ -489,10 +493,7 @@ export default class DialogsStorage { this.saveDialog(dialog); updatedDialogs[peerId] = dialog; } else { - const dropped = this.dropDialog(peerId); - if(dropped.length) { - rootScope.dispatchEvent('dialog_drop', {peerId, dialog: dropped[0]}); - } + this.dropDialogWithEvent(peerId); } const updates = this.appMessagesManager.newUpdatesAfterReloadToHandle[peerId]; diff --git a/src/scss/partials/_autocompletePeerHelper.scss b/src/scss/partials/_autocompletePeerHelper.scss index 34009172..8bdfcfb9 100644 --- a/src/scss/partials/_autocompletePeerHelper.scss +++ b/src/scss/partials/_autocompletePeerHelper.scss @@ -24,16 +24,22 @@ position: relative; line-height: var(--line-height); + @include respond-to(handhelds) { + padding-right: .75rem; + } + @include hover(); &-name { margin-left: .875rem; font-weight: 500; + flex: 0 0 auto; } &-description { margin-left: .5625rem; color: var(--secondary-text-color); + @include text-overflow(); } &-avatar {