Skip to content

Commit

Permalink
Merge pull request #75 from caipira113/develop
Browse files Browse the repository at this point in the history
fix(backend): Resolve issue with UserGroupInvitation in notifications
  • Loading branch information
noridev authored Jun 17, 2023
2 parents 3ccefa7 + ebbd759 commit 3d9d727
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/backend/src/core/entities/NotificationEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Inject, Injectable } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import { In } from 'typeorm';
import { DI } from '@/di-symbols.js';
import type { AccessTokensRepository, FollowRequestsRepository, NoteReactionsRepository, NotesRepository, User, UsersRepository } from '@/models/index.js';
import type { AccessTokensRepository, FollowRequestsRepository, NoteReactionsRepository, NotesRepository, User, UsersRepository, UserGroupInvitationsRepository } from '@/models/index.js';
import { awaitAll } from '@/misc/prelude/await-all.js';
import type { Notification } from '@/models/entities/Notification.js';
import type { Note } from '@/models/entities/Note.js';
Expand Down Expand Up @@ -43,6 +43,9 @@ export class NotificationEntityService implements OnModuleInit {
@Inject(DI.accessTokensRepository)
private accessTokensRepository: AccessTokensRepository,

@Inject(DI.userGroupInvitationsRepository)
private userGroupInvitationsRepository: UserGroupInvitationsRepository,

//private userEntityService: UserEntityService,
//private noteEntityService: NoteEntityService,
//private userGroupInvitationEntityService: UserGroupInvitationEntityService,
Expand Down Expand Up @@ -156,6 +159,14 @@ export class NotificationEntityService implements OnModuleInit {
validNotifications = validNotifications.filter(x => (x.type !== 'receiveFollowRequest') || reqs.some(r => r.followerId === x.notifierId));
}

const groupInvitedNotifications = validNotifications.filter(x => x.type === 'groupInvited');
if (groupInvitedNotifications.length > 0) {
const existingInvitationIds = await this.userGroupInvitationsRepository.find({
where: { id: In(groupInvitedNotifications.map(x => x.userGroupInvitationId!)) },
});
validNotifications = validNotifications.filter(x => (x.type !== 'groupInvited') || existingInvitationIds.some(r => r.id === x.userGroupInvitationId));
}

return await Promise.all(validNotifications.map(x => this.pack(x, meId, {}, {
packedNotes,
packedUsers,
Expand Down

0 comments on commit 3d9d727

Please sign in to comment.