tweb/src/components/appMediaViewerAvatar.ts

93 lines
2.4 KiB
TypeScript
Raw Permalink Normal View History

2021-10-05 22:40:07 +02:00
/*
* https://github.com/morethanwords/tweb
* Copyright (C) 2019-2021 Eduard Kuzmenko
* https://github.com/morethanwords/tweb/blob/master/LICENSE
*/
2022-08-04 08:49:54 +02:00
import AvatarListLoader from '../helpers/avatarListLoader';
import {Photo} from '../layer';
import appDownloadManager from '../lib/appManagers/appDownloadManager';
import appImManager from '../lib/appManagers/appImManager';
import rootScope from '../lib/rootScope';
import AppMediaViewerBase from './appMediaViewerBase';
2021-10-05 22:40:07 +02:00
type AppMediaViewerAvatarTargetType = {element: HTMLElement, photoId: Photo.photo['id'], photo?: Photo.photo};
2021-10-05 22:40:07 +02:00
export default class AppMediaViewerAvatar extends AppMediaViewerBase<'', 'delete', AppMediaViewerAvatarTargetType> {
2021-10-21 15:16:43 +02:00
public peerId: PeerId;
2021-10-05 22:40:07 +02:00
2021-10-21 15:16:43 +02:00
constructor(peerId: PeerId) {
2022-04-25 16:54:30 +02:00
super(new AvatarListLoader({peerId, managers: rootScope.managers}), [/* 'delete' */]);
2021-10-05 22:40:07 +02:00
this.peerId = peerId;
this.setBtnMenuToggle([{
icon: 'download',
text: 'MediaViewer.Context.Download',
onClick: this.onDownloadClick
}/* , {
icon: 'delete danger btn-disabled',
text: 'Delete',
onClick: () => {}
} */]);
// * constructing html end
2022-08-04 08:49:54 +02:00
2021-10-05 22:40:07 +02:00
this.setListeners();
}
onPrevClick = (target: AppMediaViewerAvatarTargetType) => {
this.openMedia({
photoId: target.photoId,
target: target.element,
fromRight: -1
});
2021-10-05 22:40:07 +02:00
};
onNextClick = (target: AppMediaViewerAvatarTargetType) => {
this.openMedia({
photoId: target.photoId,
target: target.element,
fromRight: 1
});
2021-10-05 22:40:07 +02:00
};
onDownloadClick = () => {
appDownloadManager.downloadToDisc({
media: this.target.photo,
queueId: appImManager.chat.bubbles.lazyLoadQueue.queueId
});
2021-10-05 22:40:07 +02:00
};
public async openMedia({
photoId,
target,
fromRight = 0,
prevTargets,
nextTargets
}: {
photoId: Photo.photo['id'],
target?: HTMLElement,
fromRight?: number,
prevTargets?: AppMediaViewerAvatarTargetType[],
nextTargets?: AppMediaViewerAvatarTargetType[]
}) {
2021-10-05 22:40:07 +02:00
if(this.setMoverPromise) return this.setMoverPromise;
const photo = await this.managers.appPhotosManager.getPhoto(photoId);
const ret = super._openMedia({
media: photo,
timestamp: photo.date,
fromId: this.peerId,
fromRight,
target,
reverse: false,
prevTargets,
nextTargets
});
2021-10-05 22:40:07 +02:00
this.target.photoId = photo.id;
this.target.photo = photo;
2021-10-05 22:40:07 +02:00
return ret;
}
}