SHA256
UI: улучшить превью и файлы вложений
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { channels as mockChannels } from '../mock-data.js';
|
||||
import { authService, setChannelsFeed, state } from '../state.js';
|
||||
import { toUserMessage } from '../services/ui-error-texts.js';
|
||||
import { parseMessageAttachments } from '../services/attachment-format.js';
|
||||
import {
|
||||
animatePress,
|
||||
createSkeletonCard,
|
||||
@@ -20,6 +21,11 @@ const MENU_OVERLAY_ID = 'channels-context-menu-overlay';
|
||||
const CHANNEL_TYPE_STORIES = 0;
|
||||
const CHANNEL_TYPE_PERSONAL = 100;
|
||||
|
||||
function cleanChannelMessagePreview(text) {
|
||||
const parsed = parseMessageAttachments(text);
|
||||
return String(parsed.text || '').trim() || (parsed.attachments.length ? 'Вложение' : 'Ждем ваших начинаний');
|
||||
}
|
||||
|
||||
function isChannelsDemoMode() {
|
||||
try {
|
||||
const qs = new URLSearchParams(window.location.search);
|
||||
@@ -610,7 +616,7 @@ function mapMockGroups() {
|
||||
ownerBlockchainName: String(channel.ownerName || ''),
|
||||
channelName: String(channel.channelName || channel.title || channel.id),
|
||||
}),
|
||||
messagePreview: channel.lastMessage || 'Ждем ваших начинаний',
|
||||
messagePreview: cleanChannelMessagePreview(channel.lastMessage),
|
||||
isSubscribed: channel.kind !== 'own' && channel.kind !== 'own-personal',
|
||||
isOwnChannel: channel.kind === 'own' || channel.kind === 'own-personal',
|
||||
notificationsEnabled: false,
|
||||
@@ -665,7 +671,7 @@ function mapApiChannelRow(summary, bucketKey, idx, index, notificationsState) {
|
||||
channelDescription,
|
||||
channelTypeCode,
|
||||
channelTypeVersion,
|
||||
messagePreview: summary?.lastMessage?.text || 'Ждем ваших начинаний',
|
||||
messagePreview: cleanChannelMessagePreview(summary?.lastMessage?.text),
|
||||
messagesCount: Number(summary?.messagesCount || 0),
|
||||
unreadCount: Number(summary?.unreadCount || 0),
|
||||
lastMessageAt: Number(summary?.lastMessage?.createdAtMs || 0),
|
||||
|
||||
@@ -206,17 +206,16 @@ function replaceWithUnavailable(slide, messageTimestampMs) {
|
||||
}
|
||||
|
||||
function createFileCard({ item, url, messageTimestampMs, slide }) {
|
||||
const ext = getAttachmentExtension(item.name).toUpperCase() || 'FILE';
|
||||
const card = document.createElement('div');
|
||||
card.className = 'message-attachment-file-card';
|
||||
card.role = 'button';
|
||||
card.tabIndex = 0;
|
||||
card.title = 'Скачать файл';
|
||||
card.innerHTML = `
|
||||
<div class="message-attachment-file-ext">${escapeHtml(ext)}</div>
|
||||
<div class="message-attachment-file-ext">Файл</div>
|
||||
<div class="message-attachment-file-main">
|
||||
<div class="message-attachment-name">${escapeHtml(item.name)}</div>
|
||||
<div class="message-attachment-meta">${escapeHtml(formatBytes(item.size))} · ${escapeHtml(item.ar)}</div>
|
||||
<div class="message-attachment-meta">${escapeHtml(formatBytes(item.size))}</div>
|
||||
</div>
|
||||
`;
|
||||
const openFile = () => window.open(url, '_blank', 'noopener');
|
||||
@@ -229,7 +228,6 @@ function createFileCard({ item, url, messageTimestampMs, slide }) {
|
||||
event.preventDefault();
|
||||
openFile();
|
||||
});
|
||||
card.append(createDownloadLink(url));
|
||||
void fetch(url, { method: 'HEAD', cache: 'no-store' })
|
||||
.then((response) => {
|
||||
if (!response.ok) replaceWithUnavailable(slide, messageTimestampMs);
|
||||
@@ -327,8 +325,8 @@ export function createAttachmentCarouselElement(attachments = [], { gateway = ''
|
||||
slide.append(kind === 'file'
|
||||
? createFileCard({ item, url, messageTimestampMs, slide })
|
||||
: createMediaSlide({ item, url, kind, messageTimestampMs, slide }));
|
||||
prev.disabled = index <= 0;
|
||||
next.disabled = index >= items.length - 1;
|
||||
prev.hidden = items.length <= 1 || index <= 0;
|
||||
next.hidden = items.length <= 1 || index >= items.length - 1;
|
||||
counter.textContent = `${index + 1} из ${items.length}`;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user