Добавлена фильтрация рассылки только актуальных уведомлений
Отфильтровываются давно созданные уведомления
This commit is contained in:
parent
d9cfb523b9
commit
df7e54eb6f
3 changed files with 27 additions and 2 deletions
|
|
@ -6,5 +6,6 @@
|
|||
}
|
||||
},
|
||||
"telegramBotToken": "",
|
||||
"personalMessageTemplate": ""
|
||||
"personalMessageTemplate": "",
|
||||
"periodValidityNotification": 43200 // 12h
|
||||
}
|
||||
|
|
@ -16,4 +16,5 @@ export type AppConfig = {
|
|||
};
|
||||
};
|
||||
telegramBotToken: string;
|
||||
periodValidityNotification: number;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import TelegramBot from 'node-telegram-bot-api';
|
||||
import { Change } from 'src/models/change.model';
|
||||
import { TelegramBotService } from 'src/telegram-bot/telegram-bot.service';
|
||||
|
|
@ -17,8 +18,23 @@ namespace StatusChangeAdapter {
|
|||
|
||||
@Injectable()
|
||||
export class StatusChangeAdapterService {
|
||||
constructor(private telegramBotService: TelegramBotService) {}
|
||||
private periodValidityNotification: number;
|
||||
|
||||
constructor(
|
||||
private telegramBotService: TelegramBotService,
|
||||
private configService: ConfigService,
|
||||
) {
|
||||
this.periodValidityNotification = this.configService.get<number>(
|
||||
'periodValidityNotification',
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: Удалить устаревший метод send
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @see StatusChangeAdapterService.batchSend
|
||||
*/
|
||||
async send(change: Change): Promise<boolean[]> {
|
||||
const promises = change.messages.map((m) => {
|
||||
if (!m || !m.recipient || !m.recipient.id || !m.notification_message) {
|
||||
|
|
@ -51,8 +67,15 @@ export class StatusChangeAdapterService {
|
|||
private getMessages(changes: Change[]): StatusChangeAdapter.MsgFromBatch[] {
|
||||
const res: StatusChangeAdapter.MsgFromBatch[] = [];
|
||||
const store: Record<string, StatusChangeAdapter.MsgFromBatch> = {};
|
||||
const nowTimestamp = new Date().getTime();
|
||||
for (let i = 0; i < changes.length; i++) {
|
||||
const change = changes[i];
|
||||
if (
|
||||
nowTimestamp - change.created_on_timestamp >
|
||||
this.periodValidityNotification
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
for (let j = 0; j < change.messages.length; j++) {
|
||||
const message = change.messages[j];
|
||||
if (!message.change_message) continue;
|
||||
|
|
|
|||
Loading…
Reference in a new issue