Merge pull request #3365 from specklesystems/alessandro/web-943-add-branch-updated-activity
Activitystream IoC 3 addBranchUpdatedActivity
This commit is contained in:
@@ -11,11 +11,13 @@ import {
|
||||
} from '@/modules/activitystream/helpers/types'
|
||||
import { CommentRecord } from '@/modules/comments/helpers/types'
|
||||
import {
|
||||
BranchUpdateInput,
|
||||
CommitCreateInput,
|
||||
CommitUpdateInput,
|
||||
MutationCommentArchiveArgs,
|
||||
ProjectUpdateInput,
|
||||
StreamUpdateInput,
|
||||
UpdateModelInput,
|
||||
UpdateVersionInput
|
||||
} from '@/modules/core/graph/generated/graphql'
|
||||
import {
|
||||
@@ -271,3 +273,10 @@ export type AddReplyAddedActivity = (params: {
|
||||
export type AddBranchCreatedActivity = (params: {
|
||||
branch: BranchRecord
|
||||
}) => Promise<void>
|
||||
|
||||
export type AddBranchUpdatedActivity = (params: {
|
||||
update: BranchUpdateInput | UpdateModelInput
|
||||
userId: string
|
||||
oldBranch: BranchRecord
|
||||
newBranch: BranchRecord
|
||||
}) => Promise<void>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { ActionTypes, ResourceTypes } from '@/modules/activitystream/helpers/types'
|
||||
import { BranchRecord } from '@/modules/core/helpers/types'
|
||||
import {
|
||||
pubsub,
|
||||
BranchSubscriptions as BranchPubsubEvents,
|
||||
@@ -7,10 +6,8 @@ import {
|
||||
} from '@/modules/shared/utils/subscriptions'
|
||||
import {
|
||||
BranchDeleteInput,
|
||||
BranchUpdateInput,
|
||||
DeleteModelInput,
|
||||
ProjectModelsUpdatedMessageType,
|
||||
UpdateModelInput
|
||||
ProjectModelsUpdatedMessageType
|
||||
} from '@/modules/core/graph/generated/graphql'
|
||||
import { ProjectSubscriptions, publish } from '@/modules/shared/utils/subscriptions'
|
||||
import { isBranchDeleteInput, isBranchUpdateInput } from '@/modules/core/helpers/branch'
|
||||
@@ -18,6 +15,7 @@ import { saveActivityFactory } from '@/modules/activitystream/repositories'
|
||||
import { db } from '@/db/knex'
|
||||
import {
|
||||
AddBranchCreatedActivity,
|
||||
AddBranchUpdatedActivity,
|
||||
SaveActivity
|
||||
} from '@/modules/activitystream/domain/operations'
|
||||
|
||||
@@ -61,40 +59,44 @@ export const addBranchCreatedActivityFactory =
|
||||
])
|
||||
}
|
||||
|
||||
export async function addBranchUpdatedActivity(params: {
|
||||
update: BranchUpdateInput | UpdateModelInput
|
||||
userId: string
|
||||
oldBranch: BranchRecord
|
||||
newBranch: BranchRecord
|
||||
}) {
|
||||
const { update, userId, oldBranch, newBranch } = params
|
||||
export const addBranchUpdatedActivityFactory =
|
||||
({
|
||||
saveActivity,
|
||||
publish
|
||||
}: {
|
||||
saveActivity: SaveActivity
|
||||
publish: PublishSubscription
|
||||
}): AddBranchUpdatedActivity =>
|
||||
async (params) => {
|
||||
const { update, userId, oldBranch, newBranch } = params
|
||||
|
||||
const streamId = isBranchUpdateInput(update) ? update.streamId : update.projectId
|
||||
await Promise.all([
|
||||
saveActivityFactory({ db })({
|
||||
streamId,
|
||||
resourceType: ResourceTypes.Branch,
|
||||
resourceId: update.id,
|
||||
actionType: ActionTypes.Branch.Update,
|
||||
userId,
|
||||
info: { old: oldBranch, new: update },
|
||||
message: `Branch metadata changed for branch ${update.id}`
|
||||
}),
|
||||
pubsub.publish(BranchPubsubEvents.BranchUpdated, {
|
||||
branchUpdated: { ...update },
|
||||
streamId,
|
||||
branchId: update.id
|
||||
}),
|
||||
publish(ProjectSubscriptions.ProjectModelsUpdated, {
|
||||
projectId: streamId,
|
||||
projectModelsUpdated: {
|
||||
model: newBranch,
|
||||
id: newBranch.id,
|
||||
type: ProjectModelsUpdatedMessageType.Updated
|
||||
}
|
||||
})
|
||||
])
|
||||
}
|
||||
const streamId = isBranchUpdateInput(update) ? update.streamId : update.projectId
|
||||
await Promise.all([
|
||||
saveActivity({
|
||||
streamId,
|
||||
resourceType: ResourceTypes.Branch,
|
||||
resourceId: update.id,
|
||||
actionType: ActionTypes.Branch.Update,
|
||||
userId,
|
||||
info: { old: oldBranch, new: update },
|
||||
message: `Branch metadata changed for branch ${update.id}`
|
||||
}),
|
||||
// @deprecated
|
||||
pubsub.publish(BranchPubsubEvents.BranchUpdated, {
|
||||
branchUpdated: { ...update },
|
||||
streamId,
|
||||
branchId: update.id
|
||||
}),
|
||||
publish(ProjectSubscriptions.ProjectModelsUpdated, {
|
||||
projectId: streamId,
|
||||
projectModelsUpdated: {
|
||||
model: newBranch,
|
||||
id: newBranch.id,
|
||||
type: ProjectModelsUpdatedMessageType.Updated
|
||||
}
|
||||
})
|
||||
])
|
||||
}
|
||||
|
||||
export async function addBranchDeletedActivity(params: {
|
||||
input: BranchDeleteInput | DeleteModelInput
|
||||
|
||||
@@ -17,9 +17,9 @@ import {
|
||||
} from '@/modules/core/repositories/branches'
|
||||
import { db } from '@/db/knex'
|
||||
import {
|
||||
addBranchUpdatedActivity,
|
||||
addBranchDeletedActivity,
|
||||
addBranchCreatedActivityFactory
|
||||
addBranchCreatedActivityFactory,
|
||||
addBranchUpdatedActivityFactory
|
||||
} from '@/modules/activitystream/services/branchActivity'
|
||||
import {
|
||||
getStreamFactory,
|
||||
@@ -47,7 +47,10 @@ const createBranchAndNotify = createBranchAndNotifyFactory({
|
||||
const updateBranchAndNotify = updateBranchAndNotifyFactory({
|
||||
getBranchById,
|
||||
updateBranch: updateBranchFactory({ db }),
|
||||
addBranchUpdatedActivity
|
||||
addBranchUpdatedActivity: addBranchUpdatedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
})
|
||||
})
|
||||
const deleteBranchAndNotify = deleteBranchAndNotifyFactory({
|
||||
getStream,
|
||||
|
||||
@@ -53,7 +53,7 @@ import { db } from '@/db/knex'
|
||||
import {
|
||||
addBranchCreatedActivityFactory,
|
||||
addBranchDeletedActivity,
|
||||
addBranchUpdatedActivity
|
||||
addBranchUpdatedActivityFactory
|
||||
} from '@/modules/activitystream/services/branchActivity'
|
||||
import {
|
||||
getStreamFactory,
|
||||
@@ -99,7 +99,10 @@ const createBranchAndNotify = createBranchAndNotifyFactory({
|
||||
const updateBranchAndNotify = updateBranchAndNotifyFactory({
|
||||
getBranchById: getBranchByIdFactory({ db }),
|
||||
updateBranch: updateBranchFactory({ db }),
|
||||
addBranchUpdatedActivity
|
||||
addBranchUpdatedActivity: addBranchUpdatedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
})
|
||||
})
|
||||
const deleteBranchAndNotify = deleteBranchAndNotifyFactory({
|
||||
getStream,
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import { Roles, isNullOrUndefined } from '@speckle/shared'
|
||||
import {
|
||||
addBranchDeletedActivity,
|
||||
addBranchUpdatedActivity
|
||||
} from '@/modules/activitystream/services/branchActivity'
|
||||
import { addBranchDeletedActivity } from '@/modules/activitystream/services/branchActivity'
|
||||
import {
|
||||
BranchCreateError,
|
||||
BranchDeleteError,
|
||||
@@ -34,7 +31,10 @@ import {
|
||||
GetStream,
|
||||
MarkBranchStreamUpdated
|
||||
} from '@/modules/core/domain/streams/operations'
|
||||
import { AddBranchCreatedActivity } from '@/modules/activitystream/domain/operations'
|
||||
import {
|
||||
AddBranchCreatedActivity,
|
||||
AddBranchUpdatedActivity
|
||||
} from '@/modules/activitystream/domain/operations'
|
||||
|
||||
const isBranchCreateInput = (
|
||||
i: BranchCreateInput | CreateModelInput
|
||||
@@ -68,7 +68,7 @@ export const updateBranchAndNotifyFactory =
|
||||
(deps: {
|
||||
getBranchById: GetBranchById
|
||||
updateBranch: UpdateBranch
|
||||
addBranchUpdatedActivity: typeof addBranchUpdatedActivity
|
||||
addBranchUpdatedActivity: AddBranchUpdatedActivity
|
||||
}): UpdateBranchAndNotify =>
|
||||
async (input: BranchUpdateInput | UpdateModelInput, userId: string) => {
|
||||
const streamId = isBranchUpdateInput(input) ? input.streamId : input.projectId
|
||||
|
||||
@@ -24,8 +24,8 @@ const {
|
||||
getStreamBranchCountFactory
|
||||
} = require('@/modules/core/repositories/branches')
|
||||
const {
|
||||
addBranchUpdatedActivity,
|
||||
addBranchDeletedActivity
|
||||
addBranchDeletedActivity,
|
||||
addBranchUpdatedActivityFactory
|
||||
} = require('@/modules/activitystream/services/branchActivity')
|
||||
const {
|
||||
getStreamFactory,
|
||||
@@ -129,7 +129,10 @@ const createBranch = createBranchFactory({ db: knex })
|
||||
const updateBranchAndNotify = updateBranchAndNotifyFactory({
|
||||
getBranchById: getBranchByIdFactory({ db: knex }),
|
||||
updateBranch: updateBranchFactory({ db: knex }),
|
||||
addBranchUpdatedActivity
|
||||
addBranchUpdatedActivity: addBranchUpdatedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
})
|
||||
})
|
||||
const deleteBranchAndNotify = deleteBranchAndNotifyFactory({
|
||||
getStream,
|
||||
|
||||
Reference in New Issue
Block a user