SHA256
Refine direct message profile data
This commit is contained in:
@@ -52,6 +52,18 @@ function cleanChannelMessagePreview(text) {
|
||||
|| (parsed.attachments.length ? 'Вложение' : 'Ждем ваших начинаний');
|
||||
}
|
||||
|
||||
// Keep the channel-list preview tolerant to small API naming changes. The current
|
||||
// server uses lastMessage.text/createdAtMs; legacy/alternate payloads are accepted
|
||||
// so the third line (last message + time) does not silently disappear.
|
||||
function resolveChannelLastMessage(summary) {
|
||||
const row = summary?.lastMessage || summary?.latestMessage || summary?.last_message || null;
|
||||
if (!row || typeof row !== 'object') return { text: '', createdAtMs: 0 };
|
||||
return {
|
||||
text: String(row.text ?? row.messageText ?? row.preview ?? row.body ?? '').trim(),
|
||||
createdAtMs: Number(row.createdAtMs ?? row.timeMs ?? row.created_at_ms ?? 0),
|
||||
};
|
||||
}
|
||||
|
||||
function isChannelsDemoMode() {
|
||||
try {
|
||||
const qs = new URLSearchParams(window.location.search);
|
||||
@@ -719,6 +731,7 @@ function mapApiChannelRow(summary, bucketKey, idx, index, notificationsState) {
|
||||
const isOwn = bucketKey === 'own';
|
||||
const title = displayTitle || channelName;
|
||||
const technicalLabel = `${ownerLogin} / ${channelName}`;
|
||||
const lastMessage = resolveChannelLastMessage(summary);
|
||||
|
||||
return {
|
||||
id: rowId,
|
||||
@@ -737,10 +750,10 @@ function mapApiChannelRow(summary, bucketKey, idx, index, notificationsState) {
|
||||
channelDescription,
|
||||
channelTypeCode,
|
||||
channelTypeVersion,
|
||||
messagePreview: cleanChannelMessagePreview(summary?.lastMessage?.text),
|
||||
messagePreview: cleanChannelMessagePreview(lastMessage.text),
|
||||
messagesCount: Number(summary?.messagesCount || 0),
|
||||
unreadCount: Number(summary?.unreadCount || 0),
|
||||
lastMessageAt: Number(summary?.lastMessage?.createdAtMs || 0),
|
||||
lastMessageAt: Number(lastMessage.createdAtMs || 0),
|
||||
isOwnChannel: isOwn,
|
||||
isSubscribed: !isOwn,
|
||||
notificationsEnabled: notificationsState[rowId] === true,
|
||||
|
||||
Reference in New Issue
Block a user