Добавить лицензию CC0 1.0

This commit is contained in:
AidarKC
2026-11-16 23:50:28 +03:00
parent 548160f7f8
commit c477560632
39 changed files with 901 additions and 138 deletions
+11 -6
View File
@@ -10,7 +10,7 @@ import { getAttachmentKind } from '../services/attachment-format.js';
import { parseDmTechBlocks } from '../services/dm-tech-blocks.js';
import { loadFullDmHistory, resolveMessageTimeMs } from '../services/dm-history.js';
import { formatClockTime, formatDayLabel } from '../services/channels-ux.js';
import { getChatMessages, getRememberedDmPeer, normalizeDmChatId } from '../state.js';
import { getChatMessages, getRememberedDmPeer, normalizeDmChatId, state } from '../state.js';
import { navigateUp } from '../router.js';
export const pageMeta = { id: 'chat-media-view', get title() { return t('screens.chat_media_view.text_001'); } };
@@ -18,16 +18,21 @@ export const pageMeta = { id: 'chat-media-view', get title() { return t('screens
const monthTitle = (date) => formatDate(date, { month: 'long', year: 'numeric' });
// Все вложения переписки, от новых к старым.
function collectAttachments(chatId) {
function collectAttachments(chatId, currentLogin) {
const media = [];
const files = [];
for (const msg of getChatMessages(chatId)) {
if (msg?.deleted) continue;
const parsed = parseDmTechBlocks(String(msg?.text || ''));
const list = Array.isArray(parsed.fileAttachments) ? parsed.fileAttachments : (parsed.fileAttachment ? [parsed.fileAttachment] : []);
for (const attachment of list) {
if (attachment?.kind === 'voice') continue;
const entry = { attachment, timeMs: resolveMessageTimeMs(msg), from: msg?.from };
for (const item of list) {
if (item?.kind === 'voice') continue;
const timeMs = resolveMessageTimeMs(msg);
const attachment = { ...item,
senderLogin: msg?.from === 'out' ? currentLogin : chatId,
messageTimestampMs: timeMs,
};
const entry = { attachment, timeMs, from: msg?.from };
(isDmInlineMedia(attachment) ? media : files).push(entry);
}
}
@@ -182,7 +187,7 @@ export function render({ navigate, route, chrome }) {
function renderBody() {
if (disposed) return;
const { media, files } = collectAttachments(chatId);
const { media, files } = collectAttachments(chatId, state.session?.login);
for (const [value, { button, label }] of tabButtons) {
const count = value === 'media' ? media.length : files.length;
button.textContent = count ? `${label} · ${count}` : label;
+11 -5
View File
@@ -42,7 +42,8 @@ import {
DM_MAX_ATTACHMENTS_PER_MESSAGE,
} from '../services/dm-file-service.js';
import { createAttachmentCarouselElement } from '../services/attachment-format.js';
import { createDmFileAttachmentCard, isDmInlineMedia, resolveDmMediaUrl } from '../components/dm-attachments.js';
import { createDmFileAttachmentCard, createDmExpiredAttachmentCard, isDmInlineMedia, resolveDmMediaUrl } from '../components/dm-attachments.js';
import { isDmFileExpired } from '../services/dm-file-service.js';
import {
DM_HISTORY_PAGE_SIZE,
isDmHistoryFullyLoaded,
@@ -1217,7 +1218,12 @@ function renderLog(
const bubble = document.createElement('div');
const parsedText = parseDmTechBlocks(String(msg?.text || ''));
const dmAttachments = Array.isArray(parsedText.fileAttachments) ? parsedText.fileAttachments : (parsedText.fileAttachment ? [parsedText.fileAttachment] : []);
const rawDmAttachments = Array.isArray(parsedText.fileAttachments) ? parsedText.fileAttachments : (parsedText.fileAttachment ? [parsedText.fileAttachment] : []);
const dmAttachments = rawDmAttachments.map((attachment) => ({
...attachment,
senderLogin: msg?.from === 'out' ? state.session?.login : chatId,
messageTimestampMs: msgTimeMs,
}));
const autoKind = parsedText.callSummary ? 'call-tech' : (dmAttachments.length ? 'file-tech' : '');
const bubbleKind = String(msg?.kind || autoKind || '').trim();
bubble.className = `bubble ${msg.from}${bubbleKind ? ` ${bubbleKind}` : ''}`;
@@ -1280,9 +1286,9 @@ function renderLog(
for (const attachment of dmAttachments) {
if (media.includes(attachment)) continue;
attachmentsWrap.append(
attachment?.kind === 'voice'
? createDmVoiceAttachmentCard(attachment)
: createDmFileAttachmentCard(attachment),
isDmFileExpired(attachment)
? createDmExpiredAttachmentCard(attachment)
: (attachment?.kind === 'voice' ? createDmVoiceAttachmentCard(attachment) : createDmFileAttachmentCard(attachment)),
);
}
bubble.append(attachmentsWrap);
@@ -18,7 +18,7 @@ import { t } from '../../i18n/index.js';
import { renderUserAvatar, buildAvatarInitials } from '../../components/avatar-image.js';
import { state } from '../../state.js';
import { buildArweaveDataUrl } from '../../services/arweave-file-service.js';
import { avatarR2Url } from '../../services/public-file-service.js';
import { resolvePublicFileUrl } from '../../services/public-file-service.js';
const SVGNS = 'http://www.w3.org/2000/svg';
@@ -158,7 +158,7 @@ async function resolveServerAvatarPhotoSrc(src) {
const authorLogin = String(src?.login || src?.id || '').trim();
if (txId || !pr || !authorLogin) return '';
try {
return avatarR2Url(pr);
return await resolvePublicFileUrl({ pr, authorLogin });
} catch {
return '';
}
+2 -2
View File
@@ -30,7 +30,7 @@ import { t } from '../../i18n/index.js';
import { buildAvatarInitials } from '../../components/avatar-image.js';
import { state } from '../../state.js';
import { buildArweaveDataUrl } from '../../services/arweave-file-service.js';
import { avatarR2Url } from '../../services/public-file-service.js';
import { resolvePublicFileUrl } from '../../services/public-file-service.js';
import { ISLAND_COLORS, layoutIslands, tieWeight } from './communities.js';
const NODE_R = { focus: 30, 1: 22, 2: 15, 3: 11 };
@@ -633,7 +633,7 @@ async function avatarUrlFromServer(node) {
const authorLogin = String(node?.login || node?.id || '').trim();
if (String(raw.ar || '').trim() || !pr || !authorLogin) return '';
try {
return avatarR2Url(pr);
return await resolvePublicFileUrl({ pr, authorLogin });
} catch {
return '';
}