From 4a420dcf71bf6a73e62c204c7b9ffbffc008fc9a Mon Sep 17 00:00:00 2001 From: Pavel Gnedov Date: Wed, 24 Jul 2024 07:47:39 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BB=D0=B8=D1=87=D0=BD=D1=8B=D1=85=20=D1=83=D0=B2?= =?UTF-8?q?=D0=B5=D0=B4=D0=BE=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20redmine5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/event-emitter/src/users/users.service.ts | 26 +++++++++++++++++++ .../personal-notifications.service.ts | 11 ++++++++ 2 files changed, 37 insertions(+) diff --git a/libs/event-emitter/src/users/users.service.ts b/libs/event-emitter/src/users/users.service.ts index a4c7667..2cfb407 100644 --- a/libs/event-emitter/src/users/users.service.ts +++ b/libs/event-emitter/src/users/users.service.ts @@ -46,6 +46,32 @@ export class UsersService { ); } + async findUserByLogin(login: string): Promise { + const userFromMemoryCache = this.memoryCache.find((item) => { + const email = item.mail; + if (!email) return false; + return email.startsWith(login); + }); + if (userFromMemoryCache) { + return RedmineTypes.CreateUser(userFromMemoryCache); + } + const usersDb = await this.users.getDatasource(); + const res = await usersDb.find({ + selector: { + mail: { + $regex: login, + }, + }, + limit: 1, + }); + if (!res || !res.docs || !res.docs[0]) { + return null; + } + const userFromDb = res.docs[0]; + this.memoryCache.set(userFromDb.id, userFromDb); + return RedmineTypes.CreateUser(userFromDb); + } + async findUserByName( firstname: string, lastname: string, diff --git a/src/notifications/personal-notifications.service.ts b/src/notifications/personal-notifications.service.ts index beeac60..55c2785 100644 --- a/src/notifications/personal-notifications.service.ts +++ b/src/notifications/personal-notifications.service.ts @@ -9,6 +9,7 @@ import { PersonalParsedMessage } from 'src/models/personal-parsed-message.model' @Injectable() export class PersonalNotificationsService { private userNameRe = /@([\wА-Яа-яЁё]+) ([\wА-Яа-яЁё]+)@/g; + private userName2Re = /@([\wА-Яа-яЁё\.]+)/g; private logger = new Logger(PersonalNotificationsService.name); $messages = new Subject(); @@ -71,6 +72,16 @@ export class PersonalNotificationsService { } result = results.next(); } + const results2 = notes.matchAll(this.userName2Re); + let result2 = results2.next(); + while (!result2.done) { + if (result.value && result.value[1]) { + const login = result.value[1]; + const user = await this.usersService.findUserByLogin(login); + if (user) recipients.push(user.id); + } + result2 = results2.next(); + } if (recipients.length > 0) { return { message: notes,