Files
speckle-server/packages/server/modules/comments/index.ts
T
Kristaps Fabians Geikins 6051917b59 chore(server): refactor activityStream invocations - batch #7 - streams (#4014)
* chore(server): refactor activityStream invocations - batch #7 - streams

* test fix

* more test fixes

* CR comment fix
2025-02-24 12:34:56 +02:00

64 lines
2.6 KiB
TypeScript

import { db } from '@/db/knex'
import { moduleLogger } from '@/logging/logging'
import { saveActivityFactory } from '@/modules/activitystream/repositories'
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
const commentsModule: SpeckleModule = {
async init(_, isInitial) {
moduleLogger.info('🗣 Init comments module')
if (isInitial) {
const notifyUsersOnCommentEvents = notifyUsersOnCommentEventsFactory({
eventBus: getEventBus(),
publish: publishNotification,
saveActivity: saveActivityFactory({ db })
})
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() {},
async shutdown() {
unsubFromEvents?.()
unsubFromEvents = undefined
}
}
export = commentsModule