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)}`);