Skip to content

Commit

Permalink
Moar merging
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandruPopovici committed Oct 14, 2024
2 parents 490008d + 9bafc38 commit b422fc3
Show file tree
Hide file tree
Showing 25 changed files with 357 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const roleTooltip = computed(() => {
})
const isTargettingWorkspaceGuest = computed(
() => props.collaborator.role === Roles.Workspace.Guest
() => props.collaborator.workspaceRole === Roles.Workspace.Guest
)
const onActionChosen = (
Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"typescript.suggest.autoImports": true,
"typescript.preferences.importModuleSpecifier": "non-relative",
"javascript.preferences.importModuleSpecifier": "non-relative",
"volar.completion.preferredTagNameCase": "kebab"
"volar.completion.preferredTagNameCase": "kebab",
"vitest.disableWorkspaceWarning": true
}
3 changes: 3 additions & 0 deletions packages/preview-service/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"vitest.disableWorkspaceWarning": true
}
13 changes: 12 additions & 1 deletion packages/server/modules/activitystream/domain/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import {
} from '@/modules/activitystream/helpers/types'
import {
CommitCreateInput,
CommitUpdateInput,
ProjectUpdateInput,
StreamUpdateInput
StreamUpdateInput,
UpdateVersionInput
} from '@/modules/core/graph/generated/graphql'
import {
CommitRecord,
Expand Down Expand Up @@ -212,3 +214,12 @@ export type AddCommitCreatedActivity = (params: {
modelId: string
commit: CommitRecord
}) => Promise<void>

export type AddCommitUpdatedActivity = (params: {
commitId: string
streamId: string
userId: string
originalCommit: CommitRecord
update: CommitUpdateInput | UpdateVersionInput
newCommit: CommitRecord
}) => Promise<void>
93 changes: 51 additions & 42 deletions packages/server/modules/activitystream/services/commitActivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { saveActivityFactory } from '@/modules/activitystream/repositories'
import { db } from '@/db/knex'
import {
AddCommitCreatedActivity,
AddCommitUpdatedActivity,
SaveActivity
} from '@/modules/activitystream/domain/operations'

Expand Down Expand Up @@ -80,49 +81,57 @@ const isOldVersionUpdateInput = (
i: CommitUpdateInput | UpdateVersionInput
): i is CommitUpdateInput => has(i, 'streamId')

export async function addCommitUpdatedActivity(params: {
commitId: string
streamId: string
userId: string
originalCommit: CommitRecord
update: CommitUpdateInput | UpdateVersionInput
newCommit: CommitRecord
}) {
const { commitId, streamId, userId, originalCommit, update, newCommit } = params
const legacyUpdateStruct: CommitUpdateInput = isOldVersionUpdateInput(update)
? update
: {
id: update.versionId,
message: update.message,
streamId
}
export const addCommitUpdatedActivityFactory =
({
saveActivity,
publish
}: {
saveActivity: SaveActivity
publish: PublishSubscription
}): AddCommitUpdatedActivity =>
async (params: {
commitId: string
streamId: string
userId: string
originalCommit: CommitRecord
update: CommitUpdateInput | UpdateVersionInput
newCommit: CommitRecord
}) => {
const { commitId, streamId, userId, originalCommit, update, newCommit } = params
const legacyUpdateStruct: CommitUpdateInput = isOldVersionUpdateInput(update)
? update
: {
id: update.versionId,
message: update.message,
streamId
}

await Promise.all([
saveActivityFactory({ db })({
streamId,
resourceType: ResourceTypes.Commit,
resourceId: commitId,
actionType: ActionTypes.Commit.Update,
userId,
info: { old: originalCommit, new: update },
message: `Commit updated: ${commitId}`
}),
pubsub.publish(CommitPubsubEvents.CommitUpdated, {
commitUpdated: { ...legacyUpdateStruct },
streamId,
commitId
}),
publish(ProjectSubscriptions.ProjectVersionsUpdated, {
projectId: streamId,
projectVersionsUpdated: {
id: commitId,
version: newCommit,
type: ProjectVersionsUpdatedMessageType.Updated,
modelId: null
}
})
])
}
await Promise.all([
saveActivity({
streamId,
resourceType: ResourceTypes.Commit,
resourceId: commitId,
actionType: ActionTypes.Commit.Update,
userId,
info: { old: originalCommit, new: update },
message: `Commit updated: ${commitId}`
}),
publish(CommitPubsubEvents.CommitUpdated, {
commitUpdated: { ...legacyUpdateStruct },
streamId,
commitId
}),
publish(ProjectSubscriptions.ProjectVersionsUpdated, {
projectId: streamId,
projectVersionsUpdated: {
id: commitId,
version: newCommit,
type: ProjectVersionsUpdatedMessageType.Updated,
modelId: null
}
})
])
}

export async function addCommitMovedActivity(params: {
commitId: string
Expand Down
18 changes: 18 additions & 0 deletions packages/server/modules/core/domain/streams/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ export type StoreStream = (
}>
) => Promise<Stream>

export type SetStreamFavorited = (params: {
streamId: string
userId: string
favorited?: boolean
}) => Promise<void>

export type CanUserFavoriteStream = (params: {
userId: string
streamId: string
}) => Promise<boolean>

export type DeleteStreamRecords = (streamId: string) => Promise<number>

export type GetOnboardingBaseStream = (version: string) => Promise<Optional<Stream>>
Expand Down Expand Up @@ -224,3 +235,10 @@ export type GetFavoriteStreamsCollection = (params: {
cursor?: string | null | undefined
streamIdWhitelist?: string[] | undefined
}) => Promise<{ totalCount: number; cursor: Nullable<string>; items: Stream[] }>

export type FavoriteStream = (params: {
userId: string
streamId: string
favorited?: boolean | undefined
userResourceAccessRules?: ContextResourceAccessRules
}) => Promise<Stream>
9 changes: 6 additions & 3 deletions packages/server/modules/core/graph/resolvers/commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ const {
} = require('@/modules/core/repositories/branches')
const {
addCommitDeletedActivity,
addCommitUpdatedActivity,
addCommitMovedActivity,
addCommitCreatedActivityFactory
addCommitCreatedActivityFactory,
addCommitUpdatedActivityFactory
} = require('@/modules/activitystream/services/commitActivity')
const { VersionsEmitter } = require('@/modules/core/events/versionsEmitter')
const { getObjectFactory } = require('@/modules/core/repositories/objects')
Expand Down Expand Up @@ -124,7 +124,10 @@ const updateCommitAndNotify = updateCommitAndNotifyFactory({
getCommitBranch: getCommitBranchFactory({ db }),
switchCommitBranch: switchCommitBranchFactory({ db }),
updateCommit: updateCommitFactory({ db }),
addCommitUpdatedActivity,
addCommitUpdatedActivity: addCommitUpdatedActivityFactory({
saveActivity: saveActivityFactory({ db }),
publish
}),
markCommitStreamUpdated,
markCommitBranchUpdated: markCommitBranchUpdatedFactory({ db })
})
Expand Down
15 changes: 12 additions & 3 deletions packages/server/modules/core/graph/resolvers/streams.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
getStreamUsers,
favoriteStream,
getActiveUserStreamFavoriteDate,
getStreamFavoritesCount,
getOwnedFavoritesCount
Expand Down Expand Up @@ -35,7 +34,9 @@ import {
legacyGetStreamsFactory,
getFavoritedStreamsCountFactory,
getFavoritedStreamsPageFactory,
getStreamCollaboratorsFactory
getStreamCollaboratorsFactory,
canUserFavoriteStreamFactory,
setStreamFavoritedFactory
} from '@/modules/core/repositories/streams'
import {
createStreamReturnRecordFactory,
Expand Down Expand Up @@ -87,7 +88,10 @@ import {
validateStreamAccessFactory
} from '@/modules/core/services/streams/access'
import { getDiscoverableStreamsFactory } from '@/modules/core/services/streams/discoverableStreams'
import { getFavoriteStreamsCollectionFactory } from '@/modules/core/services/streams/favorite'
import {
favoriteStreamFactory,
getFavoriteStreamsCollectionFactory
} from '@/modules/core/services/streams/favorite'

const getFavoriteStreamsCollection = getFavoriteStreamsCollectionFactory({
getFavoritedStreamsCount: getFavoritedStreamsCountFactory({ db }),
Expand Down Expand Up @@ -173,6 +177,11 @@ const getDiscoverableStreams = getDiscoverableStreamsFactory({
countDiscoverableStreams: countDiscoverableStreamsFactory({ db })
})
const getStreams = legacyGetStreamsFactory({ db })
const favoriteStream = favoriteStreamFactory({
canUserFavoriteStream: canUserFavoriteStreamFactory({ db }),
setStreamFavorited: setStreamFavoritedFactory({ db }),
getStream
})

const getUserStreamsCore = async (
forOtherUser: boolean,
Expand Down
7 changes: 5 additions & 2 deletions packages/server/modules/core/graph/resolvers/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { VersionsEmitter } from '@/modules/core/events/versionsEmitter'
import {
addCommitCreatedActivityFactory,
addCommitMovedActivity,
addCommitUpdatedActivity
addCommitUpdatedActivityFactory
} from '@/modules/activitystream/services/commitActivity'
import { getObjectFactory } from '@/modules/core/repositories/objects'
import { saveActivityFactory } from '@/modules/activitystream/repositories'
Expand Down Expand Up @@ -82,7 +82,10 @@ const updateCommitAndNotify = updateCommitAndNotifyFactory({
getCommitBranch: getCommitBranchFactory({ db }),
switchCommitBranch: switchCommitBranchFactory({ db }),
updateCommit: updateCommitFactory({ db }),
addCommitUpdatedActivity,
addCommitUpdatedActivity: addCommitUpdatedActivityFactory({
saveActivity: saveActivityFactory({ db }),
publish
}),
markCommitStreamUpdated,
markCommitBranchUpdated: markCommitBranchUpdatedFactory({ db })
})
Expand Down
Loading

0 comments on commit b422fc3

Please sign in to comment.