From 7da454355f1d1bfb59107d5e0584d9e6e8bdcee2 Mon Sep 17 00:00:00 2001 From: Kristina Date: Wed, 1 Nov 2023 17:56:25 +0400 Subject: [PATCH] UBERF-18: add reactions for comments (#3899) Signed-off-by: Kristina Fefelova --- models/activity/src/index.ts | 21 ++++++- models/chunter/src/index.ts | 26 ++++++++ models/chunter/src/plugin.ts | 9 ++- models/contact/src/index.ts | 24 +++++++ models/contact/src/plugin.ts | 5 +- models/inventory/package.json | 4 +- models/inventory/src/index.ts | 26 ++++++++ models/inventory/src/plugin.ts | 5 ++ models/lead/package.json | 1 + models/lead/src/index.ts | 13 ++++ models/lead/src/plugin.ts | 4 +- models/recruit/package.json | 1 + models/recruit/src/index.ts | 37 +++++++++++ models/recruit/src/plugin.ts | 6 +- models/tracker/src/index.ts | 49 +++++++++++++++ models/tracker/src/plugin.ts | 9 ++- plugins/activity-resources/package.json | 1 - .../src/components/Activity.svelte | 18 ++++-- .../ActivityExtensionComponent.svelte | 29 +++++++++ .../src/components/TxView.svelte | 62 ++++++++++++------- plugins/activity-resources/src/utils.ts | 6 +- plugins/activity/src/index.ts | 22 ++++++- .../src/components/CommentReactions.svelte | 47 ++++++++++++++ .../src/components/Message.svelte | 56 ++++------------- .../src/components/Reactions.svelte | 8 +-- .../src/components/ReactionsAction.svelte | 48 ++++++++++++++ plugins/chunter-resources/src/index.ts | 8 ++- plugins/chunter-resources/src/utils.ts | 39 +++++++++++- plugins/chunter/src/index.ts | 8 ++- 29 files changed, 495 insertions(+), 97 deletions(-) create mode 100644 plugins/activity-resources/src/components/ActivityExtensionComponent.svelte create mode 100644 plugins/chunter-resources/src/components/CommentReactions.svelte create mode 100644 plugins/chunter-resources/src/components/ReactionsAction.svelte diff --git a/models/activity/src/index.ts b/models/activity/src/index.ts index 4c6f701989..466171b59b 100644 --- a/models/activity/src/index.ts +++ b/models/activity/src/index.ts @@ -13,14 +13,22 @@ // limitations under the License. // -import type { ActivityFilter, DisplayTx, ExtraActivityComponent, TxViewlet } from '@hcengineering/activity' -import activity from './plugin' +import type { + ActivityExtension, + ActivityExtensionKind, + ActivityFilter, + DisplayTx, + ExtraActivityComponent, + TxViewlet +} from '@hcengineering/activity' import core, { Class, Doc, DocumentQuery, DOMAIN_MODEL, Ref, Tx } from '@hcengineering/core' import { Builder, Mixin, Model } from '@hcengineering/model' import { TClass, TDoc } from '@hcengineering/model-core' import type { Asset, IntlString, Resource } from '@hcengineering/platform' import { AnyComponent } from '@hcengineering/ui' +import activity from './plugin' + export { activityId } from '@hcengineering/activity' @Model(activity.class.TxViewlet, core.class.Doc, DOMAIN_MODEL) @@ -44,13 +52,20 @@ export class TActivityFilter extends TDoc implements ActivityFilter { filter!: Resource<(tx: DisplayTx, _class?: Ref) => boolean> } +@Model(activity.class.ActivityExtension, core.class.Doc, DOMAIN_MODEL) +export class TActivityExtension extends TDoc implements ActivityExtension { + ofClass!: Ref> + components?: Partial> + mentionClass?: Ref> +} + @Mixin(activity.mixin.ExtraActivityComponent, core.class.Class) export class TExtraActivityComponent extends TClass implements ExtraActivityComponent { component!: AnyComponent } export function createModel (builder: Builder): void { - builder.createModel(TTxViewlet, TActivityFilter, TExtraActivityComponent) + builder.createModel(TTxViewlet, TActivityFilter, TExtraActivityComponent, TActivityExtension) builder.createDoc(activity.class.ActivityFilter, core.space.Model, { label: activity.string.Attributes, diff --git a/models/chunter/src/index.ts b/models/chunter/src/index.ts index dbd18990e4..3b816ff574 100644 --- a/models/chunter/src/index.ts +++ b/models/chunter/src/index.ts @@ -150,6 +150,9 @@ export class TComment extends TAttachedDoc implements Comment { @Prop(Collection(attachment.class.Attachment), attachment.string.Attachments, { shortLabel: attachment.string.Files }) attachments?: number + + @Prop(Collection(chunter.class.Reaction), chunter.string.Reactions) + reactions?: number } @Model(chunter.class.Backlink, chunter.class.Comment) @@ -737,6 +740,29 @@ export function createModel (builder: Builder, options = { addApplication: true chunter.ids.ChannelNotification ) + builder.createDoc( + activity.class.ActivityExtension, + core.space.Model, + { + ofClass: chunter.class.Comment, + components: { + footer: chunter.component.CommentReactions, + action: chunter.component.ReactionsAction + } + }, + chunter.ids.ActivityExtension + ) + + builder.createDoc( + activity.class.ActivityExtension, + core.space.Model, + { + ofClass: chunter.class.Backlink, + isMention: true + }, + chunter.ids.BackLinkActivityExtension + ) + builder.createDoc( notification.class.NotificationType, core.space.Model, diff --git a/models/chunter/src/plugin.ts b/models/chunter/src/plugin.ts index 85ae5f03da..65558f09f8 100644 --- a/models/chunter/src/plugin.ts +++ b/models/chunter/src/plugin.ts @@ -22,6 +22,7 @@ import type { IntlString, Resource } from '@hcengineering/platform' import { mergeIds } from '@hcengineering/platform' import type { AnyComponent, Location } from '@hcengineering/ui' import type { Action, ActionCategory, ViewAction, ViewletDescriptor } from '@hcengineering/view' +import { ActivityExtension } from '@hcengineering/activity' export default mergeIds(chunterId, chunter, { component: { @@ -32,7 +33,9 @@ export default mergeIds(chunterId, chunter, { DmPresenter: '' as AnyComponent, Threads: '' as AnyComponent, SavedMessages: '' as AnyComponent, - ChunterBrowser: '' as AnyComponent + ChunterBrowser: '' as AnyComponent, + CommentReactions: '' as AnyComponent, + ReactionsAction: '' as AnyComponent }, action: { MarkCommentUnread: '' as Ref, @@ -89,7 +92,9 @@ export default mergeIds(chunterId, chunter, { TxCommentRemove: '' as Ref, TxBacklinkRemove: '' as Ref, TxMessageCreate: '' as Ref, - ChunterNotificationGroup: '' as Ref + ChunterNotificationGroup: '' as Ref, + ActivityExtension: '' as Ref, + BackLinkActivityExtension: '' as Ref }, activity: { TxCommentCreate: '' as AnyComponent, diff --git a/models/contact/src/index.ts b/models/contact/src/index.ts index 23a9557d09..fc94f2ed7e 100644 --- a/models/contact/src/index.ts +++ b/models/contact/src/index.ts @@ -916,6 +916,30 @@ export function createModel (builder: Builder): void { contact.templateField.ContactLastName ) + builder.createDoc( + activity.class.ActivityExtension, + core.space.Model, + { + ofClass: contact.class.Person, + components: { + input: chunter.component.CommentInput + } + }, + contact.ids.PersonActivityExtension + ) + + builder.createDoc( + activity.class.ActivityExtension, + core.space.Model, + { + ofClass: contact.class.Organization, + components: { + input: chunter.component.CommentInput + } + }, + contact.ids.OrganizationActivityExtension + ) + builder.mixin(contact.class.Contact, core.class.Class, activity.mixin.ExtraActivityComponent, { component: contact.component.ActivityChannelMessage }) diff --git a/models/contact/src/plugin.ts b/models/contact/src/plugin.ts index 446ac50610..d6347ee47b 100644 --- a/models/contact/src/plugin.ts +++ b/models/contact/src/plugin.ts @@ -24,6 +24,7 @@ import { IntlString, mergeIds, Resource } from '@hcengineering/platform' import { TemplateFieldFunc } from '@hcengineering/templates' import type { AnyComponent } from '@hcengineering/ui' import { Action, ActionCategory, ViewAction } from '@hcengineering/view' +import { ActivityExtension } from '@hcengineering/activity' export default mergeIds(contactId, contact, { activity: { @@ -112,7 +113,9 @@ export default mergeIds(contactId, contact, { }, ids: { OrganizationNotificationGroup: '' as Ref, - PersonNotificationGroup: '' as Ref + PersonNotificationGroup: '' as Ref, + PersonActivityExtension: '' as Ref, + OrganizationActivityExtension: '' as Ref }, action: { KickEmployee: '' as Ref, diff --git a/models/inventory/package.json b/models/inventory/package.json index 5a6d666b8c..0c1a6e1812 100644 --- a/models/inventory/package.json +++ b/models/inventory/package.json @@ -24,6 +24,7 @@ "prettier": "^2.7.1" }, "dependencies": { + "@hcengineering/activity": "^0.6.0", "@hcengineering/core": "^0.6.27", "@hcengineering/model": "^0.6.6", "@hcengineering/model-workbench": "^0.6.1", @@ -37,6 +38,7 @@ "@hcengineering/view": "^0.6.8", "@hcengineering/setting": "^0.6.10", "@hcengineering/workbench": "^0.6.8", - "@hcengineering/model-view": "^0.6.0" + "@hcengineering/model-view": "^0.6.0", + "@hcengineering/model-chunter": "^0.6.0" } } diff --git a/models/inventory/src/index.ts b/models/inventory/src/index.ts index 2889c0ead7..bec5f23cdc 100644 --- a/models/inventory/src/index.ts +++ b/models/inventory/src/index.ts @@ -14,6 +14,7 @@ // import { Domain, IndexKind, Ref } from '@hcengineering/core' +import activity from '@hcengineering/activity' import { Category, Product, Variant, inventoryId } from '@hcengineering/inventory' import { Builder, Collection, Index, Model, Prop, TypeRef, TypeString, UX } from '@hcengineering/model' import attachment from '@hcengineering/model-attachment' @@ -22,6 +23,7 @@ import { createAction } from '@hcengineering/model-view' import workbench from '@hcengineering/model-workbench' import setting from '@hcengineering/setting' import view, { Viewlet } from '@hcengineering/view' +import chunter from '@hcengineering/model-chunter' import inventory from './plugin' export { inventoryId } from '@hcengineering/inventory' @@ -162,6 +164,30 @@ export function createModel (builder: Builder): void { inventory.category.Inventory ) + builder.createDoc( + activity.class.ActivityExtension, + core.space.Model, + { + ofClass: inventory.class.Product, + components: { + input: chunter.component.CommentInput + } + }, + inventory.ids.ProductActivityExtension + ) + + builder.createDoc( + activity.class.ActivityExtension, + core.space.Model, + { + ofClass: inventory.class.Category, + components: { + input: chunter.component.CommentInput + } + }, + inventory.ids.CategoryActivityExtension + ) + createAction(builder, { label: inventory.string.CreateSubcategory, icon: inventory.icon.Categories, diff --git a/models/inventory/src/plugin.ts b/models/inventory/src/plugin.ts index ce3690a22f..79f792e77c 100644 --- a/models/inventory/src/plugin.ts +++ b/models/inventory/src/plugin.ts @@ -20,6 +20,7 @@ import inventory from '@hcengineering/inventory-resources/src/plugin' import { IntlString, mergeIds } from '@hcengineering/platform' import type { AnyComponent } from '@hcengineering/ui' import { Action, ActionCategory, ViewAction, Viewlet } from '@hcengineering/view' +import { ActivityExtension } from '@hcengineering/activity' export default mergeIds(inventoryId, inventory, { action: { @@ -47,5 +48,9 @@ export default mergeIds(inventoryId, inventory, { string: { ConfigLabel: '' as IntlString, ConfigDescription: '' as IntlString + }, + ids: { + ProductActivityExtension: '' as Ref, + CategoryActivityExtension: '' as Ref } }) diff --git a/models/lead/package.json b/models/lead/package.json index e1ade6117e..0fe21b1a75 100644 --- a/models/lead/package.json +++ b/models/lead/package.json @@ -24,6 +24,7 @@ "prettier": "^2.7.1" }, "dependencies": { + "@hcengineering/activity": "^0.6.0", "@hcengineering/core": "^0.6.27", "@hcengineering/model": "^0.6.6", "@hcengineering/ui": "^0.6.10", diff --git a/models/lead/src/index.ts b/models/lead/src/index.ts index e6b0363fe5..b3726a0b7f 100644 --- a/models/lead/src/index.ts +++ b/models/lead/src/index.ts @@ -43,6 +43,7 @@ import workbench from '@hcengineering/model-workbench' import notification from '@hcengineering/notification' import setting from '@hcengineering/setting' import { ViewOptionsModel } from '@hcengineering/view' +import activity from '@hcengineering/activity' import lead from './plugin' export { leadId } from '@hcengineering/lead' @@ -509,6 +510,18 @@ export function createModel (builder: Builder): void { lead.viewlet.DashboardLead ) + builder.createDoc( + activity.class.ActivityExtension, + core.space.Model, + { + ofClass: lead.class.Lead, + components: { + input: chunter.component.CommentInput + } + }, + lead.ids.LeadActivityExtension + ) + builder.mixin(lead.class.Lead, core.class.Class, task.mixin.KanbanCard, { card: lead.component.KanbanCard }) diff --git a/models/lead/src/plugin.ts b/models/lead/src/plugin.ts index f36ef2d24f..9dc04bad04 100644 --- a/models/lead/src/plugin.ts +++ b/models/lead/src/plugin.ts @@ -23,6 +23,7 @@ import { mergeIds } from '@hcengineering/platform' import { ProjectType } from '@hcengineering/task' import type { AnyComponent } from '@hcengineering/ui' import { Action, ActionCategory, Viewlet } from '@hcengineering/view' +import { ActivityExtension } from '@hcengineering/activity' export default mergeIds(leadId, lead, { string: { @@ -69,6 +70,7 @@ export default mergeIds(leadId, lead, { CustomerNotificationGroup: '' as Ref, FunnelNotificationGroup: '' as Ref, LeadCreateNotification: '' as Ref, - AssigneeNotification: '' as Ref + AssigneeNotification: '' as Ref, + LeadActivityExtension: '' as Ref } }) diff --git a/models/recruit/package.json b/models/recruit/package.json index a1e6742397..8fad235822 100644 --- a/models/recruit/package.json +++ b/models/recruit/package.json @@ -24,6 +24,7 @@ "prettier": "^2.7.1" }, "dependencies": { + "@hcengineering/activity": "^0.6.0", "@hcengineering/core": "^0.6.27", "@hcengineering/model": "^0.6.6", "@hcengineering/ui": "^0.6.10", diff --git a/models/recruit/src/index.ts b/models/recruit/src/index.ts index 9065695b2d..4a4fa156a7 100644 --- a/models/recruit/src/index.ts +++ b/models/recruit/src/index.ts @@ -56,6 +56,7 @@ import { } from '@hcengineering/recruit' import setting from '@hcengineering/setting' import { KeyBinding, ViewOptionModel, ViewOptionsModel } from '@hcengineering/view' +import activity from '@hcengineering/activity' import recruit from './plugin' import { createReviewModel, reviewTableConfig, reviewTableOptions } from './review' import { TOpinion, TReview } from './review-model' @@ -1557,6 +1558,42 @@ export function createModel (builder: Builder): void { recruit.filter.None ) + builder.createDoc( + activity.class.ActivityExtension, + core.space.Model, + { + ofClass: recruit.class.Vacancy, + components: { + input: chunter.component.CommentInput + } + }, + recruit.ids.VacancyActivityExtension + ) + + builder.createDoc( + activity.class.ActivityExtension, + core.space.Model, + { + ofClass: recruit.class.Applicant, + components: { + input: chunter.component.CommentInput + } + }, + recruit.ids.ApplicantActivityExtension + ) + + builder.createDoc( + activity.class.ActivityExtension, + core.space.Model, + { + ofClass: recruit.class.Review, + components: { + input: chunter.component.CommentInput + } + }, + recruit.ids.ReviewActivityExtension + ) + // Allow to use fuzzy search for mixins builder.mixin(recruit.class.Vacancy, core.class.Class, core.mixin.FullTextSearchContext, { fullTextSummary: true, diff --git a/models/recruit/src/plugin.ts b/models/recruit/src/plugin.ts index a95141a514..d0f81f159a 100644 --- a/models/recruit/src/plugin.ts +++ b/models/recruit/src/plugin.ts @@ -22,6 +22,7 @@ import recruit from '@hcengineering/recruit-resources/src/plugin' import { ProjectType } from '@hcengineering/task' import type { AnyComponent, Location } from '@hcengineering/ui' import type { Action, ActionCategory, ViewAction, ViewQueryAction, Viewlet } from '@hcengineering/view' +import { ActivityExtension } from '@hcengineering/activity' export default mergeIds(recruitId, recruit, { action: { @@ -82,7 +83,10 @@ export default mergeIds(recruitId, recruit, { ApplicationNotificationGroup: '' as Ref, AssigneeNotification: '' as Ref, ApplicationCreateNotification: '' as Ref, - ReviewCreateNotification: '' as Ref + ReviewCreateNotification: '' as Ref, + VacancyActivityExtension: '' as Ref, + ApplicantActivityExtension: '' as Ref, + ReviewActivityExtension: '' as Ref }, component: { CreateApplication: '' as AnyComponent, diff --git a/models/tracker/src/index.ts b/models/tracker/src/index.ts index f78657c66a..916d63fe21 100644 --- a/models/tracker/src/index.ts +++ b/models/tracker/src/index.ts @@ -18,6 +18,7 @@ import { Builder } from '@hcengineering/model' import core from '@hcengineering/model-core' import task from '@hcengineering/model-task' import view from '@hcengineering/model-view' +import chunter from '@hcengineering/model-chunter' import workbench from '@hcengineering/model-workbench' import notification from '@hcengineering/notification' import setting from '@hcengineering/setting' @@ -521,6 +522,54 @@ export function createModel (builder: Builder): void { order: 4000 }) + builder.createDoc( + activity.class.ActivityExtension, + core.space.Model, + { + ofClass: tracker.class.Issue, + components: { + input: chunter.component.CommentInput + } + }, + tracker.ids.IssueActivityExtension + ) + + builder.createDoc( + activity.class.ActivityExtension, + core.space.Model, + { + ofClass: tracker.class.IssueTemplate, + components: { + input: chunter.component.CommentInput + } + }, + tracker.ids.IssueTemplateActivityExtension + ) + + builder.createDoc( + activity.class.ActivityExtension, + core.space.Model, + { + ofClass: tracker.class.Component, + components: { + input: chunter.component.CommentInput + } + }, + tracker.ids.ComponentActivityExtension + ) + + builder.createDoc( + activity.class.ActivityExtension, + core.space.Model, + { + ofClass: tracker.class.Milestone, + components: { + input: chunter.component.CommentInput + } + }, + tracker.ids.MilestoneActivityExtension + ) + builder.createDoc( task.class.ProjectTypeCategory, core.space.Model, diff --git a/models/tracker/src/plugin.ts b/models/tracker/src/plugin.ts index f74f0e673c..5a0514327e 100644 --- a/models/tracker/src/plugin.ts +++ b/models/tracker/src/plugin.ts @@ -13,11 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. // - -import { TxViewlet } from '@hcengineering/activity' import { Doc, Ref } from '@hcengineering/core' import { ObjectSearchCategory, ObjectSearchFactory } from '@hcengineering/model-presentation' -import { NotificationGroup, NotificationType } from '@hcengineering/notification' import { IntlString, Resource, mergeIds } from '@hcengineering/platform' import { ProjectType } from '@hcengineering/task' import { trackerId } from '@hcengineering/tracker' @@ -25,6 +22,8 @@ import tracker from '@hcengineering/tracker-resources/src/plugin' import type { AnyComponent } from '@hcengineering/ui/src/types' import { Action, ViewAction, Viewlet } from '@hcengineering/view' import { Application } from '@hcengineering/workbench' +import { ActivityExtension, TxViewlet } from '@hcengineering/activity' +import { NotificationGroup, NotificationType } from '@hcengineering/notification' export default mergeIds(trackerId, tracker, { string: { @@ -75,6 +74,10 @@ export default mergeIds(trackerId, tracker, { TxIssueCreated: '' as Ref, TrackerNotificationGroup: '' as Ref, AssigneeNotification: '' as Ref, + IssueActivityExtension: '' as Ref, + IssueTemplateActivityExtension: '' as Ref, + ComponentActivityExtension: '' as Ref, + MilestoneActivityExtension: '' as Ref, BaseProjectType: '' as Ref }, completion: { diff --git a/plugins/activity-resources/package.json b/plugins/activity-resources/package.json index 3647edfd0d..182888175d 100644 --- a/plugins/activity-resources/package.json +++ b/plugins/activity-resources/package.json @@ -40,7 +40,6 @@ "@hcengineering/presentation": "^0.6.2", "@hcengineering/activity": "^0.6.0", "svelte": "3.55.1", - "@hcengineering/chunter": "^0.6.11", "@hcengineering/text-editor": "^0.6.0", "@hcengineering/contact": "^0.6.19", "@hcengineering/notification": "^0.6.15", diff --git a/plugins/activity-resources/src/components/Activity.svelte b/plugins/activity-resources/src/components/Activity.svelte index 0b9f361f65..76ea6391d9 100644 --- a/plugins/activity-resources/src/components/Activity.svelte +++ b/plugins/activity-resources/src/components/Activity.svelte @@ -13,17 +13,17 @@ // limitations under the License. --> + +{#each extensions as extension} + {@const component = extension.components?.[kind]} + {#if component} + + {/if} +{/each} diff --git a/plugins/activity-resources/src/components/TxView.svelte b/plugins/activity-resources/src/components/TxView.svelte index d221c62ed9..f14a8f4c38 100644 --- a/plugins/activity-resources/src/components/TxView.svelte +++ b/plugins/activity-resources/src/components/TxView.svelte @@ -14,11 +14,11 @@ // limitations under the License. --> + +{#if reactions.length} + +{/if} diff --git a/plugins/chunter-resources/src/components/Message.svelte b/plugins/chunter-resources/src/components/Message.svelte index 9835d5b5b8..483f082213 100644 --- a/plugins/chunter-resources/src/components/Message.svelte +++ b/plugins/chunter-resources/src/components/Message.svelte @@ -13,6 +13,7 @@ // limitations under the License. --> + + diff --git a/plugins/chunter-resources/src/index.ts b/plugins/chunter-resources/src/index.ts index c947963ee4..de8bffd5af 100644 --- a/plugins/chunter-resources/src/index.ts +++ b/plugins/chunter-resources/src/index.ts @@ -38,6 +38,7 @@ import CommentInput from './components/CommentInput.svelte' import CommentPopup from './components/CommentPopup.svelte' import CommentPresenter from './components/CommentPresenter.svelte' import CommentsPresenter from './components/CommentsPresenter.svelte' +import Reactions from './components/Reactions.svelte' import CommentPanel from './components/CommentPanel.svelte' import ConvertDmToPrivateChannelModal from './components/ConvertDmToPrivateChannel.svelte' import CreateChannel from './components/CreateChannel.svelte' @@ -60,6 +61,8 @@ import TxBacklinkCreate from './components/activity/TxBacklinkCreate.svelte' import TxBacklinkReference from './components/activity/TxBacklinkReference.svelte' import TxCommentCreate from './components/activity/TxCommentCreate.svelte' import TxMessageCreate from './components/activity/TxMessageCreate.svelte' +import ReactionsAction from './components/ReactionsAction.svelte' +import CommentReactions from './components/CommentReactions.svelte' import notification from '@hcengineering/notification' import { writable } from 'svelte/store' @@ -282,6 +285,7 @@ export default async (): Promise => ({ ChannelViewPanel, CommentPresenter, CommentsPresenter, + Reactions, ChannelPresenter, DirectMessagePresenter, MessagePresenter, @@ -296,7 +300,9 @@ export default async (): Promise => ({ Threads, ThreadView, SavedMessages, - CommentPanel + CommentPanel, + ReactionsAction, + CommentReactions }, function: { GetDmName: getDmName, diff --git a/plugins/chunter-resources/src/utils.ts b/plugins/chunter-resources/src/utils.ts index 634ed3448d..250f064333 100644 --- a/plugins/chunter-resources/src/utils.ts +++ b/plugins/chunter-resources/src/utils.ts @@ -1,7 +1,18 @@ -import { chunterId, ChunterMessage, Comment, ThreadMessage } from '@hcengineering/chunter' +import { chunterId, ChunterMessage, Comment, Reaction, ThreadMessage } from '@hcengineering/chunter' import contact, { Employee, PersonAccount, getName } from '@hcengineering/contact' import { employeeByIdStore } from '@hcengineering/contact-resources' -import { Class, Client, Doc, getCurrentAccount, IdMap, Obj, Ref, Space, Timestamp } from '@hcengineering/core' +import { + Class, + Client, + Doc, + getCurrentAccount, + IdMap, + Obj, + Ref, + Space, + Timestamp, + TxOperations +} from '@hcengineering/core' import { Asset } from '@hcengineering/platform' import { getClient } from '@hcengineering/presentation' import { @@ -279,3 +290,27 @@ function parseLinks (nodes: NodeListOf): HTMLLinkElement[] { }) return res } + +export async function updateDocReactions ( + client: TxOperations, + reactions: Reaction[], + object?: Doc, + emoji?: string +): Promise { + if (emoji === undefined || object === undefined) { + return + } + + const currentAccount = getCurrentAccount() + + const reaction = reactions.find((r) => r.emoji === emoji && r.createBy === currentAccount._id) + + if (reaction == null) { + await client.addCollection(chunter.class.Reaction, object.space, object._id, object._class, 'reactions', { + emoji, + createBy: currentAccount._id + }) + } else { + await client.remove(reaction) + } +} diff --git a/plugins/chunter/src/index.ts b/plugins/chunter/src/index.ts index 6139e9e511..e891de3a1c 100644 --- a/plugins/chunter/src/index.ts +++ b/plugins/chunter/src/index.ts @@ -92,8 +92,8 @@ export interface Message extends ChunterMessage { export interface Reaction extends AttachedDoc { emoji: string createBy: Ref - attachedTo: Ref - attachedToClass: Ref> + attachedTo: Ref + attachedToClass: Ref> } /** @@ -102,6 +102,7 @@ export interface Reaction extends AttachedDoc { export interface Comment extends AttachedDoc { message: string attachments?: number + reactions?: number } /** @@ -157,7 +158,8 @@ export default plugin(chunterId, { ChannelView: '' as AnyComponent, ThreadView: '' as AnyComponent, Thread: '' as AnyComponent, - CommentsPresenter: '' as AnyComponent + CommentsPresenter: '' as AnyComponent, + Reactions: '' as AnyComponent }, class: { Message: '' as Ref>,