Skip to content

Commit

Permalink
Merge pull request #136 from IGAQ/develop
Browse files Browse the repository at this point in the history
Unstable Release
  • Loading branch information
iliaamiri authored Dec 23, 2022
2 parents 22649da + 63dacd4 commit a7e73a9
Show file tree
Hide file tree
Showing 167 changed files with 6,688 additions and 992 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ bun.lockb
!.vscode/launch.json
!.vscode/extensions.json

.env
.env
igaq-google-application-credentials.json
1,748 changes: 1,655 additions & 93 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
"test:e2e": "jest --config ./test/jest-e2e.json --detectOpenHandles"
},
"dependencies": {
"@google-cloud/recaptcha-enterprise": "^3.1.1",
"@nestjs/axios": "^0.1.0",
"@nestjs/common": "^9.0.0",
"@nestjs/config": "^2.2.0",
"@nestjs/core": "^9.0.0",
"@nestjs/event-emitter": "^1.3.1",
"@nestjs/jwt": "^9.0.0",
"@nestjs/passport": "^9.0.0",
"@nestjs/platform-express": "^9.0.0",
"@nestjs/swagger": "^6.1.2",
"@nestjs/throttler": "^3.1.0",
"@prisma/client": "^4.4.0",
"bcrypt": "^5.1.0",
"cache-manager": "^4.0.0",
Expand All @@ -38,6 +41,7 @@
"passport": "^0.6.0",
"passport-jwt": "^4.0.0",
"passport-local": "^1.0.0",
"pusher": "^5.1.1-beta",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0",
Expand Down
10 changes: 10 additions & 0 deletions src/_domain/_domain.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from "@nestjs/common";
import { PusherModule } from "../pusher/pusher.module";
import { CommentEventsListener } from "./listeners/commentEvents.listener";
import { PostEventsListener } from "./listeners/postEvents.listener";

@Module({
imports: [PusherModule],
providers: [CommentEventsListener, PostEventsListener],
})
export class DomainModule {}
13 changes: 13 additions & 0 deletions src/_domain/eventTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export enum EventTypes {
NewCommentOnPost = "new-comment-on-post",
NewCommentOnComment = "new-comment-on-comment",
CommentGotUpVote = "comment-got-up-vote",
CommentGotDownVote = "comment-got-down-vote",
CommentGotRestricted = "comment-got-restricted",
CommentGotApprovedByModerator = "comment-got-approved-by-moderator",
CommentGotPinnedByAuthor = "comment-got-pinned-by-author",
PostGotUpVote = "post-got-up-vote",
PostGotDownVote = "post-got-down-vote",
PostGotRestricted = "post-got-restricted",
PostGotApprovedByModerator = "post-got-approved-by-moderator",
}
16 changes: 16 additions & 0 deletions src/_domain/injectableTokens.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { INotificationMessageMakerService } from "../pusher/services/notificationMessageMaker/notificationMessageMaker.service.interface";

const injectableTokens = {
// Database Context
IDatabaseContext: Symbol.for("IDatabaseContext"),
Expand All @@ -10,22 +12,36 @@ const injectableTokens = {
ISexualityRepository: Symbol("ISexualityRepository"),
IOpennessRepository: Symbol("IOpennessRepository"),
IGenderRepository: Symbol("IGenderRepository"),
IProfileSetupService: Symbol("IProfileSetupService"),
IUserHistoryService: Symbol("IUserHistoryService"),

// Posts Module
IPostsRepository: Symbol("IPostsRepository"),
IPostTypesRepository: Symbol("IPostTypesRepository"),
IPostTagsRepository: Symbol("IPostTagsRepository"),
IPostsService: Symbol("IPostsService"),
IPostAwardRepository: Symbol("IPostAwardRepository"),
IPostsReportService: Symbol("IPostsReportService"),

// Comments Module
ICommentsRepository: Symbol("ICommentsRepository"),
ICommentsService: Symbol("ICommentsService"),
ICommentsReportService: Symbol("ICommentsReportService"),

// Neo4j Module
INeo4jService: Symbol("INeo4jService"),

// Moderation Module
IAutoModerationService: Symbol("IAutoModerationService"),
IModeratorActionsService: Symbol("IModeratorActionsService"),

// Google Cloud reCAPTCHA Enterprise Module
IGoogleCloudRecaptchaEnterpriseService: Symbol("IGoogleCloudRecaptchaEnterpriseService"),

// Pusher
IPusherService: Symbol("IPusherService"),
IPusherUserPoolService: Symbol("IPusherUserPoolService"),
INotificationStashPoolService: Symbol("INotificationStashPoolService"),
INotificationMessageMakerService: Symbol("INotificationMessageMakerService"),
};
export { injectableTokens as _$ };
219 changes: 219 additions & 0 deletions src/_domain/listeners/commentEvents.listener.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
import { Inject, Injectable, Logger, Scope } from "@nestjs/common";
import { IPusherService } from "../../pusher/services/pusher/pusher.service.interface";
import { _$ } from "../injectableTokens";
import { OnEvent } from "@nestjs/event-emitter";
import { ChannelTypesEnum, PusherEvents } from "../../pusher/pusher.types";
import {
CommentGotApprovedByModeratorEvent,
CommentGotRestrictedEvent,
} from "../../moderation/events";
import {
CommentGotPinnedByAuthorEvent,
CommentGotVoteEvent,
NewCommentEvent,
} from "../../comments/events";
import { INotificationMessageMakerService } from "../../pusher/services/notificationMessageMaker/notificationMessageMaker.service.interface";
import { EventTypes } from "../eventTypes";
import { INotificationStashPoolService } from "../../pusher/services/notificationStashPool/notificationStashPool.service.interface";
import { generateUUID } from "../utils";

@Injectable({ scope: Scope.DEFAULT })
export class CommentEventsListener {
private readonly _logger = new Logger(CommentEventsListener.name);

private readonly _pusherService: IPusherService;
private readonly _notificationMessageMakerService: INotificationMessageMakerService;
private readonly _notificationStashPoolService: INotificationStashPoolService;

constructor(
@Inject(_$.IPusherService) pusherService: IPusherService,
@Inject(_$.INotificationMessageMakerService)
notificationMessageMakerService: INotificationMessageMakerService,
@Inject(_$.INotificationStashPoolService)
notificationStashPoolService: INotificationStashPoolService
) {
this._pusherService = pusherService;
this._notificationMessageMakerService = notificationMessageMakerService;
this._notificationStashPoolService = notificationStashPoolService;
}

@OnEvent(EventTypes.CommentGotUpVote, { async: true })
public async handleCommentGotUpVote(event: CommentGotVoteEvent): Promise<void> {
const stashToken = generateUUID();
this._notificationMessageMakerService.stashToken = stashToken;
const message = this._notificationMessageMakerService.makeForCommentGotUpVote({
username: event.username,
postId: event.postId,
commentId: event.commentId,
});

await this.stashAndPushNotification(
stashToken,
EventTypes.CommentGotUpVote,
event.subscriberId,
event.username,
event.avatar,
message
);
}

@OnEvent(EventTypes.CommentGotDownVote, { async: true })
public async handleCommentGotDownVote(event: CommentGotVoteEvent): Promise<void> {
const stashToken = generateUUID();
this._notificationMessageMakerService.stashToken = stashToken;
const message = this._notificationMessageMakerService.makeForCommentGotDownVote({
username: event.username,
postId: event.postId,
commentId: event.commentId,
});

await this.stashAndPushNotification(
stashToken,
EventTypes.CommentGotDownVote,
event.subscriberId,
event.username,
event.avatar,
message
);
}

@OnEvent(EventTypes.CommentGotRestricted, { async: true })
public async handleCommentGotRestricted(event: CommentGotRestrictedEvent): Promise<void> {
const stashToken = generateUUID();
this._notificationMessageMakerService.stashToken = stashToken;
const message = this._notificationMessageMakerService.makeForCommentGotRestricted({
commentContent: event.commentContent,
reason: event.reason,
});

await this.stashAndPushNotification(
stashToken,
EventTypes.CommentGotRestricted,
event.subscriberUserId,
event.username,
event.avatar,
message
);
}

@OnEvent(EventTypes.CommentGotPinnedByAuthor, { async: true })
public async handleCommentGotPinnedByAuthor(
event: CommentGotPinnedByAuthorEvent
): Promise<void> {
const stashToken = generateUUID();
this._notificationMessageMakerService.stashToken = stashToken;
const message = this._notificationMessageMakerService.makeForCommentGotPinnedByAuthor({
commentId: event.commentId,
postId: event.postId,
commentContent: event.commentContent,
username: event.username,
});

await this.stashAndPushNotification(
stashToken,
EventTypes.CommentGotPinnedByAuthor,
event.subscriberId,
event.username,
event.avatar,
message
);
}

@OnEvent(EventTypes.CommentGotApprovedByModerator, { async: true })
public async handleCommentGotApprovedByModerator(
event: CommentGotApprovedByModeratorEvent
): Promise<void> {
const stashToken = generateUUID();
this._notificationMessageMakerService.stashToken = stashToken;
const message = this._notificationMessageMakerService.makeForCommentGotApprovedByModerator({
commentId: event.commentId,
postId: event.postId,
username: event.username,
});

await this.stashAndPushNotification(
stashToken,
EventTypes.CommentGotApprovedByModerator,
event.subscriberId,
event.username,
event.avatar,
message
);
}

@OnEvent(EventTypes.NewCommentOnComment, { async: true })
public async handleNewCommentOnComment(event: NewCommentEvent): Promise<void> {
const stashToken = generateUUID();
this._notificationMessageMakerService.stashToken = stashToken;
const message = this._notificationMessageMakerService.makeForNewCommentOnComment({
postId: event.postId,
commentId: event.commentId,
username: event.username,
commentContent: event.commentContent,
});

await this.stashAndPushNotification(
stashToken,
EventTypes.NewCommentOnComment,
event.subscriberId,
event.username,
event.avatar,
message
);
}

@OnEvent(EventTypes.NewCommentOnPost, { async: true })
public async handleNewCommentOnPost(event: NewCommentEvent): Promise<void> {
const stashToken = generateUUID();
this._notificationMessageMakerService.stashToken = stashToken;
const message = this._notificationMessageMakerService.makeForNewCommentOnPost({
postId: event.postId,
commentId: event.commentId,
username: event.username,
postTypeName: event.postTypeName,
commentContent: event.commentContent,
});

await this.stashAndPushNotification(
stashToken,
EventTypes.NewCommentOnPost,
event.subscriberId,
event.username,
event.avatar,
message
);
}

private async stashAndPushNotification(
stashToken: UUID,
evenType: EventTypes,
subscriberId: UUID,
username: string,
avatar: string,
message: string
): Promise<void> {
const stashPoolItem = await this._notificationStashPoolService.stashNotification(
stashToken,
subscriberId,
message,
avatar,
username
);

this._pusherService
.triggerUser(
ChannelTypesEnum.IGAQ_Notification,
PusherEvents.UserReceivesNotification,
subscriberId,
{
subscriberId,
username: username,
avatar: avatar,
composedMessage: message,
stashToken: stashToken,
}
)
.then(() => this._logger.verbose(`Event ${evenType} got pushed to ${username}`))
.catch(e => this._logger.error(`Event ${evenType} ERRORED: `, e));
}
}
Loading

0 comments on commit a7e73a9

Please sign in to comment.