Skip to content

Commit

Permalink
Merge pull request #30 from anatawa12/notification-tl-limit
Browse files Browse the repository at this point in the history
feat: 通知の保存上限を変更可能に
  • Loading branch information
anatawa12 committed Aug 6, 2023
2 parents 93df939 + 9bce6ca commit b2fc19c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

### Server
- 通報のメール通知を無効化するオプションを追加
- 通知の保存上限を変更可能に

## 13.14.2-kinel.1

Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export type Source = {
nirila?: {
abuseDiscordHook: string;
disableAbuseRepository?: boolean;
notificationLimit?: number;
}
};

Expand Down
9 changes: 8 additions & 1 deletion packages/backend/src/core/NotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { PushNotificationService } from '@/core/PushNotificationService.js';
import { NotificationEntityService } from '@/core/entities/NotificationEntityService.js';
import { IdService } from '@/core/IdService.js';
import { CacheService } from '@/core/CacheService.js';
import type { Config } from '@/config.js';

@Injectable()
export class NotificationService implements OnApplicationShutdown {
Expand All @@ -31,6 +32,9 @@ export class NotificationService implements OnApplicationShutdown {
@Inject(DI.mutingsRepository)
private mutingsRepository: MutingsRepository,

@Inject(DI.config)
private config: Config,

private notificationEntityService: NotificationEntityService,
private userEntityService: UserEntityService,
private idService: IdService,
Expand Down Expand Up @@ -90,6 +94,9 @@ export class NotificationService implements OnApplicationShutdown {
}
}

let notificationLimit = this.config.nirila?.notificationLimit;
if (!Number.isInteger(notificationLimit)) notificationLimit = 300;

const notification = {
id: this.idService.genId(),
createdAt: new Date(),
Expand All @@ -99,7 +106,7 @@ export class NotificationService implements OnApplicationShutdown {

const redisIdPromise = this.redisClient.xadd(
`notificationTimeline:${notifieeId}`,
'MAXLEN', '~', '300',
'MAXLEN', '~', `${notificationLimit}`,
'*',
'data', JSON.stringify(notification));

Expand Down

0 comments on commit b2fc19c

Please sign in to comment.