Files
speckle-server/packages/server/modules/comments/index.ts
T
Daniel Gak Anagrov 3ca4a11ca3 feat(notifications): basic listener structure, notification record, delayed mechanism (#5432)
* feat: basic notification listener sturcuture

* feat: clean up generated gql

* chore: edited structure

* feat: added basic repo

* feat: ported comment email to job queue

* feat: ported stream access request accepted

* feat: added notification insertion

* fix: minor typings

* feat: delayed notifications

* updated types

* feat: fixed gql

* notifications are listed

* index on notifications

* feat: while loop skiping for update locked

* delayed notification for access request

* take into account user prefrences

* on comment view, notification is marked as read

* feat: added gql notifications

* feat: avoid raising errors

* fix: error added scopes

* fix: mr comments

* fix: cursor and service method

* feat: added stronger types to notifications and versioning logic

* minor: rows updated
2025-10-06 12:19:12 +01:00

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/publishNotification'
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