Telegram Web K with changes to work inside I2P https://web.telegram.i2p/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.0 KiB

3 years ago
/*
* https://github.com/morethanwords/tweb
* Copyright (C) 2019-2021 Eduard Kuzmenko
* https://github.com/morethanwords/tweb/blob/master/LICENSE
*/
2 years ago
import {ChatAutoDownloadSettings} from '../../helpers/autoDownload';
import mediaSizes from '../../helpers/mediaSizes';
import {Middleware} from '../../helpers/middleware';
2 years ago
import {Message, PhotoSize} from '../../layer';
import {AppManagers} from '../../lib/appManagers/managers';
import getMediaFromMessage from '../../lib/appManagers/utils/messages/getMediaFromMessage';
import choosePhotoSize from '../../lib/appManagers/utils/photos/choosePhotoSize';
import rootScope from '../../lib/rootScope';
import Chat from '../chat/chat';
import LazyLoadQueue from '../lazyLoadQueue';
import prepareAlbum from '../prepareAlbum';
import wrapPhoto from './photo';
import wrapVideo from './video';
3 years ago
export default function wrapAlbum({messages, attachmentDiv, middleware, uploading, lazyLoadQueue, isOut, chat, loadPromises, autoDownload, managers = rootScope.managers}: {
messages: Message.message[],
3 years ago
attachmentDiv: HTMLElement,
middleware?: Middleware,
3 years ago
lazyLoadQueue?: LazyLoadQueue,
uploading?: boolean,
isOut: boolean,
chat: Chat,
loadPromises?: Promise<any>[],
autoDownload?: ChatAutoDownloadSettings,
managers?: AppManagers
}) {
const items: {size: PhotoSize.photoSize, media: any, message: any}[] = [];
// !lowest msgID will be the FIRST in album
for(const message of messages) {
const media = getMediaFromMessage(message);
3 years ago
const size: any = media._ === 'photo' ? choosePhotoSize(media, 480, 480) : {w: media.w, h: media.h};
items.push({size, media, message});
3 years ago
}
/* // * pending
if(storage[0] < 0) {
items.reverse();
} */
prepareAlbum({
container: attachmentDiv,
items: items.map((i) => ({w: i.size.w, h: i.size.h})),
3 years ago
maxWidth: mediaSizes.active.album.width,
minWidth: 100,
spacing: 2,
forMedia: true
});
items.forEach((item, idx) => {
const {size, media, message} = item;
const div = attachmentDiv.children[idx] as HTMLElement;
div.dataset.mid = '' + message.mid;
div.dataset.peerId = '' + message.peerId;
const mediaDiv = div.firstElementChild as HTMLElement;
const isPhoto = media._ === 'photo';
let thumbPromise: Promise<any>;
3 years ago
if(isPhoto) {
thumbPromise = wrapPhoto({
3 years ago
photo: media,
message,
container: mediaDiv,
boxWidth: 0,
boxHeight: 0,
isOut,
lazyLoadQueue,
middleware,
size,
loadPromises,
autoDownloadSize: autoDownload.photo,
managers
});
} else {
thumbPromise = wrapVideo({
3 years ago
doc: message.media.document,
container: mediaDiv,
message,
boxWidth: 0,
boxHeight: 0,
withTail: false,
isOut,
lazyLoadQueue,
middleware,
loadPromises,
autoDownload,
managers
});
}
if(thumbPromise && loadPromises) {
loadPromises.push(thumbPromise);
}
3 years ago
});
}