Merge pull request #3149 from specklesystems/alessandro/web-943-add-stream-comment-mention
Activitystream IoC 1 addStreamCommentMentionActivity
This commit is contained in:
@@ -146,3 +146,11 @@ export type CreateActivitySummary = (args: {
|
||||
start: Date
|
||||
end: Date
|
||||
}) => Promise<ActivitySummary | null>
|
||||
|
||||
export type AddStreamCommentMentionActivity = (params: {
|
||||
streamId: string
|
||||
mentionAuthorId: string
|
||||
mentionTargetId: string
|
||||
commentId: string
|
||||
threadId: string
|
||||
}) => Promise<void>
|
||||
|
||||
@@ -23,6 +23,10 @@ import {
|
||||
} from '@/modules/shared/utils/subscriptions'
|
||||
import { saveActivityFactory } from '@/modules/activitystream/repositories'
|
||||
import { db } from '@/db/knex'
|
||||
import {
|
||||
AddStreamCommentMentionActivity,
|
||||
SaveActivity
|
||||
} from '@/modules/activitystream/domain/operations'
|
||||
|
||||
/**
|
||||
* Save "stream updated" activity
|
||||
@@ -408,26 +412,21 @@ export async function addStreamInviteDeclinedActivity(params: {
|
||||
/**
|
||||
* Save "user mentioned in stream comment" activity item
|
||||
*/
|
||||
export async function addStreamCommentMentionActivity(params: {
|
||||
streamId: string
|
||||
mentionAuthorId: string
|
||||
mentionTargetId: string
|
||||
commentId: string
|
||||
threadId: string
|
||||
}) {
|
||||
const { streamId, mentionAuthorId, mentionTargetId, commentId, threadId } = params
|
||||
await saveActivityFactory({ db })({
|
||||
streamId,
|
||||
resourceType: ResourceTypes.Comment,
|
||||
resourceId: commentId,
|
||||
actionType: ActionTypes.Comment.Mention,
|
||||
userId: mentionAuthorId,
|
||||
message: `User ${mentionAuthorId} mentioned user ${mentionTargetId} in comment ${commentId}`,
|
||||
info: {
|
||||
mentionAuthorId,
|
||||
mentionTargetId,
|
||||
commentId,
|
||||
threadId
|
||||
}
|
||||
})
|
||||
}
|
||||
export const addStreamCommentMentionActivityFactory =
|
||||
({ saveActivity }: { saveActivity: SaveActivity }): AddStreamCommentMentionActivity =>
|
||||
async ({ streamId, mentionAuthorId, mentionTargetId, commentId, threadId }) => {
|
||||
await saveActivity({
|
||||
streamId,
|
||||
resourceType: ResourceTypes.Comment,
|
||||
resourceId: commentId,
|
||||
actionType: ActionTypes.Comment.Mention,
|
||||
userId: mentionAuthorId,
|
||||
message: `User ${mentionAuthorId} mentioned user ${mentionTargetId} in comment ${commentId}`,
|
||||
info: {
|
||||
mentionAuthorId,
|
||||
mentionTargetId,
|
||||
commentId,
|
||||
threadId
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { db } from '@/db/knex'
|
||||
import { moduleLogger } from '@/logging/logging'
|
||||
import { addStreamCommentMentionActivity } from '@/modules/activitystream/services/streamActivity'
|
||||
import { saveActivityFactory } from '@/modules/activitystream/repositories'
|
||||
import { addStreamCommentMentionActivityFactory } from '@/modules/activitystream/services/streamActivity'
|
||||
import { CommentsEmitter } from '@/modules/comments/events/emitter'
|
||||
import { notifyUsersOnCommentEventsFactory } from '@/modules/comments/services/notifications'
|
||||
import { publishNotification } from '@/modules/notifications/services/publication'
|
||||
@@ -15,7 +17,9 @@ const commentsModule: SpeckleModule = {
|
||||
const notifyUsersOnCommentEvents = notifyUsersOnCommentEventsFactory({
|
||||
commentsEventsListen: CommentsEmitter.listen,
|
||||
publish: publishNotification,
|
||||
addStreamCommentMentionActivity
|
||||
addStreamCommentMentionActivity: addStreamCommentMentionActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db })
|
||||
})
|
||||
})
|
||||
unsubFromEvents = await notifyUsersOnCommentEvents()
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
NotificationPublisher,
|
||||
NotificationType
|
||||
} from '@/modules/notifications/helpers/types'
|
||||
import { addStreamCommentMentionActivity } from '@/modules/activitystream/services/streamActivity'
|
||||
import { AddStreamCommentMentionActivity } from '@/modules/activitystream/domain/operations'
|
||||
|
||||
function findMentionedUserIds(doc: JSONContent) {
|
||||
const mentionedUserIds = new Set<string>()
|
||||
@@ -36,7 +36,7 @@ function collectMentionedUserIds(comment: CommentRecord): string[] {
|
||||
|
||||
type SendNotificationsForUsersDeps = {
|
||||
publish: NotificationPublisher
|
||||
addStreamCommentMentionActivity: typeof addStreamCommentMentionActivity
|
||||
addStreamCommentMentionActivity: AddStreamCommentMentionActivity
|
||||
}
|
||||
|
||||
const sendNotificationsForUsersFactory =
|
||||
|
||||
Reference in New Issue
Block a user