4b06f42db7
* sort of works * type fixes * added option to run old way too
64 lines
2.7 KiB
TypeScript
64 lines
2.7 KiB
TypeScript
import { db } from '@/db/knex'
|
|
import { moduleLogger } from '@/observability/logging'
|
|
import { saveStreamActivityFactory } 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 type { 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: saveStreamActivityFactory({ 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 default commentsModule
|