SHA256
Добавить лицензию CC0 1.0
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { t } from '../i18n/index.js';
|
||||
// Вложения личных сообщений: превью картинок и видео после расшифровки и карточка файла со «Скачать».
|
||||
// Общие для ленты чата и экрана «Медиа и файлы».
|
||||
import { decryptDmFileToBlob, downloadAndDecryptDmFile } from '../services/dm-file-service.js';
|
||||
import { decryptDmFileToBlob, downloadAndDecryptDmFile, isDmFileExpired } from '../services/dm-file-service.js';
|
||||
import { formatBytes, getAttachmentKind } from '../services/attachment-format.js';
|
||||
import { showToast } from '../services/channels-ux.js';
|
||||
import { iconHtml } from './ui-icon.js';
|
||||
@@ -17,7 +17,7 @@ const dmMediaBlobs = new Map();
|
||||
const DM_MEDIA_CACHE_LIMIT = 40;
|
||||
|
||||
export function isDmInlineMedia(attachment) {
|
||||
if (attachment?.kind === 'voice') return false;
|
||||
if (attachment?.kind === 'voice' || isDmFileExpired(attachment)) return false;
|
||||
const size = Number(attachment?.size || 0);
|
||||
if (!(size > 0 && size <= DM_INLINE_MEDIA_MAX_BYTES)) return false;
|
||||
const kind = getAttachmentKind(attachment);
|
||||
@@ -27,6 +27,7 @@ export function isDmInlineMedia(attachment) {
|
||||
// Расшифрованный файл держим в памяти: лента перерисовывается на каждое новое сообщение,
|
||||
// и без кэша картинка расшифровывалась бы и мигала заново.
|
||||
export function resolveDmMediaUrl(attachment) {
|
||||
if (isDmFileExpired(attachment)) return Promise.reject(new Error('DM_FILE_EXPIRED'));
|
||||
const key = String(attachment?.id || attachment?.url || '');
|
||||
let pending = dmMediaBlobs.get(key);
|
||||
if (!pending) {
|
||||
@@ -40,7 +41,24 @@ export function resolveDmMediaUrl(attachment) {
|
||||
return pending.then((blob) => ({ url: URL.createObjectURL(blob), objectUrl: true }));
|
||||
}
|
||||
|
||||
export function createDmExpiredAttachmentCard(attachment) {
|
||||
const card = document.createElement('div');
|
||||
card.className = 'dm-file-card';
|
||||
const copy = document.createElement('span');
|
||||
copy.className = 'dm-file-card__copy';
|
||||
const name = document.createElement('strong');
|
||||
name.className = 'dm-file-card__name';
|
||||
name.textContent = attachment?.name || 'file';
|
||||
const info = document.createElement('span');
|
||||
info.className = 'dm-file-card__meta';
|
||||
info.textContent = t('screens.dm_attachments.file_expired');
|
||||
copy.append(name, info);
|
||||
card.append(copy);
|
||||
return card;
|
||||
}
|
||||
|
||||
export function createDmFileAttachmentCard(attachment) {
|
||||
if (isDmFileExpired(attachment)) return createDmExpiredAttachmentCard(attachment);
|
||||
const fileCard = document.createElement('div');
|
||||
fileCard.className = 'dm-file-card';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user