Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UBERF-4632: refactor activity classes structure #4190

Merged
merged 5 commits into from
Dec 13, 2023
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
152 changes: 123 additions & 29 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dev/generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"dependencies": {
"@hcengineering/account": "^0.6.0",
"@hcengineering/attachment": "^0.6.9",
"@hcengineering/chunter": "^0.6.12",
"@hcengineering/client": "^0.6.14",
"@hcengineering/client-resources": "^0.6.23",
"@hcengineering/contact": "^0.6.20",
Expand All @@ -54,7 +55,6 @@
"@hcengineering/task": "^0.6.13",
"@hcengineering/telegram": "^0.6.14",
"@hcengineering/tracker": "^0.6.13",
"@hcengineering/notification": "^0.6.16",
"@types/pdfkit": "~0.12.3",
"commander": "^8.1.0",
"faker": "~5.5.3",
Expand Down
14 changes: 3 additions & 11 deletions dev/generator/src/comments.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chunter, { ChatMessage } from '@hcengineering/chunter'
import { AttachedData, Class, Doc, generateId, Ref, Space, TxOperations } from '@hcengineering/core'
import notification, { ChatMessage } from '@hcengineering/notification'
import faker from 'faker'

export interface CommentOptions {
Expand All @@ -25,20 +25,12 @@ export async function addComments<T extends Doc> (
const commentData: AttachedData<ChatMessage> = {
message: faker.lorem.paragraphs(options.paragraphMin + faker.datatype.number(options.paragraphMax))
}
await client.addCollection(
notification.class.ChatMessage,
space,
objectId,
_class,
collection,
commentData,
commentId
)
await client.addCollection(chunter.class.ChatMessage, space, objectId, _class, collection, commentData, commentId)

if (faker.datatype.number(100) > options.updateFactor) {
const updateMsg = faker.lorem.paragraphs(options.paragraphMin + faker.datatype.number(options.paragraphMax))

await client.updateCollection(notification.class.ChatMessage, space, commentId, objectId, _class, collection, {
await client.updateCollection(chunter.class.ChatMessage, space, commentId, objectId, _class, collection, {
message: updateMsg
})
}
Expand Down
4 changes: 3 additions & 1 deletion dev/prod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@
"@hcengineering/server-request": "^0.6.0",
"@hcengineering/server-request-resources": "^0.6.0",
"@hcengineering/server-view": "^0.6.0",
"@hcengineering/server-view-resources": "^0.6.0"
"@hcengineering/server-view-resources": "^0.6.0",
"@hcengineering/server-activity": "^0.6.0",
"@hcengineering/server-activity-resources": "^0.6.0"
}
}
4 changes: 3 additions & 1 deletion dev/tool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@elastic/elasticsearch": "^7.14.0",
"@hcengineering/account": "^0.6.0",
"@hcengineering/attachment": "^0.6.9",
"@hcengineering/chunter": "^0.6.12",
"@hcengineering/client": "^0.6.14",
"@hcengineering/client-resources": "^0.6.23",
"@hcengineering/contact": "^0.6.20",
Expand All @@ -64,7 +65,6 @@
"@hcengineering/model-recruit": "^0.6.0",
"@hcengineering/model-telegram": "^0.6.0",
"@hcengineering/mongo": "^0.6.1",
"@hcengineering/notification": "^0.6.16",
"@hcengineering/openai": "^0.6.0",
"@hcengineering/platform": "^0.6.9",
"@hcengineering/recruit": "^0.6.21",
Expand Down Expand Up @@ -107,6 +107,8 @@
"@hcengineering/server-tracker-resources": "^0.6.0",
"@hcengineering/server-view": "^0.6.0",
"@hcengineering/server-view-resources": "^0.6.0",
"@hcengineering/server-activity": "^0.6.0",
"@hcengineering/server-activity-resources": "^0.6.0",
"@hcengineering/setting": "^0.6.11",
"@hcengineering/tags": "^0.6.12",
"@hcengineering/task": "^0.6.13",
Expand Down
2 changes: 2 additions & 0 deletions dev/tool/src/__start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import builder, { migrateOperations, version } from '@hcengineering/model-all'
import { devTool } from '.'

import { addLocation } from '@hcengineering/platform'
import { serverActivityId } from '@hcengineering/server-activity'
import { serverAttachmentId } from '@hcengineering/server-attachment'
import { serverCalendarId } from '@hcengineering/server-calendar'
import { serverChunterId } from '@hcengineering/server-chunter'
Expand All @@ -40,6 +41,7 @@ import { serverTelegramId } from '@hcengineering/server-telegram'
import { serverTrackerId } from '@hcengineering/server-tracker'
import { serverViewId } from '@hcengineering/server-view'

addLocation(serverActivityId, () => import('@hcengineering/server-activity-resources'))
addLocation(serverAttachmentId, () => import('@hcengineering/server-attachment-resources'))
addLocation(serverContactId, () => import('@hcengineering/server-contact-resources'))
addLocation(serverNotificationId, () => import('@hcengineering/server-notification-resources'))
Expand Down
10 changes: 5 additions & 5 deletions dev/tool/src/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ import { connect } from '@hcengineering/server-tool'
import tracker from '@hcengineering/tracker'
import tags, { TagCategory, TagElement, TagReference } from '@hcengineering/tags'
import { MongoClient } from 'mongodb'
import notification, { ChatMessage } from '@hcengineering/notification'
import chunter, { ChatMessage } from '@hcengineering/chunter'

export const DOMAIN_COMMENT = 'comment' as Domain
export const DOMAIN_CHUNTER = 'chunter' as Domain

export async function cleanWorkspace (
mongoUrl: string,
Expand Down Expand Up @@ -322,11 +322,11 @@ export async function fixCommentDoubleIdCreate (workspaceId: WorkspaceId, transa
try {
const commentTxes = await connection.findAll(core.class.TxCollectionCUD, {
'tx._class': core.class.TxCreateDoc,
'tx.objectClass': notification.class.ChatMessage
'tx.objectClass': chunter.class.ChatMessage
})
const commentTxesRemoved = await connection.findAll(core.class.TxCollectionCUD, {
'tx._class': core.class.TxRemoveDoc,
'tx.objectClass': notification.class.ChatMessage
'tx.objectClass': chunter.class.ChatMessage
})
const removed = new Map(commentTxesRemoved.map((it) => [it.tx.objectId, it]))
// Do not checked removed
Expand Down Expand Up @@ -354,7 +354,7 @@ export async function fixCommentDoubleIdCreate (workspaceId: WorkspaceId, transa
doc._id = c.tx.objectId as Ref<ChatMessage>
await connection.upload(DOMAIN_TX, [c])
// Also we need to create snapsot
await connection.upload(DOMAIN_COMMENT, [doc])
await connection.upload(DOMAIN_CHUNTER, [doc])
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions dev/tool/src/mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import { getWorkspaceDB } from '@hcengineering/mongo'
import { connect } from '@hcengineering/server-tool'
import { MongoClient } from 'mongodb'

export const DOMAIN_COMMENT = 'comment' as Domain

interface PropertyInfo {
name: string
cValue: any
Expand Down
3 changes: 2 additions & 1 deletion models/activity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@hcengineering/model": "^0.6.7",
"@hcengineering/model-core": "^0.6.0",
"@hcengineering/platform": "^0.6.9",
"@hcengineering/ui": "^0.6.11"
"@hcengineering/ui": "^0.6.11",
"@hcengineering/model-view": "^0.6.0"
}
}
191 changes: 185 additions & 6 deletions models/activity/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,63 @@
// limitations under the License.
//

import type { TxViewlet } from '@hcengineering/activity'
import core, { DOMAIN_MODEL, type Class, type Doc, type DocumentQuery, type Ref, type Tx } from '@hcengineering/core'
import { Model, type Builder } from '@hcengineering/model'
import { TDoc } from '@hcengineering/model-core'
import type { Asset, IntlString } from '@hcengineering/platform'
import {
type ActivityDoc,
type ActivityExtension,
type ActivityExtensionKind,
type ActivityMessage,
type ActivityMessageExtension,
type ActivityMessageExtensionKind,
type ActivityMessagesFilter,
type DocAttributeUpdates,
type DocUpdateAction,
type DocUpdateMessage,
type DocUpdateMessageViewlet,
type DocUpdateMessageViewletAttributesConfig,
type Reaction,
type TxViewlet
} from '@hcengineering/activity'
import core, {
DOMAIN_MODEL,
type Class,
type Doc,
type DocumentQuery,
type Ref,
type Tx,
IndexKind,
type TxCUD,
type Domain,
type Account
} from '@hcengineering/core'
import {
Model,
type Builder,
Prop,
Index,
TypeRef,
TypeString,
Mixin,
Collection,
TypeBoolean
} from '@hcengineering/model'
import { TAttachedDoc, TClass, TDoc } from '@hcengineering/model-core'
import type { Asset, IntlString, Resource } from '@hcengineering/platform'
import { type AnyComponent } from '@hcengineering/ui/src/types'

import activity from './plugin'
import view from '@hcengineering/model-view'

export { activityOperation } from './migration'
export { activityId } from '@hcengineering/activity'

export const DOMAIN_ACTIVITY = 'activity' as Domain

@Mixin(activity.mixin.ActivityDoc, core.class.Class)
export class TActivityDoc extends TClass implements ActivityDoc {
preposition?: IntlString
ignoreCollections?: string[]
}

@Model(activity.class.TxViewlet, core.class.Doc, DOMAIN_MODEL)
export class TTxViewlet extends TDoc implements TxViewlet {
icon!: Asset
Expand All @@ -39,8 +85,141 @@ export class TTxViewlet extends TDoc implements TxViewlet {
hideOnRemove!: boolean
}

@Model(activity.class.ActivityMessage, core.class.AttachedDoc, DOMAIN_ACTIVITY)
export class TActivityMessage extends TAttachedDoc implements ActivityMessage {
@Prop(TypeBoolean(), activity.string.Pinned)
isPinned?: boolean

@Prop(Collection(activity.class.Reaction), activity.string.Reactions)
reactions?: number
}

@Model(activity.class.DocUpdateMessage, activity.class.ActivityMessage, DOMAIN_ACTIVITY)
export class TDocUpdateMessage extends TActivityMessage implements DocUpdateMessage {
@Prop(TypeRef(core.class.Doc), core.string.Object)
@Index(IndexKind.Indexed)
objectId!: Ref<Doc>

@Prop(TypeRef(core.class.Class), core.string.Class)
@Index(IndexKind.Indexed)
objectClass!: Ref<Class<Doc>>

@Prop(TypeRef(core.class.TxCUD), core.string.Object)
@Index(IndexKind.Indexed)
txId!: Ref<TxCUD<Doc>>

action!: DocUpdateAction
updateCollection?: string
attributeUpdates?: DocAttributeUpdates
}

@Model(activity.class.DocUpdateMessageViewlet, core.class.Doc, DOMAIN_MODEL)
export class TDocUpdateMessageViewlet extends TDoc implements DocUpdateMessageViewlet {
@Prop(TypeRef(core.class.Doc), core.string.Class)
@Index(IndexKind.Indexed)
objectClass!: Ref<Class<Doc>>

@Prop(TypeString(), core.string.String)
@Index(IndexKind.Indexed)
action!: DocUpdateAction

label?: IntlString
labelComponent?: AnyComponent

valueAttr?: string

icon?: Asset
component?: AnyComponent
config?: DocUpdateMessageViewletAttributesConfig
hideIfRemoved?: boolean
onlyWithParent?: boolean
}

@Model(activity.class.ActivityMessageExtension, core.class.Doc, DOMAIN_MODEL)
export class TActivityMessageExtension extends TDoc implements ActivityMessageExtension {
@Prop(TypeRef(activity.class.ActivityMessage), core.string.Class)
@Index(IndexKind.Indexed)
ofMessage!: Ref<Class<ActivityMessage>>

components!: { kind: ActivityMessageExtensionKind, component: AnyComponent }[]
}

@Model(activity.class.ActivityExtension, core.class.Doc, DOMAIN_MODEL)
export class TActivityExtension extends TDoc implements ActivityExtension {
@Prop(TypeRef(core.class.Class), core.string.Class)
@Index(IndexKind.Indexed)
ofClass!: Ref<Class<Doc>>

components!: Record<ActivityExtensionKind, AnyComponent>
}

@Model(activity.class.ActivityMessagesFilter, core.class.Doc, DOMAIN_MODEL)
export class TActivityMessagesFilter extends TDoc implements ActivityMessagesFilter {
label!: IntlString
filter!: Resource<(message: ActivityMessage, _class?: Ref<Doc>) => boolean>
}

@Model(activity.class.Reaction, core.class.AttachedDoc, DOMAIN_ACTIVITY)
export class TReaction extends TAttachedDoc implements Reaction {
@Prop(TypeString(), activity.string.Emoji)
emoji!: string

@Prop(TypeRef(core.class.Account), view.string.Created)
createBy!: Ref<Account>
}
export function createModel (builder: Builder): void {
builder.createModel(TTxViewlet)
builder.createModel(
TTxViewlet,
TActivityDoc,
TActivityMessagesFilter,
TActivityMessageExtension,
TActivityMessage,
TDocUpdateMessage,
TDocUpdateMessageViewlet,
TActivityExtension,
TReaction
)

builder.mixin(activity.class.DocUpdateMessage, core.class.Class, activity.mixin.ActivityDoc, {})

builder.mixin(activity.class.DocUpdateMessage, core.class.Class, view.mixin.ObjectPresenter, {
presenter: activity.component.DocUpdateMessagePresenter
})

builder.createDoc(activity.class.ActivityMessagesFilter, core.space.Model, {
label: activity.string.Attributes,
filter: activity.filter.AttributesFilter
})

builder.createDoc(activity.class.ActivityMessagesFilter, core.space.Model, {
label: activity.string.Pinned,
filter: activity.filter.PinnedFilter
})

builder.createDoc(
activity.class.DocUpdateMessageViewlet,
core.space.Model,
{
objectClass: activity.class.Reaction,
action: 'create',
component: activity.component.ReactionAddedMessage,
label: activity.string.Reacted,
onlyWithParent: true,
hideIfRemoved: true
},
activity.ids.ReactionAddedActivityViewlet
)

builder.createDoc(
activity.class.DocUpdateMessageViewlet,
core.space.Model,
{
objectClass: activity.class.Reaction,
action: 'remove',
hideIfRemoved: true
},
activity.ids.ReactionRemovedActivityViewlet
)
}

export default activity
Loading