Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion models/server-activity/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ function getActivityControl (client: MigrationClient): ActivityControl {
modelDb: client.model,
hierarchy: client.hierarchy,
findAll: async (_class, query, options) =>
toFindResult(await client.find(client.hierarchy.getDomain(_class), query, options))
toFindResult(await client.find(client.hierarchy.getDomain(_class), query, options)),
storageAdapter: client.storageAdapter,
workspace: client.workspaceId
}
}

Expand Down
2 changes: 1 addition & 1 deletion models/view/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ export function createModel (builder: Builder): void {
})

builder.mixin(core.class.TypeCollaborativeDoc, core.class.Class, view.mixin.ActivityAttributePresenter, {
presenter: view.component.CollaborativeDocActivityPresenter
presenter: view.component.MarkupDiffPresenter
})

builder.mixin(core.class.TypeCollaborativeDocVersion, core.class.Class, view.mixin.InlineAttributEditor, {
Expand Down
1 change: 0 additions & 1 deletion models/view/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export default mergeIds(viewId, view, {
HTMLEditor: '' as AnyComponent,
CollaborativeHTMLEditor: '' as AnyComponent,
CollaborativeDocEditor: '' as AnyComponent,
CollaborativeDocActivityPresenter: '' as AnyComponent,
MarkupEditor: '' as AnyComponent,
MarkupEditorPopup: '' as AnyComponent,
ListView: '' as AnyComponent,
Expand Down
38 changes: 28 additions & 10 deletions packages/text/src/ydoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,30 @@
// limitations under the License.
//

import { Markup } from '@hcengineering/core'
import { Extensions, getSchema } from '@tiptap/core'
import { Node, Schema } from 'prosemirror-model'
import { prosemirrorJSONToYDoc, yDocToProsemirrorJSON } from 'y-prosemirror'
import { Doc, applyUpdate, encodeStateAsUpdate } from 'yjs'
import { prosemirrorJSONToYDoc, prosemirrorToYDoc, yDocToProsemirrorJSON } from 'y-prosemirror'
import { Doc as YDoc, applyUpdate, encodeStateAsUpdate } from 'yjs'
import { defaultExtensions } from './extensions'
import { MarkupNode } from './markup/model'
import { jsonToMarkup, markupToPmNode } from './markup/utils'

/**
* @public
*/
export function markupToYDoc (markup: Markup, field: string): YDoc {
const node = markupToPmNode(markup)
return prosemirrorToYDoc(node, field)
}

/**
* @public
*/
export function yDocToMarkup (ydoc: YDoc, field: string): Markup {
const json = yDocToProsemirrorJSON(ydoc, field)
return jsonToMarkup(json as MarkupNode)
}

/**
* Get ProseMirror node from Y.Doc content
Expand All @@ -31,7 +49,7 @@ export function yDocContentToNode (
schema?: Schema,
extensions?: Extensions
): Node {
const ydoc = new Doc()
const ydoc = new YDoc()
const uint8arr = new Uint8Array(content)
applyUpdate(ydoc, uint8arr)

Expand All @@ -43,7 +61,7 @@ export function yDocContentToNode (
*
* @public
*/
export function yDocToNode (ydoc: Doc, field?: string, schema?: Schema, extensions?: Extensions): Node {
export function yDocToNode (ydoc: YDoc, field?: string, schema?: Schema, extensions?: Extensions): Node {
schema ??= getSchema(extensions ?? defaultExtensions)

try {
Expand All @@ -66,7 +84,7 @@ export function yDocContentToNodes (content: ArrayBuffer, schema?: Schema, exten
const nodes: Node[] = []

try {
const ydoc = new Doc()
const ydoc = new YDoc()
const uint8arr = new Uint8Array(content)
applyUpdate(ydoc, uint8arr)

Expand All @@ -93,12 +111,12 @@ export function updateYDocContent (
updateFn: (body: Record<string, any>) => Record<string, any>,
schema?: Schema,
extensions?: Extensions
): Doc | undefined {
): YDoc | undefined {
schema ??= getSchema(extensions ?? defaultExtensions)

try {
const ydoc = new Doc()
const res = new Doc({ gc: false })
const ydoc = new YDoc()
const res = new YDoc({ gc: false })
const uint8arr = new Uint8Array(content)
applyUpdate(ydoc, uint8arr)

Expand All @@ -121,10 +139,10 @@ export function updateYDocContent (
*
* @public
*/
export function YDocFromContent (content: MarkupNode, field: string, schema?: Schema, extensions?: Extensions): Doc {
export function YDocFromContent (content: MarkupNode, field: string, schema?: Schema, extensions?: Extensions): YDoc {
schema ??= getSchema(extensions ?? defaultExtensions)

const res = new Doc({ gc: false })
const res = new YDoc({ gc: false })

const yDoc = prosemirrorJSONToYDoc(schema, content, field)
const update = encodeStateAsUpdate(yDoc)
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions plugins/view-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import ClassPresenter from './components/ClassPresenter.svelte'
import ClassRefPresenter from './components/ClassRefPresenter.svelte'
import CollaborativeDocEditor from './components/CollaborativeDocEditor.svelte'
import CollaborativeHTMLEditor from './components/CollaborativeHTMLEditor.svelte'
import CollaborativeDocActivityPresenter from './components/CollaborativeDocActivityPresenter.svelte'
import ColorsPopup from './components/ColorsPopup.svelte'
import DateEditor from './components/DateEditor.svelte'
import DatePresenter from './components/DatePresenter.svelte'
Expand Down Expand Up @@ -277,7 +276,6 @@ export default async (): Promise<Resources> => ({
HTMLEditor,
CollaborativeDocEditor,
CollaborativeHTMLEditor,
CollaborativeDocActivityPresenter,
ListView,
GrowPresenter,
DividerPresenter,
Expand Down
4 changes: 2 additions & 2 deletions server-plugins/activity-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ function getDocUpdateMessageTx (
}

export async function pushDocUpdateMessages (
ctx: MeasureContext | undefined,
ctx: MeasureContext,
control: ActivityControl,
res: TxCollectionCUD<Doc, DocUpdateMessage>[],
object: Doc | undefined,
Expand Down Expand Up @@ -231,7 +231,7 @@ export async function pushDocUpdateMessages (
: undefined
}

const attributesUpdates = await getTxAttributesUpdates(control, originTx, tx, object, objectCache, controlRules)
const attributesUpdates = await getTxAttributesUpdates(ctx, control, originTx, tx, object, objectCache, controlRules)

for (const attributeUpdates of attributesUpdates) {
res.push(
Expand Down
36 changes: 34 additions & 2 deletions server-plugins/activity-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import {
AttachedDoc,
type Attribute,
Class,
CollaborativeDoc,
collaborativeDocFromLastVersion,
Collection,
Doc,
Hierarchy,
Markup,
MeasureContext,
Mixin,
Ref,
RefTo,
Expand All @@ -14,15 +18,18 @@ import {
TxCUD,
TxMixin,
TxProcessor,
TxUpdateDoc
TxUpdateDoc,
WorkspaceId
} from '@hcengineering/core'
import core from '@hcengineering/core/src/component'
import { ActivityMessageControl, DocAttributeUpdates, DocUpdateAction } from '@hcengineering/activity'
import { ActivityControl, DocObjectCache, getAllObjectTransactions } from '@hcengineering/server-activity'
import { getDocCollaborators } from '@hcengineering/server-notification-resources'
import notification from '@hcengineering/notification'
import { TriggerControl } from '@hcengineering/server-core'
import { StorageAdapter, TriggerControl } from '@hcengineering/server-core'
import { translate } from '@hcengineering/platform'
import { loadCollaborativeDoc } from '@hcengineering/collaboration'
import { EmptyMarkup, yDocToMarkup } from '@hcengineering/text'

function getAvailableAttributesKeys (tx: TxCUD<Doc>, hierarchy: Hierarchy): string[] {
if (hierarchy.isDerived(tx._class, core.class.TxUpdateDoc)) {
Expand Down Expand Up @@ -226,6 +233,7 @@ export async function getAttributeDiff (
}

export async function getTxAttributesUpdates (
ctx: MeasureContext,
control: ActivityControl,
originTx: TxCUD<Doc>,
tx: TxCUD<Doc>,
Expand Down Expand Up @@ -296,6 +304,7 @@ export async function getTxAttributesUpdates (
if (
hierarchy.isDerived(attrClass, core.class.TypeMarkup) ||
hierarchy.isDerived(attrClass, core.class.TypeCollaborativeMarkup) ||
hierarchy.isDerived(attrClass, core.class.TypeCollaborativeDoc) ||
mixin === notification.mixin.Collaborators
) {
if (docDiff === undefined) {
Expand Down Expand Up @@ -323,6 +332,16 @@ export async function getTxAttributesUpdates (
}
}

// we don't want to show collaborative documents in activity
// instead we show their content as Markup
// TODO this should be generalized via activity extension
const attrType = mixin !== undefined ? hierarchy.findAttribute(mixin, key) : clazz
if (attrType?.type?._class === core.class.TypeCollaborativeDoc) {
attrClass = isMixin ? attrClass : core.class.TypeMarkup
attrValue = await getMarkup(ctx, control.storageAdapter, control.workspace, attrValue, key)
prevValue = await getMarkup(ctx, control.storageAdapter, control.workspace, prevValue, key)
}

let setAttr = []

if (Array.isArray(attrValue)) {
Expand Down Expand Up @@ -406,3 +425,16 @@ export function getCollectionAttribute (

return undefined
}

async function getMarkup (
ctx: MeasureContext,
storage: StorageAdapter,
workspace: WorkspaceId,
value: CollaborativeDoc,
field: string
): Promise<Markup> {
if (value === undefined) return EmptyMarkup
value = collaborativeDocFromLastVersion(value)
const ydoc = await loadCollaborativeDoc(storage, workspace, value, ctx)
return ydoc !== undefined ? yDocToMarkup(ydoc, field) : EmptyMarkup
}
5 changes: 4 additions & 1 deletion server-plugins/activity/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Doc, Hierarchy, ModelDb, Ref, Storage, TxCUD, TxFactory } from '@hcengineering/core'
import { Doc, Hierarchy, ModelDb, Ref, Storage, TxCUD, TxFactory, WorkspaceId } from '@hcengineering/core'
import { StorageAdapter } from '@hcengineering/server-core'

export interface DocObjectCache {
docs: Map<Ref<Doc>, Doc | null>
Expand All @@ -10,4 +11,6 @@ export interface ActivityControl {
hierarchy: Hierarchy
txFactory: TxFactory
modelDb: ModelDb
storageAdapter: StorageAdapter
workspace: WorkspaceId
}
2 changes: 1 addition & 1 deletion server-plugins/request-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async function getRequestNotificationTx (tx: TxCollectionCUD<Doc, Request>, cont
if (doc === undefined) return []

const res: Tx[] = []
const messagesTxes = await pushDocUpdateMessages(undefined, control, [], doc, tx)
const messagesTxes = await pushDocUpdateMessages(control.ctx, control, [], doc, tx)

if (messagesTxes.length === 0) return []

Expand Down
1 change: 0 additions & 1 deletion server/collaboration/src/utils/collaborative-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export async function loadCollaborativeDoc (
for (const source of sources) {
const { documentId, versionId } = collaborativeDocParse(source)

ctx.info('loading collaborative document', { source })
const ydoc = await loadCollaborativeDocVersion(ctx, storageAdapter, workspace, documentId, versionId)

if (ydoc !== undefined) {
Expand Down