Activitystream IoC 1 addStreamCreatedActivity (#3206)
* chore(activitystream): addStreamPermissionsAddedActivity refactor multi region * chore(activitystream): addStreamCreatedActivity refactor multi region
This commit is contained in:
committed by
GitHub
parent
f52bafc7e2
commit
c2c95d20c2
@@ -175,38 +175,46 @@ export async function addStreamClonedActivity(
|
||||
/**
|
||||
* Save "user created stream" activity item
|
||||
*/
|
||||
export async function addStreamCreatedActivity(params: {
|
||||
streamId: string
|
||||
creatorId: string
|
||||
input: StreamCreateInput | ProjectCreateInput
|
||||
stream: StreamRecord
|
||||
}) {
|
||||
const { streamId, creatorId, input, stream } = params
|
||||
export const addStreamCreatedActivityFactory =
|
||||
({
|
||||
saveActivity,
|
||||
publish
|
||||
}: {
|
||||
saveActivity: SaveActivity
|
||||
publish: PublishSubscription
|
||||
}) =>
|
||||
async (params: {
|
||||
streamId: string
|
||||
creatorId: string
|
||||
input: StreamCreateInput | ProjectCreateInput
|
||||
stream: StreamRecord
|
||||
}) => {
|
||||
const { streamId, creatorId, input, stream } = params
|
||||
|
||||
await Promise.all([
|
||||
saveActivityFactory({ db })({
|
||||
streamId,
|
||||
resourceType: ResourceTypes.Stream,
|
||||
resourceId: streamId,
|
||||
actionType: ActionTypes.Stream.Create,
|
||||
userId: creatorId,
|
||||
info: { input },
|
||||
message: `Stream ${input.name} created`
|
||||
}),
|
||||
pubsub.publish(StreamPubsubEvents.UserStreamAdded, {
|
||||
userStreamAdded: { id: streamId, ...input },
|
||||
ownerId: creatorId
|
||||
}),
|
||||
publish(UserSubscriptions.UserProjectsUpdated, {
|
||||
userProjectsUpdated: {
|
||||
id: streamId,
|
||||
type: UserProjectsUpdatedMessageType.Added,
|
||||
project: stream
|
||||
},
|
||||
ownerId: creatorId
|
||||
})
|
||||
])
|
||||
}
|
||||
await Promise.all([
|
||||
saveActivity({
|
||||
streamId,
|
||||
resourceType: ResourceTypes.Stream,
|
||||
resourceId: streamId,
|
||||
actionType: ActionTypes.Stream.Create,
|
||||
userId: creatorId,
|
||||
info: { input },
|
||||
message: `Stream ${input.name} created`
|
||||
}),
|
||||
publish(StreamPubsubEvents.UserStreamAdded, {
|
||||
userStreamAdded: { id: streamId, ...input },
|
||||
ownerId: creatorId
|
||||
}),
|
||||
publish(UserSubscriptions.UserProjectsUpdated, {
|
||||
userProjectsUpdated: {
|
||||
id: streamId,
|
||||
type: UserProjectsUpdatedMessageType.Added,
|
||||
project: stream
|
||||
},
|
||||
ownerId: creatorId
|
||||
})
|
||||
])
|
||||
}
|
||||
|
||||
/**
|
||||
* Save "stream permissions granted to user" activity item
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { MaybeNullOrUndefined, Roles, wait } from '@speckle/shared'
|
||||
import {
|
||||
addStreamCreatedActivity,
|
||||
addStreamCreatedActivityFactory,
|
||||
addStreamDeletedActivity,
|
||||
addStreamUpdatedActivity
|
||||
} from '@/modules/activitystream/services/streamActivity'
|
||||
@@ -55,6 +55,8 @@ import { buildCoreInviteEmailContentsFactory } from '@/modules/serverinvites/ser
|
||||
import { getEventBus } from '@/modules/shared/services/eventBus'
|
||||
import { ProjectInviteResourceType } from '@/modules/serverinvites/domain/constants'
|
||||
import { createBranchFactory } from '@/modules/core/repositories/branches'
|
||||
import { saveActivityFactory } from '@/modules/activitystream/repositories'
|
||||
import { publish } from '@/modules/shared/utils/subscriptions'
|
||||
|
||||
export async function createStreamReturnRecord(
|
||||
params: (StreamCreateInput | ProjectCreateInput) & {
|
||||
@@ -112,7 +114,10 @@ export async function createStreamReturnRecord(
|
||||
|
||||
// Save activity
|
||||
if (createActivity) {
|
||||
await addStreamCreatedActivity({
|
||||
await addStreamCreatedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
})({
|
||||
streamId,
|
||||
input: params,
|
||||
stream,
|
||||
|
||||
Reference in New Issue
Block a user