From 2bcfb9f6f473101f875a03718b8ec031a83750b1 Mon Sep 17 00:00:00 2001 From: "gorbenko.pavel" Date: Wed, 14 Oct 2026 14:36:39 +0500 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=B2=20=D0=BF=D0=B8=D1=81=D1=8C=D0=BC?= =?UTF-8?q?=D0=B5=20=D0=BE=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B8=20=D1=87=D0=B0=D1=82=D0=B0=20=E2=80=94=20=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=BA=D0=B0=20=C2=AB=D0=9F=D1=80=D0=B8=D0=BA?= =?UTF-8?q?=D1=80=D0=B5=D0=BF=D0=BB=D0=B5=D0=BD=D1=8B=20=D1=84=D0=B0=D0=B9?= =?UTF-8?q?=D0=BB=D1=8B:=20=E2=80=A6=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Иначе сообщение из одного файла приходило письмом с пустым текстом. Co-Authored-By: Claude Opus 5.5 --- .../requestPortal/shared/chat/chatNotify.test.ts | 9 +++++++++ .../requestPortal/shared/chat/chatNotify.ts | 15 ++++++++++++++- .../requestPortal/shared/chat/useRequestChat.ts | 8 ++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/webparts/requestPortal/shared/chat/chatNotify.test.ts b/src/webparts/requestPortal/shared/chat/chatNotify.test.ts index 57ea5f1..ffc622f 100644 --- a/src/webparts/requestPortal/shared/chat/chatNotify.test.ts +++ b/src/webparts/requestPortal/shared/chat/chatNotify.test.ts @@ -50,6 +50,15 @@ describe('buildChatNotifyBody', () => { expect(self?.mentionedEmails).toEqual(['petrova@tnsu.kz']); }); + it('файлы — строкой в тексте письма, и при пустом сообщении тоже', () => { + expect(buildChatNotifyBody({ ...base, fileNames: ['акт.pdf', 'скан.jpg'] })?.messageText).toBe( + 'Текст\n\nПрикреплены файлы: акт.pdf, скан.jpg' + ); + expect(buildChatNotifyBody({ ...base, messageText: '', fileNames: ['акт.pdf'] })?.messageText).toBe( + 'Прикреплены файлы: акт.pdf' + ); + }); + it('нет ни инициатора, ни отметок — поток не вызываем', () => { expect(buildChatNotifyBody({ ...base, initiatorEmail: '' })).toBeUndefined(); }); diff --git a/src/webparts/requestPortal/shared/chat/chatNotify.ts b/src/webparts/requestPortal/shared/chat/chatNotify.ts index 019fd25..209adaf 100644 --- a/src/webparts/requestPortal/shared/chat/chatNotify.ts +++ b/src/webparts/requestPortal/shared/chat/chatNotify.ts @@ -23,6 +23,8 @@ export interface IChatNotifyInput { authorName: string; authorEmail: string; messageText: string; + /** Имена приложенных файлов, как их выбрал пользователь (без складского префикса). */ + fileNames?: string[]; requestCode: string; requestUrl: string; requestTitle: string; @@ -32,6 +34,17 @@ export interface IChatNotifyInput { const sameEmail = (a: string, b: string): boolean => a.toLowerCase() === b.toLowerCase(); +/** + * Текст для письма: сообщение и строка о файлах. Без неё сообщение из одного + * файла пришло бы письмом с пустым текстом. Сами файлы в письмо не кладём — + * они в библиотеке, открываются по ссылке на заявку. + */ +function letterText(text: string, fileNames: string[]): string { + if (fileNames.length === 0) return text; + const files = `Прикреплены файлы: ${fileNames.join(', ')}`; + return text ? `${text}\n\n${files}` : files; +} + /** * Собрать тело запроса к потоку или undefined, если писать некому. * @@ -62,7 +75,7 @@ export function buildChatNotifyBody(input: IChatNotifyInput): IChatNotifyBody | initiatorEmail, mentionedEmails: mentioned, authorName: input.authorName, - messageText: input.messageText, + messageText: letterText(input.messageText, input.fileNames || []), RequestUniqueCode: input.requestCode, requestUrl: input.requestUrl, requestTitle: input.requestTitle diff --git a/src/webparts/requestPortal/shared/chat/useRequestChat.ts b/src/webparts/requestPortal/shared/chat/useRequestChat.ts index 993aa1e..08a3f0f 100644 --- a/src/webparts/requestPortal/shared/chat/useRequestChat.ts +++ b/src/webparts/requestPortal/shared/chat/useRequestChat.ts @@ -126,7 +126,7 @@ export function useRequestChat( // Письмо о сообщении — после записи комментария и без ожидания: сбой потока // не должен выглядеть как неудачная отправка (см. notifyChatMessage). const notifyAboutMessage = React.useCallback( - (text: string): void => { + (text: string, fileNames: string[]): void => { if (!info) return; const body = buildChatNotifyBody({ initiatorEmail: info.initiator.email, @@ -134,6 +134,7 @@ export function useRequestChat( authorName: currentUserName, authorEmail: currentUserEmail, messageText: text, + fileNames, requestCode: info.code, requestUrl: requestLinkOnPage(PORTAL_PAGE_URL, formKey, itemId, listId), requestTitle: info.title || info.code, @@ -163,7 +164,10 @@ export function useRequestChat( await addChatMessage(formKey, itemId, listId, trimmed, files); setError(undefined); reload(); - notifyAboutMessage(trimmed); + notifyAboutMessage( + trimmed, + files.map((f) => f.name) + ); return true; } catch (e) { setError(`Не удалось отправить сообщение: ${friendlyErrorMessage(e)}`);