fix(files): аватары и баннеры доступны авторизованным пользователям
Аватар нельзя было показать в списке друзей: файл без комнаты был доступен только загрузившему. Добавлено назначение файла (`files.purpose`: attachment | avatar | banner, миграция 00006): аватары и баннеры отдаются любому авторизованному пользователю, вложения по-прежнему проверяются по правам комнаты, а непривязанные загрузки остаются приватными.
This commit is contained in:
@@ -194,7 +194,7 @@ export function parseChannelPayload(value: unknown): Channel | null {
|
||||
if (id === undefined || name === undefined) {
|
||||
return null;
|
||||
}
|
||||
if (type !== 'text' && type !== 'voice' && type !== 'category') {
|
||||
if (type !== 'text' && type !== 'voice' && type !== 'category' && type !== 'dm') {
|
||||
return null;
|
||||
}
|
||||
const channel: Channel = {
|
||||
@@ -226,9 +226,94 @@ export function parseChannelPayload(value: unknown): Channel | null {
|
||||
if (typeof record['can_view'] === 'boolean') {
|
||||
channel.can_view = record['can_view'];
|
||||
}
|
||||
// Личная беседа: собеседник и последнее сообщение (READY и CHANNEL_*).
|
||||
const recipientId = asString(record['recipient_id']);
|
||||
const iconFileId = asString(record['icon_file_id']);
|
||||
const status = asString(record['status']);
|
||||
const lastMessageId = asString(record['last_message_id']);
|
||||
const lastMessageAt = asString(record['last_message_at']);
|
||||
if (recipientId !== undefined) {
|
||||
channel.recipient_id = recipientId;
|
||||
}
|
||||
if (iconFileId !== undefined) {
|
||||
channel.icon_file_id = iconFileId;
|
||||
}
|
||||
if (userStatuses.includes(status as UserStatus)) {
|
||||
channel.status = status as UserStatus;
|
||||
}
|
||||
if (lastMessageId !== undefined) {
|
||||
channel.last_message_id = lastMessageId;
|
||||
}
|
||||
if (lastMessageAt !== undefined) {
|
||||
channel.last_message_at = lastMessageAt;
|
||||
}
|
||||
return channel;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Друзья и личные беседы (AGENT.md §8.3 / 7.8) */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
export interface DmChannelEvent {
|
||||
channel_id: string;
|
||||
}
|
||||
|
||||
export interface RelationshipEvent {
|
||||
user_id: string;
|
||||
}
|
||||
|
||||
export interface PresenceEvent {
|
||||
user_id: string;
|
||||
status?: UserStatus;
|
||||
visible_status?: UserStatus;
|
||||
custom_status?: string;
|
||||
last_seen_at?: string;
|
||||
}
|
||||
|
||||
/** `DM_CHANNEL_CREATE`: создана личная беседа — перечитываем список бесед. */
|
||||
export function parseDmChannelEvent(value: unknown): DmChannelEvent | null {
|
||||
const record = asRecord(value);
|
||||
const channelId = asString(record?.['channel_id']);
|
||||
return record === null || channelId === undefined ? null : { channel_id: channelId };
|
||||
}
|
||||
|
||||
/** `RELATIONSHIP_UPDATE`: изменилась связь с пользователем. */
|
||||
export function parseRelationshipEvent(value: unknown): RelationshipEvent | null {
|
||||
const record = asRecord(value);
|
||||
const userId = asString(record?.['user_id']);
|
||||
return record === null || userId === undefined ? null : { user_id: userId };
|
||||
}
|
||||
|
||||
/**
|
||||
* `PRESENCE_UPDATE`: статус друга. Поля необязательны — сервер присылает
|
||||
* только изменившиеся, поэтому разбираем каждое отдельно.
|
||||
*/
|
||||
export function parsePresenceEvent(value: unknown): PresenceEvent | null {
|
||||
const record = asRecord(value);
|
||||
const userId = asString(record?.['user_id']);
|
||||
if (record === null || userId === undefined) {
|
||||
return null;
|
||||
}
|
||||
const event: PresenceEvent = { user_id: userId };
|
||||
const status = asString(record['status']);
|
||||
const visibleStatus = asString(record['visible_status']);
|
||||
const customStatus = asString(record['custom_status']);
|
||||
const lastSeenAt = asString(record['last_seen_at']);
|
||||
if (userStatuses.includes(status as UserStatus)) {
|
||||
event.status = status as UserStatus;
|
||||
}
|
||||
if (userStatuses.includes(visibleStatus as UserStatus)) {
|
||||
event.visible_status = visibleStatus as UserStatus;
|
||||
}
|
||||
if (customStatus !== undefined) {
|
||||
event.custom_status = customStatus;
|
||||
}
|
||||
if (lastSeenAt !== undefined) {
|
||||
event.last_seen_at = lastSeenAt;
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* События сообщений Фазы 2 (AGENT.md §8.3) */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
Reference in New Issue
Block a user