Fix media viewer search

This commit is contained in:
Eduard Kuzmenko 2020-12-23 04:18:24 +02:00
parent 3d81994cee
commit aa7ddf8004
8 changed files with 35 additions and 22 deletions

View File

@ -1110,6 +1110,7 @@ type AppMediaViewerTargetType = {
export default class AppMediaViewer extends AppMediaViewerBase<'caption', 'delete' | 'forward', AppMediaViewerTargetType> { export default class AppMediaViewer extends AppMediaViewerBase<'caption', 'delete' | 'forward', AppMediaViewerTargetType> {
public currentMessageId = 0; public currentMessageId = 0;
public peerId: number; public peerId: number;
public threadId: number;
constructor(private inputFilter: 'inputMessagesFilterPhotoVideo' | 'inputMessagesFilterChatPhotos' = 'inputMessagesFilterPhotoVideo') { constructor(private inputFilter: 'inputMessagesFilterPhotoVideo' | 'inputMessagesFilterChatPhotos' = 'inputMessagesFilterPhotoVideo') {
super(['delete', 'forward']); super(['delete', 'forward']);
@ -1193,7 +1194,7 @@ export default class AppMediaViewer extends AppMediaViewerBase<'caption', 'delet
} }
const message = appMessagesManager.getMessageByPeer(this.peerId, mid); const message = appMessagesManager.getMessageByPeer(this.peerId, mid);
appImManager.setPeer(message.peerId, mid); appImManager.setInnerPeer(message.peerId, mid, this.threadId ? 'discussion' : undefined, this.threadId);
}); });
} }
}; };
@ -1237,13 +1238,14 @@ export default class AppMediaViewer extends AppMediaViewerBase<'caption', 'delet
} }
if(anchor) maxId = anchor.mid; if(anchor) maxId = anchor.mid;
if(!older) maxId += 1; if(!older) maxId = appMessagesManager.incrementMessageId(maxId, 1);
const peerId = this.peerId; const peerId = this.peerId;
const threadId = this.threadId;
const promise = appMessagesManager.getSearch(peerId, '', const promise = appMessagesManager.getSearch(peerId, '',
{_: this.inputFilter}, maxId, backLimit ? 0 : loadCount/* older ? loadCount : 0 */, 0, backLimit).then(value => { {_: this.inputFilter}, maxId, backLimit ? 0 : loadCount/* older ? loadCount : 0 */, 0, backLimit, threadId).then(value => {
if(this.peerId != peerId) { if(this.peerId !== peerId || this.threadId !== threadId) {
this.log.warn('peer changed'); this.log.warn('peer changed');
return; return;
} }
@ -1310,7 +1312,7 @@ export default class AppMediaViewer extends AppMediaViewerBase<'caption', 'delet
} }
public async openMedia(message: any, target?: HTMLElement, reverse = false, public async openMedia(message: any, target?: HTMLElement, reverse = false,
prevTargets: AppMediaViewer['prevTargets'] = [], nextTargets: AppMediaViewer['prevTargets'] = [], needLoadMore = true) { prevTargets: AppMediaViewer['prevTargets'] = [], nextTargets: AppMediaViewer['prevTargets'] = [], needLoadMore = true, threadId?: number) {
if(this.setMoverPromise) return this.setMoverPromise; if(this.setMoverPromise) return this.setMoverPromise;
const mid = message.mid; const mid = message.mid;
@ -1325,6 +1327,7 @@ export default class AppMediaViewer extends AppMediaViewerBase<'caption', 'delet
} else { } else {
this.reverse = reverse; this.reverse = reverse;
this.peerId = message.peerId; this.peerId = message.peerId;
this.threadId = threadId;
} }
this.currentMessageId = mid; this.currentMessageId = mid;

View File

@ -617,7 +617,7 @@ export default class ChatBubbles {
} }
new AppMediaViewer().openMedia(message, targets[idx].element, true, new AppMediaViewer().openMedia(message, targets[idx].element, true,
targets.slice(0, idx), targets.slice(idx + 1)/* , !message.grouped_id */); targets.slice(0, idx), targets.slice(idx + 1), undefined, this.chat.threadId/* , !message.grouped_id */);
cancelEvent(e); cancelEvent(e);
//appMediaViewer.openMedia(message, target as HTMLImageElement); //appMediaViewer.openMedia(message, target as HTMLImageElement);

View File

@ -164,7 +164,7 @@ export default class Chat extends EventListenerBase<{
} }
this.peerId = peerId; this.peerId = peerId;
appSidebarRight.sharedMediaTab.setPeer(peerId); appSidebarRight.sharedMediaTab.setPeer(peerId, this.threadId);
this.cleanup(); this.cleanup();
} else { } else {
this.peerChanged = true; this.peerChanged = true;

View File

@ -42,6 +42,7 @@ export default class AppSharedMediaTab implements SliderTab {
public closeBtn: HTMLElement; public closeBtn: HTMLElement;
private peerId = 0; private peerId = 0;
private threadId = 0;
public profileContentEl: HTMLDivElement; public profileContentEl: HTMLDivElement;
public contentContainer: HTMLDivElement; public contentContainer: HTMLDivElement;
@ -190,7 +191,7 @@ export default class AppSharedMediaTab implements SliderTab {
return {element, mid: id}; return {element, mid: id};
}); });
new AppMediaViewer().openMedia(message, target, false, targets.slice(idx + 1).reverse(), targets.slice(0, idx).reverse(), true); new AppMediaViewer().openMedia(message, target, false, targets.slice(idx + 1).reverse(), targets.slice(0, idx).reverse(), true/* , this.threadId */);
}); });
this.profileElements.notificationsCheckbox.addEventListener('change', () => { this.profileElements.notificationsCheckbox.addEventListener('change', () => {
@ -403,6 +404,7 @@ export default class AppSharedMediaTab implements SliderTab {
public async performSearchResult(messages: any[], type: SharedMediaType, append = true) { public async performSearchResult(messages: any[], type: SharedMediaType, append = true) {
const peerId = this.peerId; const peerId = this.peerId;
const threadId = this.threadId;
const elemsToAppend: HTMLElement[] = []; const elemsToAppend: HTMLElement[] = [];
const promises: Promise<any>[] = []; const promises: Promise<any>[] = [];
const sharedMediaDiv = this.sharedMedia[type]; const sharedMediaDiv = this.sharedMedia[type];
@ -455,7 +457,7 @@ export default class AppSharedMediaTab implements SliderTab {
const load = () => appPhotosManager.preloadPhoto(isPhoto ? media.id : media, appPhotosManager.choosePhotoSize(media, 200, 200)) const load = () => appPhotosManager.preloadPhoto(isPhoto ? media.id : media, appPhotosManager.choosePhotoSize(media, 200, 200))
.then(() => { .then(() => {
if(appImManager.chat.peerId != peerId) { if(this.peerId != peerId || this.threadId != threadId) {
this.log.warn('peer changed'); this.log.warn('peer changed');
return; return;
} }
@ -606,7 +608,7 @@ export default class AppSharedMediaTab implements SliderTab {
if(webpage.photo) { if(webpage.photo) {
let load = () => appPhotosManager.preloadPhoto(webpage.photo.id, appPhotosManager.choosePhotoSize(webpage.photo, 60, 60)) let load = () => appPhotosManager.preloadPhoto(webpage.photo.id, appPhotosManager.choosePhotoSize(webpage.photo, 60, 60))
.then(() => { .then(() => {
if(appImManager.chat.peerId != peerId) { if(this.peerId != peerId || this.threadId != threadId) {
this.log.warn('peer changed'); this.log.warn('peer changed');
return; return;
} }
@ -660,7 +662,7 @@ export default class AppSharedMediaTab implements SliderTab {
if(promises.length) { if(promises.length) {
await Promise.all(promises); await Promise.all(promises);
if(this.peerId != peerId) { if(this.peerId !== peerId || this.threadId !== threadId) {
this.log.warn('peer changed'); this.log.warn('peer changed');
return; return;
} }
@ -696,6 +698,7 @@ export default class AppSharedMediaTab implements SliderTab {
this.log('loadSidebarMedia', single, this.peerId, this.loadSidebarMediaPromises); this.log('loadSidebarMedia', single, this.peerId, this.loadSidebarMediaPromises);
const peerId = this.peerId; const peerId = this.peerId;
const threadId = this.threadId;
let typesToLoad = single ? [this.sharedMediaType] : this.sharedMediaTypes.filter(t => t !== this.sharedMediaType && t !== 'inputMessagesFilterEmpty'); let typesToLoad = single ? [this.sharedMediaType] : this.sharedMediaTypes.filter(t => t !== this.sharedMediaType && t !== 'inputMessagesFilterEmpty');
typesToLoad = typesToLoad.filter(type => !this.loadedAllMedia[type] typesToLoad = typesToLoad.filter(type => !this.loadedAllMedia[type]
@ -750,14 +753,14 @@ export default class AppSharedMediaTab implements SliderTab {
this.log(logStr + 'search house of glass pre', type, maxId); this.log(logStr + 'search house of glass pre', type, maxId);
//let loadCount = history.length ? 50 : 15; //let loadCount = history.length ? 50 : 15;
return this.loadSidebarMediaPromises[type] = appMessagesManager.getSearch(peerId, '', {_: type}, maxId, loadCount) return this.loadSidebarMediaPromises[type] = appMessagesManager.getSearch(peerId, '', {_: type}, maxId, loadCount, undefined, undefined/* , this.threadId */)
.then(value => { .then(value => {
const mids = value.history.map(message => message.mid); const mids = value.history.map(message => message.mid);
history.push(...mids); history.push(...mids);
this.log(logStr + 'search house of glass', type, value); this.log(logStr + 'search house of glass', type, value);
if(appImManager.chat.peerId != peerId) { if(this.peerId !== peerId || this.threadId !== threadId) {
this.log.warn('peer changed'); this.log.warn('peer changed');
return; return;
} }
@ -875,8 +878,8 @@ export default class AppSharedMediaTab implements SliderTab {
this.loadMutex = promise; this.loadMutex = promise;
} }
public setPeer(peerId: number) { public setPeer(peerId: number, threadId = 0) {
if(this.peerId == peerId) return; if(this.peerId === peerId && this.threadId === peerId) return;
if(this.init) { if(this.init) {
this.init(); this.init();
@ -884,6 +887,7 @@ export default class AppSharedMediaTab implements SliderTab {
} }
this.peerId = peerId; this.peerId = peerId;
this.threadId = threadId;
this.cleanup(); this.cleanup();
} }
@ -892,6 +896,7 @@ export default class AppSharedMediaTab implements SliderTab {
this.cleaned = false; this.cleaned = false;
const peerId = this.peerId; const peerId = this.peerId;
const threadId = this.threadId;
this.cleanupHTML(); this.cleanupHTML();
@ -923,7 +928,7 @@ export default class AppSharedMediaTab implements SliderTab {
} }
appProfileManager.getProfile(peerId).then(userFull => { appProfileManager.getProfile(peerId).then(userFull => {
if(this.peerId != peerId) { if(this.peerId !== peerId || this.threadId !== threadId) {
this.log.warn('peer changed'); this.log.warn('peer changed');
return; return;
} }
@ -939,7 +944,7 @@ export default class AppSharedMediaTab implements SliderTab {
let chat = appPeersManager.getPeer(peerId); let chat = appPeersManager.getPeer(peerId);
appProfileManager.getChatFull(chat.id).then((chatFull) => { appProfileManager.getChatFull(chat.id).then((chatFull) => {
if(this.peerId != peerId) { if(this.peerId !== peerId || this.threadId !== threadId) {
this.log.warn('peer changed'); this.log.warn('peer changed');
return; return;
} }

View File

@ -466,7 +466,7 @@ export class AppImManager {
appSidebarRight.searchTab.closeBtn?.click(); appSidebarRight.searchTab.closeBtn?.click();
} }
appSidebarRight.sharedMediaTab.setPeer(this.chat.peerId); appSidebarRight.sharedMediaTab.setPeer(this.chat.peerId, this.chat.threadId);
appSidebarRight.sharedMediaTab.loadSidebarMedia(true); appSidebarRight.sharedMediaTab.loadSidebarMedia(true);
appSidebarRight.sharedMediaTab.fillProfileElements(); appSidebarRight.sharedMediaTab.fillProfileElements();

View File

@ -1417,7 +1417,7 @@ $bubble-margin: .25rem;
} }
&.photo, &.video { &.photo, &.video {
&.is-message-empty.is-group-last { &.is-message-empty.is-group-last:not(.with-replies) {
.bubble__container:after { .bubble__container:after {
display: none; display: none;
} }
@ -1683,7 +1683,7 @@ $bubble-margin: .25rem;
} }
&.is-message-empty.is-group-last { &.is-message-empty.is-group-last {
&:not(.with-media-tail) { &:not(.with-media-tail):not(.with-replies) {
&.photo, &.video { &.photo, &.video {
.bubble__container { .bubble__container {
border-bottom-left-radius: 6px; border-bottom-left-radius: 6px;

View File

@ -48,11 +48,13 @@
transform: scale(0); transform: scale(0);
border-radius: 50%; border-radius: 50%;
animation: ripple-effect .7s forwards; animation: ripple-effect .7s forwards;
//animation-timing-function: ease-out;
transition: .35s opacity; transition: .35s opacity;
//overflow: hidden; //overflow: hidden;
.btn-menu &, .c-ripple.is-square & { .btn-menu &, .c-ripple.is-square & {
animation-name: ripple-effect-handhelds; animation-name: ripple-effect-handhelds;
//animation-timing-function: ease-out;
animation-duration: .2s; animation-duration: .2s;
transition-duration: .1s; transition-duration: .1s;
//border-radius: 15%; //border-radius: 15%;
@ -80,9 +82,10 @@
--ripple-duration: .2s; --ripple-duration: .2s;
&__circle { &__circle {
animation-name: ripple-effect-handhelds;
//animation-timing-function: ease-out;
animation-duration: .2s; animation-duration: .2s;
transition-duration: .1s; transition-duration: .1s;
animation-name: ripple-effect-handhelds;
} }
} }
} }
@ -100,7 +103,8 @@
@keyframes ripple-effect-handhelds { @keyframes ripple-effect-handhelds {
0% { 0% {
transform: scale(.85); //transform: scale(.85);
transform: scale(.27);
} }
to { to {

View File

@ -1,5 +1,6 @@
.popup-stickers { .popup-stickers {
$parent: ".popup"; $parent: ".popup";
user-select: none;
h6 { h6 {
padding: 0 2rem 0 1.5rem; padding: 0 2rem 0 1.5rem;