mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2025-09-18 21:38:07 +00:00
move dialog announcement check into different function
This commit is contained in:
parent
e5aabb2978
commit
4926afc264
1 changed files with 15 additions and 16 deletions
|
@ -69,14 +69,7 @@ export class AnnouncementService {
|
|||
@bindThis
|
||||
public async create(values: Partial<MiAnnouncement>, moderator?: MiUser): Promise<{ raw: MiAnnouncement; packed: Packed<'Announcement'> }> {
|
||||
if (values.display === 'dialog') {
|
||||
// Check how many active dialog queries already exist, to enforce a limit
|
||||
const dialogCount = await this.announcementsRepository.createQueryBuilder('announcement')
|
||||
.where({ isActive: true })
|
||||
.where({ display: 'dialog' })
|
||||
.getCount();
|
||||
if (dialogCount >= 5) {
|
||||
throw new IdentifiableError('c0d15f15-f18e-4a40-bcb1-f310d58204ee', 'Too many dialog announcements.');
|
||||
}
|
||||
await this.assertDialogAnnouncenmentsCountLimit();
|
||||
}
|
||||
|
||||
const announcement = await this.announcementsRepository.insertOne({
|
||||
|
@ -134,14 +127,7 @@ export class AnnouncementService {
|
|||
public async update(announcement: MiAnnouncement, values: Partial<MiAnnouncement>, moderator?: MiUser): Promise<void> {
|
||||
// Check if this operation would produce an active dialog announcement
|
||||
if ((values.display ?? announcement.display) === 'dialog' && (values.isActive ?? announcement.isActive)) {
|
||||
// Check how many active dialog queries already exist, to enforce a limit
|
||||
const dialogCount = await this.announcementsRepository.createQueryBuilder('announcement')
|
||||
.where({ isActive: true })
|
||||
.where({ display: 'dialog' })
|
||||
.getCount();
|
||||
if (dialogCount >= 5) {
|
||||
throw new IdentifiableError('c0d15f15-f18e-4a40-bcb1-f310d58204ee', 'Too many dialog announcements.');
|
||||
}
|
||||
await this.assertDialogAnnouncenmentsCountLimit();
|
||||
}
|
||||
|
||||
await this.announcementsRepository.update(announcement.id, {
|
||||
|
@ -246,4 +232,17 @@ export class AnnouncementService {
|
|||
this.globalEventService.publishMainStream(user.id, 'readAllAnnouncements');
|
||||
}
|
||||
}
|
||||
|
||||
private async assertDialogAnnouncenmentsCountLimit(): Promise<void> {
|
||||
// Check how many active dialog queries already exist, to enforce a limit
|
||||
const dialogCount = await this.announcementsRepository.createQueryBuilder('announcement')
|
||||
.where({
|
||||
isActive: true,
|
||||
display: 'dialog',
|
||||
})
|
||||
.getCount();
|
||||
if (dialogCount >= 5) {
|
||||
throw new IdentifiableError('c0d15f15-f18e-4a40-bcb1-f310d58204ee', 'Too many dialog announcements.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue