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,