From b6871a61cc80e09c61b053acbd297adb2df5edb5 Mon Sep 17 00:00:00 2001 From: Kristaps Fabians Geikins Date: Fri, 24 Jan 2025 10:28:39 +0200 Subject: [PATCH 1/2] chore(server): refactor activityStream invocations - batch #5 - comments --- .../activitystream/domain/operations.ts | 8 +- .../activitystream/events/commentListeners.ts | 120 +++++++++++ .../server/modules/activitystream/index.ts | 6 + .../services/commentActivity.ts | 200 ------------------ .../modules/cli/commands/download/commit.ts | 27 +-- .../modules/cli/commands/download/project.ts | 27 +-- .../server/modules/comments/domain/events.ts | 19 +- .../comments/graph/resolvers/comments.ts | 110 +++------- .../server/modules/comments/services/index.ts | 131 ++++++++++-- .../modules/comments/services/management.ts | 115 +++++++--- .../comments/tests/comments.graph.spec.js | 29 ++- .../modules/comments/tests/comments.spec.ts | 43 +++- .../server/modules/cross-server-sync/index.ts | 25 +-- .../modules/shared/utils/subscriptions.ts | 10 +- 14 files changed, 463 insertions(+), 407 deletions(-) create mode 100644 packages/server/modules/activitystream/events/commentListeners.ts delete mode 100644 packages/server/modules/activitystream/services/commentActivity.ts diff --git a/packages/server/modules/activitystream/domain/operations.ts b/packages/server/modules/activitystream/domain/operations.ts index 8bdcce5ec..480d650a4 100644 --- a/packages/server/modules/activitystream/domain/operations.ts +++ b/packages/server/modules/activitystream/domain/operations.ts @@ -253,26 +253,20 @@ export type AddCommitDeletedActivity = (params: { branchId: string }) => Promise -export type AddCommentCreatedActivity = (params: { - streamId: string - userId: string +export type AddThreadCreatedActivity = (params: { input: CommentCreatedActivityInput comment: CommentRecord }) => Promise export type AddCommentArchivedActivity = (params: { - streamId: string - commentId: string userId: string input: MutationCommentArchiveArgs comment: CommentRecord }) => Promise export type AddReplyAddedActivity = (params: { - streamId: string input: ReplyCreatedActivityInput reply: CommentRecord - userId: string }) => Promise export type AddBranchCreatedActivity = (params: { diff --git a/packages/server/modules/activitystream/events/commentListeners.ts b/packages/server/modules/activitystream/events/commentListeners.ts new file mode 100644 index 000000000..dc03d12f3 --- /dev/null +++ b/packages/server/modules/activitystream/events/commentListeners.ts @@ -0,0 +1,120 @@ +import { + AddThreadCreatedActivity, + AddReplyAddedActivity, + SaveActivity, + AddCommentArchivedActivity +} from '@/modules/activitystream/domain/operations' +import { + CommentCreatedActivityInput, + ReplyCreatedActivityInput +} from '@/modules/activitystream/domain/types' +import { ActionTypes, ResourceTypes } from '@/modules/activitystream/helpers/types' +import { CommentEvents, CommentEventsPayloads } from '@/modules/comments/domain/events' +import { ReplyCreateInput } from '@/modules/core/graph/generated/graphql' +import { EventBusListen } from '@/modules/shared/services/eventBus' +import { has } from 'lodash' +import { OverrideProperties } from 'type-fest' + +const addThreadCreatedActivityFactory = + ({ saveActivity }: { saveActivity: SaveActivity }): AddThreadCreatedActivity => + async (params) => { + const { input, comment } = params + + await saveActivity({ + resourceId: comment.id, + streamId: comment.streamId, + resourceType: ResourceTypes.Comment, + actionType: ActionTypes.Comment.Create, + userId: comment.authorId, + info: { input }, + message: `Comment added: ${comment.id} (${input})` + }) + } + +const isLegacyReplyCreateInput = ( + i: ReplyCreatedActivityInput +): i is ReplyCreateInput => has(i, 'streamId') + +const addReplyAddedActivityFactory = + ({ saveActivity }: { saveActivity: SaveActivity }): AddReplyAddedActivity => + async (params) => { + const { input, reply } = params + + const parentCommentId = isLegacyReplyCreateInput(input) + ? input.parentComment + : input.threadId + await saveActivity({ + streamId: reply.streamId, + resourceType: ResourceTypes.Comment, + resourceId: parentCommentId, + actionType: ActionTypes.Comment.Reply, + userId: reply.authorId, + info: { input }, + message: `Comment reply #${reply.id} created` + }) + } + +const addCommentArchivedActivityFactory = + ({ saveActivity }: { saveActivity: SaveActivity }): AddCommentArchivedActivity => + async (params) => { + const { userId, input, comment } = params + + await saveActivity({ + streamId: comment.streamId, + resourceType: ResourceTypes.Comment, + resourceId: comment.id, + actionType: ActionTypes.Comment.Archive, + userId, + info: { input }, + message: `Comment #${comment.id} archived` + }) + } + +const isReplyCreatedPayload = ( + payload: CommentEventsPayloads[typeof CommentEvents.Created] +): payload is OverrideProperties< + CommentEventsPayloads[typeof CommentEvents.Created], + { + input: ReplyCreatedActivityInput + } +> => { + return payload.isThread === false +} + +const isThreadCreatedPayload = ( + payload: CommentEventsPayloads[typeof CommentEvents.Created] +): payload is OverrideProperties< + CommentEventsPayloads[typeof CommentEvents.Created], + { + input: CommentCreatedActivityInput + } +> => { + return payload.isThread +} + +export const reportCommentActivityFactory = + (deps: { eventListen: EventBusListen; saveActivity: SaveActivity }) => () => { + const addThreadCreatedActivity = addThreadCreatedActivityFactory(deps) + const addReplyAddedActivity = addReplyAddedActivityFactory(deps) + const addCommentArchivedActivity = addCommentArchivedActivityFactory(deps) + + const quitters = [ + deps.eventListen(CommentEvents.Created, async ({ payload }) => { + if (isReplyCreatedPayload(payload)) { + await addReplyAddedActivity({ + reply: payload.comment, + input: payload.input + }) + } else if (isThreadCreatedPayload(payload)) { + await addThreadCreatedActivity(payload) + } + }), + deps.eventListen(CommentEvents.Archived, async ({ payload }) => { + await addCommentArchivedActivity(payload) + }) + ] + + return () => { + quitters.forEach((quit) => quit()) + } + } diff --git a/packages/server/modules/activitystream/index.ts b/packages/server/modules/activitystream/index.ts index 62596a91b..883e9b3a4 100644 --- a/packages/server/modules/activitystream/index.ts +++ b/packages/server/modules/activitystream/index.ts @@ -30,6 +30,7 @@ import { reportUserActivityFactory } from '@/modules/activitystream/events/userL import { reportAccessRequestActivityFactory } from '@/modules/activitystream/events/accessRequestListeners' import { reportBranchActivityFactory } from '@/modules/activitystream/events/branchListeners' import { reportCommitActivityFactory } from '@/modules/activitystream/events/commitListeners' +import { reportCommentActivityFactory } from '@/modules/activitystream/events/commentListeners' let scheduledTask: ReturnType | null = null let quitEventListeners: Optional<() => void> = undefined @@ -62,12 +63,17 @@ const initializeEventListeners = ({ eventListen: eventBus.listen, saveActivity }) + const reportCommentActivity = reportCommentActivityFactory({ + eventListen: eventBus.listen, + saveActivity + }) const quitCbs = [ reportUserActivity(), reportAccessRequestActivity(), reportBranchActivity(), reportCommitActivity(), + reportCommentActivity(), eventBus.listen(ServerInvitesEvents.Created, async ({ payload }) => { if (!isProjectResourceTarget(payload.invite.resource)) return await onServerInviteCreatedFactory({ diff --git a/packages/server/modules/activitystream/services/commentActivity.ts b/packages/server/modules/activitystream/services/commentActivity.ts deleted file mode 100644 index 7b9807318..000000000 --- a/packages/server/modules/activitystream/services/commentActivity.ts +++ /dev/null @@ -1,200 +0,0 @@ -import { - AddCommentArchivedActivity, - AddCommentCreatedActivity, - AddReplyAddedActivity, - SaveActivity -} from '@/modules/activitystream/domain/operations' -import { - CommentCreatedActivityInput, - ReplyCreatedActivityInput -} from '@/modules/activitystream/domain/types' -import { ActionTypes, ResourceTypes } from '@/modules/activitystream/helpers/types' -import { - GetViewerResourceItemsUngrouped, - GetViewerResourcesForComment, - GetViewerResourcesFromLegacyIdentifiers -} from '@/modules/comments/domain/operations' -import { ViewerResourceItem } from '@/modules/comments/domain/types' -import { - CommentCreateInput, - ProjectCommentsUpdatedMessageType, - ReplyCreateInput -} from '@/modules/core/graph/generated/graphql' -import { PublishSubscription, pubsub } from '@/modules/shared/utils/subscriptions' -import { - CommentSubscriptions, - ProjectSubscriptions -} from '@/modules/shared/utils/subscriptions' -import { has } from 'lodash' - -const isLegacyCommentCreateInput = ( - i: CommentCreatedActivityInput -): i is CommentCreateInput => has(i, 'streamId') - -export const addCommentCreatedActivityFactory = - ({ - getViewerResourceItemsUngrouped, - getViewerResourcesFromLegacyIdentifiers, - saveActivity, - publish - }: { - getViewerResourceItemsUngrouped: GetViewerResourceItemsUngrouped - getViewerResourcesFromLegacyIdentifiers: GetViewerResourcesFromLegacyIdentifiers - saveActivity: SaveActivity - publish: PublishSubscription - }): AddCommentCreatedActivity => - async (params) => { - const { streamId, userId, input, comment } = params - - let resourceIds: string - let resourceItems: ViewerResourceItem[] - if (isLegacyCommentCreateInput(input)) { - resourceIds = input.resources.map((res) => res?.resourceId).join(',') - - const validResources = input.resources.filter( - (r): r is NonNullable => !!r - ) - resourceItems = await getViewerResourcesFromLegacyIdentifiers( - streamId, - validResources - ) - } else { - resourceItems = - input.resolvedResourceItems || - (await getViewerResourceItemsUngrouped({ - projectId: streamId, - resourceIdString: input.resourceIdString - })) - resourceIds = resourceItems.map((i) => i.versionId || i.objectId).join(',') - } - - await Promise.all([ - saveActivity({ - resourceId: comment.id, - streamId, - resourceType: ResourceTypes.Comment, - actionType: ActionTypes.Comment.Create, - userId, - info: { input }, - message: `Comment added: ${comment.id} (${input})` - }), - // @deprecated unused in FE2 - pubsub.publish(CommentSubscriptions.CommentActivity, { - commentActivity: { - type: 'comment-added', - comment - }, - streamId, - resourceIds - }), - publish(ProjectSubscriptions.ProjectCommentsUpdated, { - projectCommentsUpdated: { - id: comment.id, - type: ProjectCommentsUpdatedMessageType.Created, - comment - }, - projectId: streamId, - resourceItems - }) - ]) - } - -/** - * Add comment archived/unarchived activity - */ -export const addCommentArchivedActivityFactory = - ({ - getViewerResourcesForComment, - saveActivity, - publish - }: { - getViewerResourcesForComment: GetViewerResourcesForComment - publish: PublishSubscription - saveActivity: SaveActivity - }): AddCommentArchivedActivity => - async (params) => { - const { streamId, commentId, userId, input, comment } = params - const isArchiving = !!input.archived - - await Promise.all([ - saveActivity({ - streamId, - resourceType: ResourceTypes.Comment, - resourceId: commentId, - actionType: ActionTypes.Comment.Archive, - userId, - info: { input }, - message: `Comment #${commentId} archived` - }), - // @deprecated not used in FE2 - pubsub.publish(CommentSubscriptions.CommentThreadActivity, { - commentThreadActivity: { - type: isArchiving ? 'comment-archived' : 'comment-added' - }, - streamId: input.streamId, - commentId: input.commentId - }), - publish(ProjectSubscriptions.ProjectCommentsUpdated, { - projectCommentsUpdated: { - id: commentId, - type: isArchiving - ? ProjectCommentsUpdatedMessageType.Archived - : ProjectCommentsUpdatedMessageType.Created, - comment: isArchiving ? null : comment - }, - projectId: streamId, - resourceItems: await getViewerResourcesForComment(streamId, comment.id) - }) - ]) - } - -const isLegacyReplyCreateInput = ( - i: ReplyCreatedActivityInput -): i is ReplyCreateInput => has(i, 'streamId') - -export const addReplyAddedActivityFactory = - ({ - getViewerResourcesForComment, - saveActivity, - publish - }: { - getViewerResourcesForComment: GetViewerResourcesForComment - publish: PublishSubscription - saveActivity: SaveActivity - }): AddReplyAddedActivity => - async (params) => { - const { streamId, input, reply, userId } = params - - const parentCommentId = isLegacyReplyCreateInput(input) - ? input.parentComment - : input.threadId - await Promise.all([ - saveActivity({ - streamId, - resourceType: ResourceTypes.Comment, - resourceId: parentCommentId, - actionType: ActionTypes.Comment.Reply, - userId, - info: { input }, - message: `Comment reply #${reply.id} created` - }), - // @deprecated - pubsub.publish(CommentSubscriptions.CommentThreadActivity, { - commentThreadActivity: { - type: 'reply-added', - reply - }, - streamId, - commentId: parentCommentId - }), - publish(ProjectSubscriptions.ProjectCommentsUpdated, { - projectCommentsUpdated: { - id: reply.id, - type: ProjectCommentsUpdatedMessageType.Created, - comment: reply - }, - projectId: streamId, - resourceItems: await getViewerResourcesForComment(streamId, reply.id) - }) - ]) - } diff --git a/packages/server/modules/cli/commands/download/commit.ts b/packages/server/modules/cli/commands/download/commit.ts index 5640670d0..c977d772f 100644 --- a/packages/server/modules/cli/commands/download/commit.ts +++ b/packages/server/modules/cli/commands/download/commit.ts @@ -46,19 +46,14 @@ import { markCommentUpdatedFactory, markCommentViewedFactory } from '@/modules/comments/repositories/comments' -import { - addCommentCreatedActivityFactory, - addReplyAddedActivityFactory -} from '@/modules/activitystream/services/commentActivity' import { validateInputAttachmentsFactory } from '@/modules/comments/services/commentTextService' import { getBlobsFactory } from '@/modules/blobstorage/repositories' import { createCommitByBranchIdFactory } from '@/modules/core/services/commit/management' -import { saveActivityFactory } from '@/modules/activitystream/repositories' import { publish } from '@/modules/shared/utils/subscriptions' import { getUserFactory } from '@/modules/core/repositories/users' import { createObjectFactory } from '@/modules/core/services/objects/management' import { getProjectDbClient } from '@/modules/multiregion/utils/dbSelector' -import { db, mainDb } from '@/db/knex' +import { db } from '@/db/knex' import { getEventBus } from '@/modules/shared/services/eventBus' const command: CommandModule< @@ -143,12 +138,7 @@ const command: CommandModule< insertCommentLinks, markCommentViewed, emitEvent: getEventBus().emit, - addCommentCreatedActivity: addCommentCreatedActivityFactory({ - getViewerResourcesFromLegacyIdentifiers, - getViewerResourceItemsUngrouped, - saveActivity: saveActivityFactory({ db: mainDb }), - publish - }) + publishSub: publish }) const createCommentReplyAndNotify = createCommentReplyAndNotifyFactory({ @@ -158,14 +148,11 @@ const command: CommandModule< insertCommentLinks, markCommentUpdated: markCommentUpdatedFactory({ db: projectDb }), emitEvent: getEventBus().emit, - addReplyAddedActivity: addReplyAddedActivityFactory({ - getViewerResourcesForComment: getViewerResourcesForCommentFactory({ - getCommentsResources: getCommentsResourcesFactory({ db: projectDb }), - getViewerResourcesFromLegacyIdentifiers - }), - saveActivity: saveActivityFactory({ db: mainDb }), - publish - }) + getViewerResourcesForComment: getViewerResourcesForCommentFactory({ + getCommentsResources: getCommentsResourcesFactory({ db: projectDb }), + getViewerResourcesFromLegacyIdentifiers + }), + publishSub: publish }) const createCommitByBranchId = createCommitByBranchIdFactory({ diff --git a/packages/server/modules/cli/commands/download/project.ts b/packages/server/modules/cli/commands/download/project.ts index e65e4191c..53c63653a 100644 --- a/packages/server/modules/cli/commands/download/project.ts +++ b/packages/server/modules/cli/commands/download/project.ts @@ -27,10 +27,6 @@ import { createCommentThreadAndNotifyFactory } from '@/modules/comments/services/management' import { createBranchAndNotifyFactory } from '@/modules/core/services/branch/management' -import { - addCommentCreatedActivityFactory, - addReplyAddedActivityFactory -} from '@/modules/activitystream/services/commentActivity' import { createCommitFactory, getAllBranchCommitsFactory, @@ -46,7 +42,7 @@ import { getViewerResourcesForCommentsFactory, getViewerResourcesFromLegacyIdentifiersFactory } from '@/modules/core/services/commit/viewerResources' -import { db, mainDb } from '@/db/knex' +import { db } from '@/db/knex' import { getCommentFactory, getCommentsResourcesFactory, @@ -57,7 +53,6 @@ import { } from '@/modules/comments/repositories/comments' import { getBlobsFactory } from '@/modules/blobstorage/repositories' import { validateInputAttachmentsFactory } from '@/modules/comments/services/commentTextService' -import { saveActivityFactory } from '@/modules/activitystream/repositories' import { publish } from '@/modules/shared/utils/subscriptions' import { getUserFactory } from '@/modules/core/repositories/users' import { createObjectFactory } from '@/modules/core/services/objects/management' @@ -168,12 +163,7 @@ const command: CommandModule< insertCommentLinks, markCommentViewed, emitEvent: getEventBus().emit, - addCommentCreatedActivity: addCommentCreatedActivityFactory({ - getViewerResourcesFromLegacyIdentifiers, - getViewerResourceItemsUngrouped, - saveActivity: saveActivityFactory({ db: mainDb }), - publish - }) + publishSub: publish }) const createCommentReplyAndNotify = createCommentReplyAndNotifyFactory({ getComment: getCommentFactory({ db: projectDb }), @@ -182,14 +172,11 @@ const command: CommandModule< insertCommentLinks, markCommentUpdated: markCommentUpdatedFactory({ db: projectDb }), emitEvent: getEventBus().emit, - addReplyAddedActivity: addReplyAddedActivityFactory({ - getViewerResourcesForComment: getViewerResourcesForCommentFactory({ - getCommentsResources: getCommentsResourcesFactory({ db: projectDb }), - getViewerResourcesFromLegacyIdentifiers - }), - saveActivity: saveActivityFactory({ db: mainDb }), - publish - }) + getViewerResourcesForComment: getViewerResourcesForCommentFactory({ + getCommentsResources: getCommentsResourcesFactory({ db: projectDb }), + getViewerResourcesFromLegacyIdentifiers + }), + publishSub: publish }) const createCommitByBranchId = createCommitByBranchIdFactory({ diff --git a/packages/server/modules/comments/domain/events.ts b/packages/server/modules/comments/domain/events.ts index 30f73395e..428912318 100644 --- a/packages/server/modules/comments/domain/events.ts +++ b/packages/server/modules/comments/domain/events.ts @@ -1,16 +1,31 @@ +import { + CommentCreatedActivityInput, + ReplyCreatedActivityInput +} from '@/modules/activitystream/domain/types' import { CommentRecord } from '@/modules/comments/helpers/types' +import { MutationCommentArchiveArgs } from '@/modules/core/graph/generated/graphql' export const commentEventsNamespace = 'comments' as const export const CommentEvents = { Created: `${commentEventsNamespace}.created`, - Updated: `${commentEventsNamespace}.updated` + Updated: `${commentEventsNamespace}.updated`, + Archived: `${commentEventsNamespace}.archived` } as const export type CommentEventsPayloads = { - [CommentEvents.Created]: { comment: CommentRecord } + [CommentEvents.Created]: { + comment: CommentRecord + isThread: boolean + input: CommentCreatedActivityInput | ReplyCreatedActivityInput + } [CommentEvents.Updated]: { previousComment: CommentRecord newComment: CommentRecord } + [CommentEvents.Archived]: { + userId: string + input: MutationCommentArchiveArgs + comment: CommentRecord + } } diff --git a/packages/server/modules/comments/graph/resolvers/comments.ts b/packages/server/modules/comments/graph/resolvers/comments.ts index f6f97da06..7164e1626 100644 --- a/packages/server/modules/comments/graph/resolvers/comments.ts +++ b/packages/server/modules/comments/graph/resolvers/comments.ts @@ -49,11 +49,6 @@ import { filteredSubscribe, ProjectSubscriptions } from '@/modules/shared/utils/subscriptions' -import { - addCommentArchivedActivityFactory, - addCommentCreatedActivityFactory, - addReplyAddedActivityFactory -} from '@/modules/activitystream/services/commentActivity' import { doViewerResourcesFit, getViewerResourcesForCommentFactory, @@ -95,7 +90,6 @@ import { } from '@/modules/core/repositories/branches' import { getStreamObjectsFactory } from '@/modules/core/repositories/objects' import { getStreamFactory } from '@/modules/core/repositories/streams' -import { saveActivityFactory } from '@/modules/activitystream/repositories' import { getProjectDbClient } from '@/modules/multiregion/utils/dbSelector' import { Knex } from 'knex' import { getEventBus } from '@/modules/shared/services/eventBus' @@ -533,8 +527,6 @@ export = { const getViewerResourceItemsUngrouped = buildGetViewerResourceItemsUngrouped({ db: projectDb }) - const getViewerResourcesFromLegacyIdentifiers = - buildGetViewerResourcesFromLegacyIdentifiers({ db: projectDb }) const validateInputAttachments = validateInputAttachmentsFactory({ getBlobs: getBlobsFactory({ db: projectDb }) @@ -550,12 +542,7 @@ export = { insertCommentLinks, markCommentViewed, emitEvent: getEventBus().emit, - addCommentCreatedActivity: addCommentCreatedActivityFactory({ - getViewerResourcesFromLegacyIdentifiers, - getViewerResourceItemsUngrouped, - saveActivity: saveActivityFactory({ db: mainDb }), - publish - }) + publishSub: publish }) return await createCommentThreadAndNotify(args.input, ctx.userId!) @@ -588,14 +575,11 @@ export = { insertCommentLinks, markCommentUpdated: markCommentUpdatedFactory({ db: projectDb }), emitEvent: getEventBus().emit, - addReplyAddedActivity: addReplyAddedActivityFactory({ - getViewerResourcesForComment: getViewerResourcesForCommentFactory({ - getCommentsResources: getCommentsResourcesFactory({ db: projectDb }), - getViewerResourcesFromLegacyIdentifiers - }), - saveActivity: saveActivityFactory({ db: mainDb }), - publish - }) + getViewerResourcesForComment: getViewerResourcesForCommentFactory({ + getCommentsResources: getCommentsResourcesFactory({ db: projectDb }), + getViewerResourcesFromLegacyIdentifiers + }), + publishSub: publish }) return await createCommentReplyAndNotify(args.input, ctx.userId!) @@ -656,11 +640,9 @@ export = { getComment, getStream, updateComment, - addCommentArchivedActivity: addCommentArchivedActivityFactory({ - getViewerResourcesForComment, - saveActivity: saveActivityFactory({ db: mainDb }), - publish - }) + getViewerResourcesForComment, + publishSub: publish, + emitEvent: getEventBus().emit }) await archiveCommentAndNotify( @@ -740,6 +722,8 @@ export = { throw new ForbiddenError('You are not authorized.') const projectDb = await getProjectDbClient({ projectId: args.input.streamId }) + const getViewerResourcesFromLegacyIdentifiers = + buildGetViewerResourcesFromLegacyIdentifiers({ db: projectDb }) const createComment = createCommentFactory({ checkStreamResourcesAccess: streamResourceCheckFactory({ @@ -752,31 +736,15 @@ export = { insertCommentLinks: insertCommentLinksFactory({ db: projectDb }), deleteComment: deleteCommentFactory({ db: projectDb }), markCommentViewed: markCommentViewedFactory({ db: projectDb }), - emitEvent: getEventBus().emit + emitEvent: getEventBus().emit, + publishSub: publish, + getViewerResourcesFromLegacyIdentifiers }) const comment = await createComment({ userId: context.userId, input: args.input }) - const getViewerResourceItemsUngrouped = buildGetViewerResourceItemsUngrouped({ - db: projectDb - }) - const getViewerResourcesFromLegacyIdentifiers = - buildGetViewerResourcesFromLegacyIdentifiers({ db: projectDb }) - - await addCommentCreatedActivityFactory({ - getViewerResourceItemsUngrouped, - getViewerResourcesFromLegacyIdentifiers, - saveActivity: saveActivityFactory({ db: mainDb }), - publish - })({ - streamId: args.input.streamId, - userId: context.userId, - input: args.input, - comment - }) - return comment.id }, @@ -825,30 +793,22 @@ export = { }) const projectDb = await getProjectDbClient({ projectId: args.streamId }) - const archiveComment = archiveCommentFactory({ - getComment: getCommentFactory({ db: projectDb }), - getStream, - updateComment: updateCommentFactory({ db: projectDb }) - }) - const updatedComment = await archiveComment({ ...args, userId: context.userId! }) // NOTE: permissions check inside service - const getViewerResourcesFromLegacyIdentifiers = buildGetViewerResourcesFromLegacyIdentifiers({ db: projectDb }) const getViewerResourcesForComment = getViewerResourcesForCommentFactory({ getCommentsResources: getCommentsResourcesFactory({ db: projectDb }), getViewerResourcesFromLegacyIdentifiers }) - await addCommentArchivedActivityFactory({ - getViewerResourcesForComment, - saveActivity: saveActivityFactory({ db: mainDb }), - publish - })({ - streamId: args.streamId, - commentId: args.commentId, - userId: context.userId!, - input: args, - comment: updatedComment + + const archiveComment = archiveCommentFactory({ + getComment: getCommentFactory({ db: projectDb }), + getStream, + updateComment: updateCommentFactory({ db: projectDb }), + emitEvent: getEventBus().emit, + publishSub: publish, + getViewerResourcesForComment }) + await archiveComment({ ...args, userId: context.userId! }) // NOTE: permissions check inside service return true }, @@ -878,7 +838,13 @@ export = { }), deleteComment: deleteCommentFactory({ db: projectDb }), markCommentUpdated: markCommentUpdatedFactory({ db: projectDb }), - emitEvent: getEventBus().emit + emitEvent: getEventBus().emit, + publishSub: publish, + getViewerResourcesForComment: getViewerResourcesForCommentFactory({ + getCommentsResources: getCommentsResourcesFactory({ db: projectDb }), + getViewerResourcesFromLegacyIdentifiers: + buildGetViewerResourcesFromLegacyIdentifiers({ db: projectDb }) + }) }) const reply = await createCommentReply({ authorId: context.userId, @@ -889,22 +855,6 @@ export = { blobIds: args.input.blobIds }) - const getViewerResourcesFromLegacyIdentifiers = - buildGetViewerResourcesFromLegacyIdentifiers({ db: projectDb }) - await addReplyAddedActivityFactory({ - getViewerResourcesForComment: getViewerResourcesForCommentFactory({ - getCommentsResources: getCommentsResourcesFactory({ db: projectDb }), - getViewerResourcesFromLegacyIdentifiers - }), - saveActivity: saveActivityFactory({ db: mainDb }), - publish - })({ - streamId: args.input.streamId, - input: args.input, - reply, - userId: context.userId - }) - return reply.id } }, diff --git a/packages/server/modules/comments/services/index.ts b/packages/server/modules/comments/services/index.ts index 5c0fc9bd9..d6a7ecc6d 100644 --- a/packages/server/modules/comments/services/index.ts +++ b/packages/server/modules/comments/services/index.ts @@ -5,7 +5,8 @@ import { isNonNullable, Roles } from '@speckle/shared' import { ResourceIdentifier, CommentCreateInput, - CommentEditInput + CommentEditInput, + ProjectCommentsUpdatedMessageType } from '@/modules/core/graph/generated/graphql' import { CommentLinkRecord, CommentRecord } from '@/modules/comments/helpers/types' import { SmartTextEditorValueSchema } from '@/modules/core/services/richTextEditorService' @@ -14,6 +15,8 @@ import { CheckStreamResourcesAccess, DeleteComment, GetComment, + GetViewerResourcesForComment, + GetViewerResourcesFromLegacyIdentifiers, InsertCommentLinks, InsertComments, MarkCommentUpdated, @@ -26,6 +29,11 @@ import { GetStream } from '@/modules/core/domain/streams/operations' import { EventBusEmit } from '@/modules/shared/services/eventBus' import { CommentEvents } from '@/modules/comments/domain/events' import { JSONContent } from '@tiptap/core' +import { + CommentSubscriptions, + ProjectSubscriptions, + PublishSubscription +} from '@/modules/shared/utils/subscriptions' export const streamResourceCheckFactory = (deps: { @@ -56,6 +64,8 @@ export const createCommentFactory = deleteComment: DeleteComment markCommentViewed: MarkCommentViewed emitEvent: EventBusEmit + publishSub: PublishSubscription + getViewerResourcesFromLegacyIdentifiers: GetViewerResourcesFromLegacyIdentifiers }) => async ({ userId, input }: { userId: string; input: CommentCreateInput }) => { if (input.resources.length < 1) @@ -116,12 +126,37 @@ export const createCommentFactory = await deps.markCommentViewed(id, userId) // so we don't self mark a comment as unread the moment it's created - await deps.emitEvent({ - eventName: CommentEvents.Created, - payload: { - comment: newComment - } - }) + await Promise.all([ + deps.emitEvent({ + eventName: CommentEvents.Created, + payload: { + comment: newComment, + input, + isThread: true + } + }), + // @deprecated unused in FE2 + deps.publishSub(CommentSubscriptions.CommentActivity, { + commentActivity: { + type: 'comment-added', + comment: newComment + }, + streamId: input.streamId, + resourceIds: input.resources.map((res) => res?.resourceId).join(',') + }), + deps.publishSub(ProjectSubscriptions.ProjectCommentsUpdated, { + projectCommentsUpdated: { + id: newComment.id, + type: ProjectCommentsUpdatedMessageType.Created, + comment: newComment + }, + projectId: input.streamId, + resourceItems: await deps.getViewerResourcesFromLegacyIdentifiers( + input.streamId, + input.resources.filter(isNonNullable) + ) + }) + ]) return newComment } @@ -138,6 +173,8 @@ export const createCommentReplyFactory = deleteComment: DeleteComment markCommentUpdated: MarkCommentUpdated emitEvent: EventBusEmit + publishSub: PublishSubscription + getViewerResourcesForComment: GetViewerResourcesForComment }) => async ({ authorId, @@ -188,12 +225,45 @@ export const createCommentReplyFactory = await deps.markCommentUpdated(parentCommentId) - await deps.emitEvent({ - eventName: CommentEvents.Created, - payload: { - comment: newComment - } - }) + await Promise.all([ + deps.emitEvent({ + eventName: CommentEvents.Created, + payload: { + comment: newComment, + isThread: false, + input: { + threadId: parentCommentId, + projectId: streamId, + content: { + blobIds, + doc: text + } + } + } + }), + // TODO: Move to event bus listeners + // @deprecated + deps.publishSub(CommentSubscriptions.CommentThreadActivity, { + commentThreadActivity: { + type: 'reply-added', + reply: newComment + }, + streamId: newComment.streamId, + commentId: parentCommentId + }), + deps.publishSub(ProjectSubscriptions.ProjectCommentsUpdated, { + projectCommentsUpdated: { + id: newComment.id, + type: ProjectCommentsUpdatedMessageType.Created, + comment: newComment + }, + projectId: newComment.streamId, + resourceItems: await deps.getViewerResourcesForComment( + newComment.streamId, + newComment.id + ) + }) + ]) return newComment } @@ -249,6 +319,9 @@ export const archiveCommentFactory = getComment: GetComment getStream: GetStream updateComment: UpdateComment + emitEvent: EventBusEmit + publishSub: PublishSubscription + getViewerResourcesForComment: GetViewerResourcesForComment }) => async ({ commentId, @@ -275,5 +348,37 @@ export const archiveCommentFactory = } const updatedComment = await deps.updateComment(commentId, { archived }) + + await Promise.all([ + deps.emitEvent({ + eventName: CommentEvents.Archived, + payload: { + userId, + input: { archived, commentId, streamId }, + comment: updatedComment! + } + }), + // TODO: Move to event bus listeners + // @deprecated not used in FE2 + deps.publishSub(CommentSubscriptions.CommentThreadActivity, { + commentThreadActivity: { + type: archived ? 'comment-archived' : 'comment-added' + }, + streamId, + commentId + }), + deps.publishSub(ProjectSubscriptions.ProjectCommentsUpdated, { + projectCommentsUpdated: { + id: commentId, + type: archived + ? ProjectCommentsUpdatedMessageType.Archived + : ProjectCommentsUpdatedMessageType.Created, + comment: archived ? null : comment + }, + projectId: streamId, + resourceItems: await deps.getViewerResourcesForComment(streamId, comment.id) + }) + ]) + return updatedComment! } diff --git a/packages/server/modules/comments/services/management.ts b/packages/server/modules/comments/services/management.ts index 0836579b4..fabc211ab 100644 --- a/packages/server/modules/comments/services/management.ts +++ b/packages/server/modules/comments/services/management.ts @@ -5,7 +5,8 @@ import { StreamInvalidAccessError } from '@/modules/core/errors/stream' import { CreateCommentInput, CreateCommentReplyInput, - EditCommentInput + EditCommentInput, + ProjectCommentsUpdatedMessageType } from '@/modules/core/graph/generated/graphql' import { CommentCreateError, CommentUpdateError } from '@/modules/comments/errors' import { buildCommentTextFromInput } from '@/modules/comments/services/commentTextService' @@ -26,6 +27,7 @@ import { EditCommentAndNotify, GetComment, GetViewerResourceItemsUngrouped, + GetViewerResourcesForComment, InsertCommentLinks, InsertCommentPayload, InsertComments, @@ -35,13 +37,13 @@ import { ValidateInputAttachments } from '@/modules/comments/domain/operations' import { GetStream } from '@/modules/core/domain/streams/operations' -import { - AddCommentArchivedActivity, - AddCommentCreatedActivity, - AddReplyAddedActivity -} from '@/modules/activitystream/domain/operations' import { EventBusEmit } from '@/modules/shared/services/eventBus' import { CommentEvents } from '@/modules/comments/domain/events' +import { + CommentSubscriptions, + ProjectSubscriptions, + PublishSubscription +} from '@/modules/shared/utils/subscriptions' type AuthorizeProjectCommentsAccessDeps = { getStream: GetStream @@ -118,7 +120,7 @@ export const createCommentThreadAndNotifyFactory = insertCommentLinks: InsertCommentLinks markCommentViewed: MarkCommentViewed emitEvent: EventBusEmit - addCommentCreatedActivity: AddCommentCreatedActivity + publishSub: PublishSubscription }): CreateCommentThreadAndNotify => async (input: CreateCommentInput, userId: string) => { const [resources] = await Promise.all([ @@ -180,17 +182,29 @@ export const createCommentThreadAndNotifyFactory = deps.emitEvent({ eventName: CommentEvents.Created, payload: { - comment + comment, + input, + isThread: true } }), - deps.addCommentCreatedActivity({ - streamId: input.projectId, - userId, - input: { - ...input, - resolvedResourceItems: resources + // TODO: Move to event bus listeners + // @deprecated unused in FE2 + deps.publishSub(CommentSubscriptions.CommentActivity, { + commentActivity: { + type: 'comment-added', + comment }, - comment + streamId: input.projectId, + resourceIds: resources.map((i) => i.versionId || i.objectId).join(',') + }), + deps.publishSub(ProjectSubscriptions.ProjectCommentsUpdated, { + projectCommentsUpdated: { + id: comment.id, + type: ProjectCommentsUpdatedMessageType.Created, + comment + }, + projectId: input.projectId, + resourceItems: resources }) ]) @@ -205,7 +219,8 @@ export const createCommentReplyAndNotifyFactory = insertCommentLinks: InsertCommentLinks markCommentUpdated: MarkCommentUpdated emitEvent: EventBusEmit - addReplyAddedActivity: AddReplyAddedActivity + publishSub: PublishSubscription + getViewerResourcesForComment: GetViewerResourcesForComment }): CreateCommentReplyAndNotify => async (input: CreateCommentReplyInput, userId: string) => { const thread = await deps.getComment({ id: input.threadId, userId }) @@ -244,14 +259,29 @@ export const createCommentReplyAndNotifyFactory = deps.emitEvent({ eventName: CommentEvents.Created, payload: { - comment: reply + comment: reply, + input, + isThread: false } }), - deps.addReplyAddedActivity({ - streamId: thread.streamId, - input, - reply, - userId + // TODO: Move to event bus listeners + // @deprecated + deps.publishSub(CommentSubscriptions.CommentThreadActivity, { + commentThreadActivity: { + type: 'reply-added', + reply + }, + streamId: reply.streamId, + commentId: thread.id + }), + deps.publishSub(ProjectSubscriptions.ProjectCommentsUpdated, { + projectCommentsUpdated: { + id: reply.id, + type: ProjectCommentsUpdatedMessageType.Created, + comment: reply + }, + projectId: reply.streamId, + resourceItems: await deps.getViewerResourcesForComment(reply.streamId, reply.id) }) ]) @@ -298,7 +328,9 @@ export const archiveCommentAndNotifyFactory = getComment: GetComment getStream: GetStream updateComment: UpdateComment - addCommentArchivedActivity: AddCommentArchivedActivity + emitEvent: EventBusEmit + publishSub: PublishSubscription + getViewerResourcesForComment: GetViewerResourcesForComment }): ArchiveCommentAndNotify => async (commentId: string, userId: string, archived = true) => { const comment = await deps.getComment({ id: commentId, userId }) @@ -321,17 +353,36 @@ export const archiveCommentAndNotifyFactory = archived }) - await deps.addCommentArchivedActivity({ - streamId: stream.id, - commentId, - userId, - input: { - archived, + await Promise.all([ + deps.emitEvent({ + eventName: CommentEvents.Archived, + payload: { + userId, + input: { archived, commentId, streamId: stream.id }, + comment: updatedComment! + } + }), + // TODO: Move to event bus listeners + // @deprecated not used in FE2 + deps.publishSub(CommentSubscriptions.CommentThreadActivity, { + commentThreadActivity: { + type: archived ? 'comment-archived' : 'comment-added' + }, streamId: stream.id, commentId - }, - comment: updatedComment! - }) + }), + deps.publishSub(ProjectSubscriptions.ProjectCommentsUpdated, { + projectCommentsUpdated: { + id: commentId, + type: archived + ? ProjectCommentsUpdatedMessageType.Archived + : ProjectCommentsUpdatedMessageType.Created, + comment: archived ? null : comment + }, + projectId: stream.id, + resourceItems: await deps.getViewerResourcesForComment(stream.id, comment.id) + }) + ]) return updatedComment } diff --git a/packages/server/modules/comments/tests/comments.graph.spec.js b/packages/server/modules/comments/tests/comments.graph.spec.js index 1f09bcdd3..cf35a3ffd 100644 --- a/packages/server/modules/comments/tests/comments.graph.spec.js +++ b/packages/server/modules/comments/tests/comments.graph.spec.js @@ -22,7 +22,8 @@ const { markCommentViewedFactory, insertCommentsFactory, insertCommentLinksFactory, - deleteCommentFactory + deleteCommentFactory, + getCommentsResourcesFactory } = require('@/modules/comments/repositories/comments') const { db } = require('@/db/knex') const { @@ -36,7 +37,8 @@ const { const { createCommitFactory, insertStreamCommitsFactory, - insertBranchCommitsFactory + insertBranchCommitsFactory, + getCommitsAndTheirBranchIdsFactory } = require('@/modules/core/repositories/commits') const { getBranchByIdFactory, @@ -54,7 +56,8 @@ const { const { getObjectFactory, storeSingleObjectIfNotFoundFactory, - storeClosuresIfNotFoundFactory + storeClosuresIfNotFoundFactory, + getStreamObjectsFactory } = require('@/modules/core/repositories/objects') const { legacyCreateStreamFactory, @@ -109,6 +112,10 @@ const { } = require('@/modules/serverinvites/services/processing') const { getServerInfoFactory } = require('@/modules/core/repositories/server') const { createObjectFactory } = require('@/modules/core/services/objects/management') +const { + getViewerResourcesFromLegacyIdentifiersFactory, + getViewerResourcesForCommentsFactory +} = require('@/modules/core/services/commit/viewerResources') const getServerInfo = getServerInfoFactory({ db }) const getUser = getUserFactory({ db }) @@ -118,6 +125,18 @@ const streamResourceCheck = streamResourceCheckFactory({ checkStreamResourceAccess: checkStreamResourceAccessFactory({ db }) }) const markCommentViewed = markCommentViewedFactory({ db }) + +const getViewerResourcesFromLegacyIdentifiers = + getViewerResourcesFromLegacyIdentifiersFactory({ + getViewerResourcesForComments: getViewerResourcesForCommentsFactory({ + getCommentsResources: getCommentsResourcesFactory({ db }), + getViewerResourcesFromLegacyIdentifiers: (...args) => + getViewerResourcesFromLegacyIdentifiers(...args) // recursive dep + }), + getCommitsAndTheirBranchIds: getCommitsAndTheirBranchIdsFactory({ db }), + getStreamObjects: getStreamObjectsFactory({ db }) + }) + const createComment = createCommentFactory({ checkStreamResourcesAccess: streamResourceCheck, validateInputAttachments: validateInputAttachmentsFactory({ @@ -127,7 +146,9 @@ const createComment = createCommentFactory({ insertCommentLinks: insertCommentLinksFactory({ db }), deleteComment: deleteCommentFactory({ db }), markCommentViewed, - emitEvent: getEventBus().emit + emitEvent: getEventBus().emit, + publishSub: publish, + getViewerResourcesFromLegacyIdentifiers }) const getObject = getObjectFactory({ db }) diff --git a/packages/server/modules/comments/tests/comments.spec.ts b/packages/server/modules/comments/tests/comments.spec.ts index 0a20f3d56..cf235e181 100644 --- a/packages/server/modules/comments/tests/comments.spec.ts +++ b/packages/server/modules/comments/tests/comments.spec.ts @@ -43,7 +43,8 @@ import { updateCommentFactory, getCommentsLegacyFactory, getResourceCommentCountFactory, - getStreamCommentCountFactory + getStreamCommentCountFactory, + getCommentsResourcesFactory } from '@/modules/comments/repositories/comments' import { db } from '@/db/knex' import { getBlobsFactory } from '@/modules/blobstorage/repositories' @@ -59,7 +60,8 @@ import { import { createCommitFactory, insertStreamCommitsFactory, - insertBranchCommitsFactory + insertBranchCommitsFactory, + getCommitsAndTheirBranchIdsFactory } from '@/modules/core/repositories/commits' import { getBranchByIdFactory, @@ -70,7 +72,8 @@ import { import { getObjectFactory, storeSingleObjectIfNotFoundFactory, - storeClosuresIfNotFoundFactory + storeClosuresIfNotFoundFactory, + getStreamObjectsFactory } from '@/modules/core/repositories/objects' import { legacyCreateStreamFactory, @@ -118,6 +121,11 @@ import { import { CommentRecord } from '@/modules/comments/helpers/types' import { MaybeNullOrUndefined } from '@speckle/shared' import { CommentEvents } from '@/modules/comments/domain/events' +import { + getViewerResourcesForCommentFactory, + getViewerResourcesForCommentsFactory, + getViewerResourcesFromLegacyIdentifiersFactory +} from '@/modules/core/services/commit/viewerResources' type LegacyCommentRecord = CommentRecord & { total_count: string @@ -138,6 +146,17 @@ const validateInputAttachments = validateInputAttachmentsFactory({ const insertComments = insertCommentsFactory({ db }) const insertCommentLinks = insertCommentLinksFactory({ db }) const deleteComment = deleteCommentFactory({ db }) + +const getViewerResourcesFromLegacyIdentifiers = + getViewerResourcesFromLegacyIdentifiersFactory({ + getViewerResourcesForComments: getViewerResourcesForCommentsFactory({ + getCommentsResources: getCommentsResourcesFactory({ db }), + getViewerResourcesFromLegacyIdentifiers: (...args) => + getViewerResourcesFromLegacyIdentifiers(...args) // recursive dep + }), + getCommitsAndTheirBranchIds: getCommitsAndTheirBranchIdsFactory({ db }), + getStreamObjects: getStreamObjectsFactory({ db }) + }) const createComment = createCommentFactory({ checkStreamResourcesAccess: streamResourceCheck, validateInputAttachments, @@ -145,7 +164,14 @@ const createComment = createCommentFactory({ insertCommentLinks, deleteComment, markCommentViewed, - emitEvent: getEventBus().emit + emitEvent: getEventBus().emit, + publishSub: publish, + getViewerResourcesFromLegacyIdentifiers +}) +const getViewerResourcesForComment = getViewerResourcesForCommentFactory({ + getCommentsResources: getCommentsResourcesFactory({ db }), + getViewerResourcesFromLegacyIdentifiers: (...args) => + getViewerResourcesFromLegacyIdentifiers(...args) // recursive dep }) const createCommentReply = createCommentReplyFactory({ validateInputAttachments, @@ -154,7 +180,9 @@ const createCommentReply = createCommentReplyFactory({ checkStreamResourcesAccess: streamResourceCheck, deleteComment, markCommentUpdated: markCommentUpdatedFactory({ db }), - emitEvent: getEventBus().emit + emitEvent: getEventBus().emit, + publishSub: publish, + getViewerResourcesForComment }) const getComment = getCommentFactory({ db }) const updateComment = updateCommentFactory({ db }) @@ -167,7 +195,10 @@ const editComment = editCommentFactory({ const archiveComment = archiveCommentFactory({ getComment, getStream, - updateComment + updateComment, + emitEvent: getEventBus().emit, + publishSub: publish, + getViewerResourcesForComment }) const getComments = getCommentsLegacyFactory({ db }) const getResourceCommentCount = getResourceCommentCountFactory({ db }) diff --git a/packages/server/modules/cross-server-sync/index.ts b/packages/server/modules/cross-server-sync/index.ts index 3a6a30a84..d2c28ea2a 100644 --- a/packages/server/modules/cross-server-sync/index.ts +++ b/packages/server/modules/cross-server-sync/index.ts @@ -1,10 +1,5 @@ import { db } from '@/db/knex' import { moduleLogger, crossServerSyncLogger } from '@/logging/logging' -import { saveActivityFactory } from '@/modules/activitystream/repositories' -import { - addCommentCreatedActivityFactory, - addReplyAddedActivityFactory -} from '@/modules/activitystream/services/commentActivity' import { getBlobsFactory } from '@/modules/blobstorage/repositories' import { getCommentFactory, @@ -120,12 +115,7 @@ const crossServerSyncModule: SpeckleModule = { insertCommentLinks, markCommentViewed, emitEvent: getEventBus().emit, - addCommentCreatedActivity: addCommentCreatedActivityFactory({ - getViewerResourcesFromLegacyIdentifiers, - getViewerResourceItemsUngrouped, - saveActivity: saveActivityFactory({ db }), - publish - }) + publishSub: publish }) const createCommentReplyAndNotify = createCommentReplyAndNotifyFactory({ getComment: getCommentFactory({ db }), @@ -134,14 +124,11 @@ const crossServerSyncModule: SpeckleModule = { insertCommentLinks, markCommentUpdated: markCommentUpdatedFactory({ db }), emitEvent: getEventBus().emit, - addReplyAddedActivity: addReplyAddedActivityFactory({ - getViewerResourcesForComment: getViewerResourcesForCommentFactory({ - getCommentsResources: getCommentsResourcesFactory({ db }), - getViewerResourcesFromLegacyIdentifiers - }), - saveActivity: saveActivityFactory({ db }), - publish - }) + getViewerResourcesForComment: getViewerResourcesForCommentFactory({ + getCommentsResources: getCommentsResourcesFactory({ db }), + getViewerResourcesFromLegacyIdentifiers + }), + publishSub: publish }) const getStreamBranchByName = getStreamBranchByNameFactory({ db }) const createCommitByBranchId = createCommitByBranchIdFactory({ diff --git a/packages/server/modules/shared/utils/subscriptions.ts b/packages/server/modules/shared/utils/subscriptions.ts index 2bbb825c6..5f2feea68 100644 --- a/packages/server/modules/shared/utils/subscriptions.ts +++ b/packages/server/modules/shared/utils/subscriptions.ts @@ -56,7 +56,7 @@ import { SubscriptionWorkspaceUpdatedArgs, WorkspaceUpdatedMessage } from '@/modules/core/graph/generated/graphql' -import { Merge } from 'type-fest' +import { Merge, OverrideProperties } from 'type-fest' import { ModelGraphQLReturn, ProjectGraphQLReturn, @@ -276,8 +276,10 @@ type SubscriptionTypeMap = { } [CommentSubscriptions.CommentThreadActivity]: { payload: { - commentThreadActivity: Partial & - Pick + commentThreadActivity: OverrideProperties< + CommentThreadActivityMessage, + { reply?: CommentRecord } + > streamId: string commentId: string } @@ -299,7 +301,7 @@ type SubscriptionTypeMap = { comment: CommentRecord } streamId: string - resourceIds: string[] + resourceIds: string } variables: SubscriptionCommentActivityArgs } From 0b90dcf0df579c62cea5b094746efb055ac4bc72 Mon Sep 17 00:00:00 2001 From: Kristaps Fabians Geikins Date: Fri, 24 Jan 2025 18:29:50 +0200 Subject: [PATCH 2/2] chore(server): moving out comments sub reporting to separate listeners --- .../modules/cli/commands/download/commit.ts | 7 +- .../modules/cli/commands/download/project.ts | 7 +- .../server/modules/comments/domain/events.ts | 2 + .../comments/events/subscriptionListeners.ts | 90 +++++++++++ .../comments/graph/resolvers/comments.ts | 20 +-- packages/server/modules/comments/index.ts | 32 ++++ .../server/modules/comments/services/index.ts | 149 +++++------------- .../modules/comments/services/management.ts | 97 ++---------- .../comments/tests/comments.graph.spec.js | 1 - .../modules/comments/tests/comments.spec.ts | 6 +- .../server/modules/cross-server-sync/index.ts | 7 +- 11 files changed, 191 insertions(+), 227 deletions(-) create mode 100644 packages/server/modules/comments/events/subscriptionListeners.ts diff --git a/packages/server/modules/cli/commands/download/commit.ts b/packages/server/modules/cli/commands/download/commit.ts index c977d772f..b984333f9 100644 --- a/packages/server/modules/cli/commands/download/commit.ts +++ b/packages/server/modules/cli/commands/download/commit.ts @@ -49,7 +49,6 @@ import { import { validateInputAttachmentsFactory } from '@/modules/comments/services/commentTextService' import { getBlobsFactory } from '@/modules/blobstorage/repositories' import { createCommitByBranchIdFactory } from '@/modules/core/services/commit/management' -import { publish } from '@/modules/shared/utils/subscriptions' import { getUserFactory } from '@/modules/core/repositories/users' import { createObjectFactory } from '@/modules/core/services/objects/management' import { getProjectDbClient } from '@/modules/multiregion/utils/dbSelector' @@ -137,8 +136,7 @@ const command: CommandModule< insertComments, insertCommentLinks, markCommentViewed, - emitEvent: getEventBus().emit, - publishSub: publish + emitEvent: getEventBus().emit }) const createCommentReplyAndNotify = createCommentReplyAndNotifyFactory({ @@ -151,8 +149,7 @@ const command: CommandModule< getViewerResourcesForComment: getViewerResourcesForCommentFactory({ getCommentsResources: getCommentsResourcesFactory({ db: projectDb }), getViewerResourcesFromLegacyIdentifiers - }), - publishSub: publish + }) }) const createCommitByBranchId = createCommitByBranchIdFactory({ diff --git a/packages/server/modules/cli/commands/download/project.ts b/packages/server/modules/cli/commands/download/project.ts index 53c63653a..a1f34f677 100644 --- a/packages/server/modules/cli/commands/download/project.ts +++ b/packages/server/modules/cli/commands/download/project.ts @@ -53,7 +53,6 @@ import { } from '@/modules/comments/repositories/comments' import { getBlobsFactory } from '@/modules/blobstorage/repositories' import { validateInputAttachmentsFactory } from '@/modules/comments/services/commentTextService' -import { publish } from '@/modules/shared/utils/subscriptions' import { getUserFactory } from '@/modules/core/repositories/users' import { createObjectFactory } from '@/modules/core/services/objects/management' import { authorizeResolver } from '@/modules/shared' @@ -162,8 +161,7 @@ const command: CommandModule< insertComments, insertCommentLinks, markCommentViewed, - emitEvent: getEventBus().emit, - publishSub: publish + emitEvent: getEventBus().emit }) const createCommentReplyAndNotify = createCommentReplyAndNotifyFactory({ getComment: getCommentFactory({ db: projectDb }), @@ -175,8 +173,7 @@ const command: CommandModule< getViewerResourcesForComment: getViewerResourcesForCommentFactory({ getCommentsResources: getCommentsResourcesFactory({ db: projectDb }), getViewerResourcesFromLegacyIdentifiers - }), - publishSub: publish + }) }) const createCommitByBranchId = createCommitByBranchIdFactory({ diff --git a/packages/server/modules/comments/domain/events.ts b/packages/server/modules/comments/domain/events.ts index 428912318..6e19679d8 100644 --- a/packages/server/modules/comments/domain/events.ts +++ b/packages/server/modules/comments/domain/events.ts @@ -2,6 +2,7 @@ import { CommentCreatedActivityInput, ReplyCreatedActivityInput } from '@/modules/activitystream/domain/types' +import { ViewerResourceItem } from '@/modules/comments/domain/types' import { CommentRecord } from '@/modules/comments/helpers/types' import { MutationCommentArchiveArgs } from '@/modules/core/graph/generated/graphql' @@ -18,6 +19,7 @@ export type CommentEventsPayloads = { comment: CommentRecord isThread: boolean input: CommentCreatedActivityInput | ReplyCreatedActivityInput + resourceItems: ViewerResourceItem[] } [CommentEvents.Updated]: { previousComment: CommentRecord diff --git a/packages/server/modules/comments/events/subscriptionListeners.ts b/packages/server/modules/comments/events/subscriptionListeners.ts new file mode 100644 index 000000000..f6368aa20 --- /dev/null +++ b/packages/server/modules/comments/events/subscriptionListeners.ts @@ -0,0 +1,90 @@ +import { CommentEvents } from '@/modules/comments/domain/events' +import { GetViewerResourcesForComment } from '@/modules/comments/domain/operations' +import { ProjectCommentsUpdatedMessageType } from '@/modules/core/graph/generated/graphql' +import { DependenciesOf } from '@/modules/shared/helpers/factory' +import { EventBusListen, EventPayload } from '@/modules/shared/services/eventBus' +import { + CommentSubscriptions, + ProjectSubscriptions, + PublishSubscription +} from '@/modules/shared/utils/subscriptions' + +const reportCommentCreatedFactory = + (deps: { publish: PublishSubscription }) => + async (payload: EventPayload) => { + const { comment, resourceItems } = payload.payload + + await Promise.all([ + // @deprecated unused in FE2 + deps.publish(CommentSubscriptions.CommentActivity, { + commentActivity: { + type: 'comment-added', + comment + }, + streamId: comment.streamId, + resourceIds: resourceItems.map((i) => i.versionId || i.objectId).join(',') + }), + deps.publish(ProjectSubscriptions.ProjectCommentsUpdated, { + projectCommentsUpdated: { + id: comment.id, + type: ProjectCommentsUpdatedMessageType.Created, + comment + }, + projectId: comment.streamId, + resourceItems + }) + ]) + } + +const reportCommentArchivedFactory = + (deps: { + publish: PublishSubscription + getViewerResourcesForComment: GetViewerResourcesForComment + }) => + async (payload: EventPayload) => { + const { + comment, + input: { archived, streamId } + } = payload.payload + + await Promise.all([ + deps.publish(CommentSubscriptions.CommentThreadActivity, { + commentThreadActivity: { + type: archived ? 'comment-archived' : 'comment-added' + }, + streamId, + commentId: comment.id + }), + deps.publish(ProjectSubscriptions.ProjectCommentsUpdated, { + projectCommentsUpdated: { + id: comment.id, + type: archived + ? ProjectCommentsUpdatedMessageType.Archived + : ProjectCommentsUpdatedMessageType.Created, + comment: archived ? null : comment + }, + projectId: streamId, + resourceItems: await deps.getViewerResourcesForComment(streamId, comment.id) + }) + ]) + } + +export const reportSubscriptionEventsFactory = + ( + deps: { + eventListen: EventBusListen + publish: PublishSubscription + } & DependenciesOf & + DependenciesOf + ) => + () => { + const reportCommentCreated = reportCommentCreatedFactory(deps) + const reportCommentArchived = reportCommentArchivedFactory(deps) + + const quitters = [ + deps.eventListen(CommentEvents.Created, reportCommentCreated), + deps.eventListen(CommentEvents.Archived, reportCommentArchived) + ] + + return () => quitters.forEach((q) => q()) + } diff --git a/packages/server/modules/comments/graph/resolvers/comments.ts b/packages/server/modules/comments/graph/resolvers/comments.ts index 7164e1626..fa59df8a2 100644 --- a/packages/server/modules/comments/graph/resolvers/comments.ts +++ b/packages/server/modules/comments/graph/resolvers/comments.ts @@ -541,8 +541,7 @@ export = { insertComments, insertCommentLinks, markCommentViewed, - emitEvent: getEventBus().emit, - publishSub: publish + emitEvent: getEventBus().emit }) return await createCommentThreadAndNotify(args.input, ctx.userId!) @@ -578,8 +577,7 @@ export = { getViewerResourcesForComment: getViewerResourcesForCommentFactory({ getCommentsResources: getCommentsResourcesFactory({ db: projectDb }), getViewerResourcesFromLegacyIdentifiers - }), - publishSub: publish + }) }) return await createCommentReplyAndNotify(args.input, ctx.userId!) @@ -641,7 +639,6 @@ export = { getStream, updateComment, getViewerResourcesForComment, - publishSub: publish, emitEvent: getEventBus().emit }) @@ -737,7 +734,6 @@ export = { deleteComment: deleteCommentFactory({ db: projectDb }), markCommentViewed: markCommentViewedFactory({ db: projectDb }), emitEvent: getEventBus().emit, - publishSub: publish, getViewerResourcesFromLegacyIdentifiers }) const comment = await createComment({ @@ -793,20 +789,11 @@ export = { }) const projectDb = await getProjectDbClient({ projectId: args.streamId }) - const getViewerResourcesFromLegacyIdentifiers = - buildGetViewerResourcesFromLegacyIdentifiers({ db: projectDb }) - const getViewerResourcesForComment = getViewerResourcesForCommentFactory({ - getCommentsResources: getCommentsResourcesFactory({ db: projectDb }), - getViewerResourcesFromLegacyIdentifiers - }) - const archiveComment = archiveCommentFactory({ getComment: getCommentFactory({ db: projectDb }), getStream, updateComment: updateCommentFactory({ db: projectDb }), - emitEvent: getEventBus().emit, - publishSub: publish, - getViewerResourcesForComment + emitEvent: getEventBus().emit }) await archiveComment({ ...args, userId: context.userId! }) // NOTE: permissions check inside service @@ -839,7 +826,6 @@ export = { deleteComment: deleteCommentFactory({ db: projectDb }), markCommentUpdated: markCommentUpdatedFactory({ db: projectDb }), emitEvent: getEventBus().emit, - publishSub: publish, getViewerResourcesForComment: getViewerResourcesForCommentFactory({ getCommentsResources: getCommentsResourcesFactory({ db: projectDb }), getViewerResourcesFromLegacyIdentifiers: diff --git a/packages/server/modules/comments/index.ts b/packages/server/modules/comments/index.ts index 0f495fa4c..39cba0970 100644 --- a/packages/server/modules/comments/index.ts +++ b/packages/server/modules/comments/index.ts @@ -2,10 +2,20 @@ import { db } from '@/db/knex' import { moduleLogger } from '@/logging/logging' import { saveActivityFactory } from '@/modules/activitystream/repositories' import { addStreamCommentMentionActivityFactory } from '@/modules/activitystream/services/streamActivity' +import { reportSubscriptionEventsFactory } from '@/modules/comments/events/subscriptionListeners' +import { getCommentsResourcesFactory } from '@/modules/comments/repositories/comments' import { notifyUsersOnCommentEventsFactory } from '@/modules/comments/services/notifications' +import { getCommitsAndTheirBranchIdsFactory } from '@/modules/core/repositories/commits' +import { getStreamObjectsFactory } from '@/modules/core/repositories/objects' +import { + getViewerResourcesForCommentFactory, + getViewerResourcesForCommentsFactory, + getViewerResourcesFromLegacyIdentifiersFactory +} from '@/modules/core/services/commit/viewerResources' import { publishNotification } from '@/modules/notifications/services/publication' import { Optional, SpeckleModule } from '@/modules/shared/helpers/typeHelper' import { getEventBus } from '@/modules/shared/services/eventBus' +import { publish } from '@/modules/shared/utils/subscriptions' let unsubFromEvents: Optional<() => void> = undefined @@ -22,6 +32,28 @@ const commentsModule: SpeckleModule = { }) }) unsubFromEvents = await notifyUsersOnCommentEvents() + + const getViewerResourcesFromLegacyIdentifiers = + getViewerResourcesFromLegacyIdentifiersFactory({ + getViewerResourcesForComments: getViewerResourcesForCommentsFactory({ + getCommentsResources: getCommentsResourcesFactory({ db }), + getViewerResourcesFromLegacyIdentifiers: (...args) => + getViewerResourcesFromLegacyIdentifiers(...args) // recursive dep + }), + getCommitsAndTheirBranchIds: getCommitsAndTheirBranchIdsFactory({ db }), + getStreamObjects: getStreamObjectsFactory({ db }) + }) + const getViewerResourcesForComment = getViewerResourcesForCommentFactory({ + getCommentsResources: getCommentsResourcesFactory({ db }), + getViewerResourcesFromLegacyIdentifiers: (...args) => + getViewerResourcesFromLegacyIdentifiers(...args) // recursive dep + }) + + reportSubscriptionEventsFactory({ + eventListen: getEventBus().listen, + publish, + getViewerResourcesForComment + })() } }, async finalize() {}, diff --git a/packages/server/modules/comments/services/index.ts b/packages/server/modules/comments/services/index.ts index d6a7ecc6d..ff75f9a81 100644 --- a/packages/server/modules/comments/services/index.ts +++ b/packages/server/modules/comments/services/index.ts @@ -5,8 +5,7 @@ import { isNonNullable, Roles } from '@speckle/shared' import { ResourceIdentifier, CommentCreateInput, - CommentEditInput, - ProjectCommentsUpdatedMessageType + CommentEditInput } from '@/modules/core/graph/generated/graphql' import { CommentLinkRecord, CommentRecord } from '@/modules/comments/helpers/types' import { SmartTextEditorValueSchema } from '@/modules/core/services/richTextEditorService' @@ -29,11 +28,6 @@ import { GetStream } from '@/modules/core/domain/streams/operations' import { EventBusEmit } from '@/modules/shared/services/eventBus' import { CommentEvents } from '@/modules/comments/domain/events' import { JSONContent } from '@tiptap/core' -import { - CommentSubscriptions, - ProjectSubscriptions, - PublishSubscription -} from '@/modules/shared/utils/subscriptions' export const streamResourceCheckFactory = (deps: { @@ -64,7 +58,6 @@ export const createCommentFactory = deleteComment: DeleteComment markCommentViewed: MarkCommentViewed emitEvent: EventBusEmit - publishSub: PublishSubscription getViewerResourcesFromLegacyIdentifiers: GetViewerResourcesFromLegacyIdentifiers }) => async ({ userId, input }: { userId: string; input: CommentCreateInput }) => { @@ -126,37 +119,19 @@ export const createCommentFactory = await deps.markCommentViewed(id, userId) // so we don't self mark a comment as unread the moment it's created - await Promise.all([ - deps.emitEvent({ - eventName: CommentEvents.Created, - payload: { - comment: newComment, - input, - isThread: true - } - }), - // @deprecated unused in FE2 - deps.publishSub(CommentSubscriptions.CommentActivity, { - commentActivity: { - type: 'comment-added', - comment: newComment - }, - streamId: input.streamId, - resourceIds: input.resources.map((res) => res?.resourceId).join(',') - }), - deps.publishSub(ProjectSubscriptions.ProjectCommentsUpdated, { - projectCommentsUpdated: { - id: newComment.id, - type: ProjectCommentsUpdatedMessageType.Created, - comment: newComment - }, - projectId: input.streamId, - resourceItems: await deps.getViewerResourcesFromLegacyIdentifiers( - input.streamId, - input.resources.filter(isNonNullable) - ) - }) - ]) + const resourceItems = await deps.getViewerResourcesFromLegacyIdentifiers( + input.streamId, + input.resources.filter(isNonNullable) + ) + await deps.emitEvent({ + eventName: CommentEvents.Created, + payload: { + comment: newComment, + input, + isThread: true, + resourceItems + } + }) return newComment } @@ -173,7 +148,6 @@ export const createCommentReplyFactory = deleteComment: DeleteComment markCommentUpdated: MarkCommentUpdated emitEvent: EventBusEmit - publishSub: PublishSubscription getViewerResourcesForComment: GetViewerResourcesForComment }) => async ({ @@ -225,45 +199,26 @@ export const createCommentReplyFactory = await deps.markCommentUpdated(parentCommentId) - await Promise.all([ - deps.emitEvent({ - eventName: CommentEvents.Created, - payload: { - comment: newComment, - isThread: false, - input: { - threadId: parentCommentId, - projectId: streamId, - content: { - blobIds, - doc: text - } + const resourceItems = await deps.getViewerResourcesForComment( + newComment.streamId, + newComment.id + ) + await deps.emitEvent({ + eventName: CommentEvents.Created, + payload: { + comment: newComment, + isThread: false, + input: { + threadId: parentCommentId, + projectId: streamId, + content: { + blobIds, + doc: text } - } - }), - // TODO: Move to event bus listeners - // @deprecated - deps.publishSub(CommentSubscriptions.CommentThreadActivity, { - commentThreadActivity: { - type: 'reply-added', - reply: newComment }, - streamId: newComment.streamId, - commentId: parentCommentId - }), - deps.publishSub(ProjectSubscriptions.ProjectCommentsUpdated, { - projectCommentsUpdated: { - id: newComment.id, - type: ProjectCommentsUpdatedMessageType.Created, - comment: newComment - }, - projectId: newComment.streamId, - resourceItems: await deps.getViewerResourcesForComment( - newComment.streamId, - newComment.id - ) - }) - ]) + resourceItems + } + }) return newComment } @@ -320,8 +275,6 @@ export const archiveCommentFactory = getStream: GetStream updateComment: UpdateComment emitEvent: EventBusEmit - publishSub: PublishSubscription - getViewerResourcesForComment: GetViewerResourcesForComment }) => async ({ commentId, @@ -349,36 +302,14 @@ export const archiveCommentFactory = const updatedComment = await deps.updateComment(commentId, { archived }) - await Promise.all([ - deps.emitEvent({ - eventName: CommentEvents.Archived, - payload: { - userId, - input: { archived, commentId, streamId }, - comment: updatedComment! - } - }), - // TODO: Move to event bus listeners - // @deprecated not used in FE2 - deps.publishSub(CommentSubscriptions.CommentThreadActivity, { - commentThreadActivity: { - type: archived ? 'comment-archived' : 'comment-added' - }, - streamId, - commentId - }), - deps.publishSub(ProjectSubscriptions.ProjectCommentsUpdated, { - projectCommentsUpdated: { - id: commentId, - type: archived - ? ProjectCommentsUpdatedMessageType.Archived - : ProjectCommentsUpdatedMessageType.Created, - comment: archived ? null : comment - }, - projectId: streamId, - resourceItems: await deps.getViewerResourcesForComment(streamId, comment.id) - }) - ]) + await deps.emitEvent({ + eventName: CommentEvents.Archived, + payload: { + userId, + input: { archived, commentId, streamId }, + comment: updatedComment! + } + }) return updatedComment! } diff --git a/packages/server/modules/comments/services/management.ts b/packages/server/modules/comments/services/management.ts index fabc211ab..a28c19f31 100644 --- a/packages/server/modules/comments/services/management.ts +++ b/packages/server/modules/comments/services/management.ts @@ -5,8 +5,7 @@ import { StreamInvalidAccessError } from '@/modules/core/errors/stream' import { CreateCommentInput, CreateCommentReplyInput, - EditCommentInput, - ProjectCommentsUpdatedMessageType + EditCommentInput } from '@/modules/core/graph/generated/graphql' import { CommentCreateError, CommentUpdateError } from '@/modules/comments/errors' import { buildCommentTextFromInput } from '@/modules/comments/services/commentTextService' @@ -39,11 +38,6 @@ import { import { GetStream } from '@/modules/core/domain/streams/operations' import { EventBusEmit } from '@/modules/shared/services/eventBus' import { CommentEvents } from '@/modules/comments/domain/events' -import { - CommentSubscriptions, - ProjectSubscriptions, - PublishSubscription -} from '@/modules/shared/utils/subscriptions' type AuthorizeProjectCommentsAccessDeps = { getStream: GetStream @@ -120,7 +114,6 @@ export const createCommentThreadAndNotifyFactory = insertCommentLinks: InsertCommentLinks markCommentViewed: MarkCommentViewed emitEvent: EventBusEmit - publishSub: PublishSubscription }): CreateCommentThreadAndNotify => async (input: CreateCommentInput, userId: string) => { const [resources] = await Promise.all([ @@ -184,27 +177,9 @@ export const createCommentThreadAndNotifyFactory = payload: { comment, input, - isThread: true + isThread: true, + resourceItems: resources } - }), - // TODO: Move to event bus listeners - // @deprecated unused in FE2 - deps.publishSub(CommentSubscriptions.CommentActivity, { - commentActivity: { - type: 'comment-added', - comment - }, - streamId: input.projectId, - resourceIds: resources.map((i) => i.versionId || i.objectId).join(',') - }), - deps.publishSub(ProjectSubscriptions.ProjectCommentsUpdated, { - projectCommentsUpdated: { - id: comment.id, - type: ProjectCommentsUpdatedMessageType.Created, - comment - }, - projectId: input.projectId, - resourceItems: resources }) ]) @@ -219,7 +194,6 @@ export const createCommentReplyAndNotifyFactory = insertCommentLinks: InsertCommentLinks markCommentUpdated: MarkCommentUpdated emitEvent: EventBusEmit - publishSub: PublishSubscription getViewerResourcesForComment: GetViewerResourcesForComment }): CreateCommentReplyAndNotify => async (input: CreateCommentReplyInput, userId: string) => { @@ -254,6 +228,10 @@ export const createCommentReplyAndNotifyFactory = } // Mark parent comment updated and emit events + const resourceItems = await deps.getViewerResourcesForComment( + reply.streamId, + reply.id + ) await Promise.all([ deps.markCommentUpdated(thread.id), deps.emitEvent({ @@ -261,27 +239,9 @@ export const createCommentReplyAndNotifyFactory = payload: { comment: reply, input, - isThread: false + isThread: false, + resourceItems } - }), - // TODO: Move to event bus listeners - // @deprecated - deps.publishSub(CommentSubscriptions.CommentThreadActivity, { - commentThreadActivity: { - type: 'reply-added', - reply - }, - streamId: reply.streamId, - commentId: thread.id - }), - deps.publishSub(ProjectSubscriptions.ProjectCommentsUpdated, { - projectCommentsUpdated: { - id: reply.id, - type: ProjectCommentsUpdatedMessageType.Created, - comment: reply - }, - projectId: reply.streamId, - resourceItems: await deps.getViewerResourcesForComment(reply.streamId, reply.id) }) ]) @@ -329,7 +289,6 @@ export const archiveCommentAndNotifyFactory = getStream: GetStream updateComment: UpdateComment emitEvent: EventBusEmit - publishSub: PublishSubscription getViewerResourcesForComment: GetViewerResourcesForComment }): ArchiveCommentAndNotify => async (commentId: string, userId: string, archived = true) => { @@ -353,36 +312,14 @@ export const archiveCommentAndNotifyFactory = archived }) - await Promise.all([ - deps.emitEvent({ - eventName: CommentEvents.Archived, - payload: { - userId, - input: { archived, commentId, streamId: stream.id }, - comment: updatedComment! - } - }), - // TODO: Move to event bus listeners - // @deprecated not used in FE2 - deps.publishSub(CommentSubscriptions.CommentThreadActivity, { - commentThreadActivity: { - type: archived ? 'comment-archived' : 'comment-added' - }, - streamId: stream.id, - commentId - }), - deps.publishSub(ProjectSubscriptions.ProjectCommentsUpdated, { - projectCommentsUpdated: { - id: commentId, - type: archived - ? ProjectCommentsUpdatedMessageType.Archived - : ProjectCommentsUpdatedMessageType.Created, - comment: archived ? null : comment - }, - projectId: stream.id, - resourceItems: await deps.getViewerResourcesForComment(stream.id, comment.id) - }) - ]) + await deps.emitEvent({ + eventName: CommentEvents.Archived, + payload: { + userId, + input: { archived, commentId, streamId: stream.id }, + comment: updatedComment! + } + }) return updatedComment } diff --git a/packages/server/modules/comments/tests/comments.graph.spec.js b/packages/server/modules/comments/tests/comments.graph.spec.js index cf35a3ffd..1a2664ef9 100644 --- a/packages/server/modules/comments/tests/comments.graph.spec.js +++ b/packages/server/modules/comments/tests/comments.graph.spec.js @@ -147,7 +147,6 @@ const createComment = createCommentFactory({ deleteComment: deleteCommentFactory({ db }), markCommentViewed, emitEvent: getEventBus().emit, - publishSub: publish, getViewerResourcesFromLegacyIdentifiers }) diff --git a/packages/server/modules/comments/tests/comments.spec.ts b/packages/server/modules/comments/tests/comments.spec.ts index cf235e181..d45821603 100644 --- a/packages/server/modules/comments/tests/comments.spec.ts +++ b/packages/server/modules/comments/tests/comments.spec.ts @@ -165,7 +165,6 @@ const createComment = createCommentFactory({ deleteComment, markCommentViewed, emitEvent: getEventBus().emit, - publishSub: publish, getViewerResourcesFromLegacyIdentifiers }) const getViewerResourcesForComment = getViewerResourcesForCommentFactory({ @@ -181,7 +180,6 @@ const createCommentReply = createCommentReplyFactory({ deleteComment, markCommentUpdated: markCommentUpdatedFactory({ db }), emitEvent: getEventBus().emit, - publishSub: publish, getViewerResourcesForComment }) const getComment = getCommentFactory({ db }) @@ -196,9 +194,7 @@ const archiveComment = archiveCommentFactory({ getComment, getStream, updateComment, - emitEvent: getEventBus().emit, - publishSub: publish, - getViewerResourcesForComment + emitEvent: getEventBus().emit }) const getComments = getCommentsLegacyFactory({ db }) const getResourceCommentCount = getResourceCommentCountFactory({ db }) diff --git a/packages/server/modules/cross-server-sync/index.ts b/packages/server/modules/cross-server-sync/index.ts index d2c28ea2a..310a16b90 100644 --- a/packages/server/modules/cross-server-sync/index.ts +++ b/packages/server/modules/cross-server-sync/index.ts @@ -67,7 +67,6 @@ import { ensureOnboardingProjectFactory } from '@/modules/cross-server-sync/serv import { downloadProjectFactory } from '@/modules/cross-server-sync/services/project' import { SpeckleModule } from '@/modules/shared/helpers/typeHelper' import { getEventBus } from '@/modules/shared/services/eventBus' -import { publish } from '@/modules/shared/utils/subscriptions' const crossServerSyncModule: SpeckleModule = { init() { @@ -114,8 +113,7 @@ const crossServerSyncModule: SpeckleModule = { insertComments, insertCommentLinks, markCommentViewed, - emitEvent: getEventBus().emit, - publishSub: publish + emitEvent: getEventBus().emit }) const createCommentReplyAndNotify = createCommentReplyAndNotifyFactory({ getComment: getCommentFactory({ db }), @@ -127,8 +125,7 @@ const crossServerSyncModule: SpeckleModule = { getViewerResourcesForComment: getViewerResourcesForCommentFactory({ getCommentsResources: getCommentsResourcesFactory({ db }), getViewerResourcesFromLegacyIdentifiers - }), - publishSub: publish + }) }) const getStreamBranchByName = getStreamBranchByNameFactory({ db }) const createCommitByBranchId = createCommitByBranchIdFactory({