feat(chat): личный чат тьютор ↔ админ с вложениями

Диалоги 1:1 (один тред на тьютора), отдельный SSE-канал whatido:chat
вместо общей ленты notifications, вложения с белым списком расширений
и вставкой из буфера (Ctrl+V), очистка по chat_retention_days.
Таблицы в бэкап, chat_attachments добавлен в sweepOrphanedUploads.
This commit is contained in:
dev
2026-10-05 17:30:26 +03:00
parent 3836fc82ef
commit 235fd43af4
12 changed files with 1409 additions and 10 deletions
+29 -3
View File
@@ -7,12 +7,13 @@ const BACKUP_TABLES = [
'groups', 'students', 'entries', 'project_files', 'branches', 'users', 'user_branches',
'group_photos', 'entry_photos', 'modules', 'student_photos', 'share_links', 'photo_jobs',
'lesson_reports', 'lesson_report_versions', 'audit_log', 'notifications',
'notification_reads', 'banned_ips',
'notification_reads', 'banned_ips', 'chat_threads', 'chat_messages', 'chat_attachments',
];
const BACKUP_SEQUENCE_TABLES = [
'groups', 'students', 'entries', 'project_files', 'branches', 'users', 'group_photos',
'entry_photos', 'modules', 'student_photos', 'share_links', 'photo_jobs', 'lesson_reports',
'lesson_report_versions', 'audit_log', 'notifications',
'lesson_report_versions', 'audit_log', 'notifications', 'chat_threads', 'chat_messages',
'chat_attachments',
];
function isSupportedBackupVersion(data) {
@@ -462,7 +463,32 @@ function normalizeRestoreData(data) {
created_at: optTs(x.created_at),
finished_at: optTs(x.finished_at),
}));
return { groups, students, entries, project_files, settings, branches, users, user_branches, entry_photos, student_photos, group_photos, share_links, modules, photo_jobs, lesson_reports, lesson_report_versions, audit_log, notifications, notification_reads, banned_ips };
const chat_threads = (data.chat_threads || []).map(x => ({
id: reqInt(x.id),
tutor_id: reqInt(x.tutor_id),
last_message_at: optTs(x.last_message_at),
last_message_text: optStr(x.last_message_text, 300),
tutor_unread: optInt(x.tutor_unread, 0, 2147483647) ?? 0,
admin_unread: optInt(x.admin_unread, 0, 2147483647) ?? 0,
created_at: optTs(x.created_at),
}));
const chat_messages = (data.chat_messages || []).map(x => ({
id: reqInt(x.id),
thread_id: reqInt(x.thread_id),
sender_id: reqInt(x.sender_id),
body: optStr(x.body, 5000) ?? '',
created_at: optTs(x.created_at),
}));
const chat_attachments = (data.chat_attachments || []).map(x => ({
id: reqInt(x.id),
message_id: reqInt(x.message_id),
token: reqToken(x.token),
path: reqUploadPath(x.path, 255),
name: reqStr(x.name, 255),
size: optInt(x.size, 0, 2147483647) ?? 0,
created_at: optTs(x.created_at),
}));
return { groups, students, entries, project_files, settings, branches, users, user_branches, entry_photos, student_photos, group_photos, share_links, modules, photo_jobs, lesson_reports, lesson_report_versions, audit_log, notifications, notification_reads, banned_ips, chat_threads, chat_messages, chat_attachments };
}
module.exports = {