From 1371131c4d324f4feb12ce3af2d479b3612caa9a Mon Sep 17 00:00:00 2001 From: budaeva <47611627+budaeva@users.noreply.github.com> Date: Thu, 21 Apr 2022 12:39:49 +0700 Subject: [PATCH] Chunter: saved messages (#1466) Signed-off-by: budaeva --- models/chunter/package.json | 3 +- models/chunter/src/index.ts | 17 ++- models/chunter/src/plugin.ts | 6 +- plugins/chunter-assets/assets/icons.svg | 3 + plugins/chunter-assets/lang/en.json | 7 +- plugins/chunter-assets/lang/ru.json | 7 +- plugins/chunter-assets/src/index.ts | 3 +- plugins/chunter-resources/package.json | 3 +- .../src/components/Channel.svelte | 9 +- .../src/components/ChannelView.svelte | 7 ++ .../components/EditChannelSettingsTab.svelte | 2 +- .../src/components/Message.svelte | 27 +++-- .../src/components/SavedMessages.svelte | 108 ++++++++++++++++++ .../src/components/ThreadView.svelte | 15 ++- plugins/chunter-resources/src/index.ts | 23 +++- plugins/chunter-resources/src/plugin.ts | 6 +- plugins/chunter/package.json | 3 +- plugins/chunter/src/index.ts | 14 ++- 18 files changed, 238 insertions(+), 25 deletions(-) create mode 100644 plugins/chunter-resources/src/components/SavedMessages.svelte diff --git a/models/chunter/package.json b/models/chunter/package.json index 26b2d480fa..4263bec283 100644 --- a/models/chunter/package.json +++ b/models/chunter/package.json @@ -39,6 +39,7 @@ "@anticrm/model-workbench": "~0.6.1", "@anticrm/model-notification": "~0.6.0", "@anticrm/activity": "~0.6.0", - "@anticrm/workbench": "~0.6.1" + "@anticrm/workbench": "~0.6.1", + "@anticrm/model-preference": "~0.6.0" } } diff --git a/models/chunter/src/index.ts b/models/chunter/src/index.ts index 7157dce07c..0bd60779eb 100644 --- a/models/chunter/src/index.ts +++ b/models/chunter/src/index.ts @@ -14,7 +14,7 @@ // import activity from '@anticrm/activity' -import type { Backlink, Channel, ChunterMessage, Comment, Message, ThreadMessage } from '@anticrm/chunter' +import type { Backlink, Channel, ChunterMessage, Comment, Message, SavedMessages, ThreadMessage } from '@anticrm/chunter' import contact, { Employee } from '@anticrm/contact' import type { Account, Class, Doc, Domain, Ref, Space, Timestamp } from '@anticrm/core' import { IndexKind } from '@anticrm/core' @@ -25,6 +25,7 @@ import view from '@anticrm/model-view' import workbench from '@anticrm/model-workbench' import chunter from './plugin' import notification from '@anticrm/model-notification' +import preference, { TPreference } from '@anticrm/model-preference' export const DOMAIN_CHUNTER = 'chunter' as Domain export const DOMAIN_COMMENT = 'comment' as Domain @@ -100,8 +101,14 @@ export class TBacklink extends TComment implements Backlink { backlinkClass!: Ref> } +@Model(chunter.class.SavedMessages, preference.class.Preference) +export class TSavedMessages extends TPreference implements SavedMessages { + @Prop(TypeRef(chunter.class.ChunterMessage), chunter.string.SavedMessages) + attachedTo!: Ref +} + export function createModel (builder: Builder): void { - builder.createModel(TChannel, TMessage, TThreadMessage, TChunterMessage, TComment, TBacklink) + builder.createModel(TChannel, TMessage, TThreadMessage, TChunterMessage, TComment, TBacklink, TSavedMessages) builder.mixin(chunter.class.Channel, core.class.Class, workbench.mixin.SpaceView, { view: { class: chunter.class.Message @@ -239,6 +246,12 @@ export function createModel (builder: Builder): void { icon: chunter.icon.Thread, component: chunter.component.Threads, position: 'top' + }, + { + id: 'savedMessages', + label: chunter.string.SavedMessages, + icon: chunter.icon.Bookmark, + component: chunter.component.SavedMessages } ], spaces: [ diff --git a/models/chunter/src/plugin.ts b/models/chunter/src/plugin.ts index b5e639af07..1407bee569 100644 --- a/models/chunter/src/plugin.ts +++ b/models/chunter/src/plugin.ts @@ -27,7 +27,8 @@ export default mergeIds(chunterId, chunter, { CommentPresenter: '' as AnyComponent, ChannelPresenter: '' as AnyComponent, Threads: '' as AnyComponent, - ThreadView: '' as AnyComponent + ThreadView: '' as AnyComponent, + SavedMessages: '' as AnyComponent }, action: { MarkCommentUnread: '' as Ref, @@ -55,7 +56,8 @@ export default mergeIds(chunterId, chunter, { Edit: '' as IntlString, MarkUnread: '' as IntlString, LastMessage: '' as IntlString, - PinnedMessages: '' as IntlString + PinnedMessages: '' as IntlString, + SavedMessages: '' as IntlString }, viewlet: { Chat: '' as Ref diff --git a/plugins/chunter-assets/assets/icons.svg b/plugins/chunter-assets/assets/icons.svg index 9f7fd3c7d6..bd72866009 100644 --- a/plugins/chunter-assets/assets/icons.svg +++ b/plugins/chunter-assets/assets/icons.svg @@ -11,4 +11,7 @@ + + + diff --git a/plugins/chunter-assets/lang/en.json b/plugins/chunter-assets/lang/en.json index d2394797ec..c3cceb7825 100644 --- a/plugins/chunter-assets/lang/en.json +++ b/plugins/chunter-assets/lang/en.json @@ -44,6 +44,11 @@ "ArchiveChannel": "Archive channel", "UnarchiveChannel": "Unarchive channel", "ArchiveConfirm": "Do you want to archive channel?", - "UnarchiveConfirm": "Do you want to unarchive channel?" + "UnarchiveConfirm": "Do you want to unarchive channel?", + "SavedMessages": "Saved messages", + "AddToSaved": "Add to saved", + "RemoveFromSaved": "Remove from saved", + "EmptySavedHeader": "Add messages to come back to later", + "EmptySavedText": "Tick off your to-dos or save something for another time. Only you can see your saved items, so use them however you like." } } \ No newline at end of file diff --git a/plugins/chunter-assets/lang/ru.json b/plugins/chunter-assets/lang/ru.json index 60d255e184..f369de8009 100644 --- a/plugins/chunter-assets/lang/ru.json +++ b/plugins/chunter-assets/lang/ru.json @@ -43,6 +43,11 @@ "ArchiveChannel": "Архивировать канал", "UnarchiveChannel": "Разархивировать канал", "ArchiveConfirm": "Вы действительно хотите архивировать канал?", - "UnarchiveConfirm": "Вы действительно хотите разархивировать канал?" + "UnarchiveConfirm": "Вы действительно хотите разархивировать канал?", + "SavedMessages": "Сохраненные сообщения", + "AddToSaved": "Добавить в сохраненные", + "RemoveFromSaved": "Удалить из сохраненных", + "EmptySavedHeader": "Добавляйте сообщения и файлы, чтобы вернуться к ним позже", + "EmptySavedText": "Пометьте свои задачи или сохраните что-нибудь на потом. Только вы можете просматривать свои сохраненные объекты, поэтому используйте их как угодно." } } \ No newline at end of file diff --git a/plugins/chunter-assets/src/index.ts b/plugins/chunter-assets/src/index.ts index b222700a30..417e6eae9a 100644 --- a/plugins/chunter-assets/src/index.ts +++ b/plugins/chunter-assets/src/index.ts @@ -21,7 +21,8 @@ loadMetadata(chunter.icon, { Chunter: `${icons}#chunter`, Hashtag: `${icons}#hashtag`, Thread: `${icons}#thread`, - Lock: `${icons}#lock` + Lock: `${icons}#lock`, + Bookmark: `${icons}#bookmark` }) addStringsLoader(chunterId, async (lang: string) => await import(`../lang/${lang}.json`)) diff --git a/plugins/chunter-resources/package.json b/plugins/chunter-resources/package.json index 40888d2da2..0b708c0d0f 100644 --- a/plugins/chunter-resources/package.json +++ b/plugins/chunter-resources/package.json @@ -46,6 +46,7 @@ "@anticrm/attachment-resources": "~0.6.0", "@anticrm/view-resources": "~0.6.0", "@anticrm/view": "~0.6.0", - "@anticrm/workbench": "~0.6.1" + "@anticrm/workbench": "~0.6.1", + "@anticrm/preference": "~0.6.0" } } diff --git a/plugins/chunter-resources/src/components/Channel.svelte b/plugins/chunter-resources/src/components/Channel.svelte index 00cc4dbb24..e0b90cb04c 100644 --- a/plugins/chunter-resources/src/components/Channel.svelte +++ b/plugins/chunter-resources/src/components/Channel.svelte @@ -26,6 +26,7 @@ export let space: Ref | undefined export let pinnedIds: Ref[] + export let savedIds: Ref[] let div: HTMLDivElement | undefined let autoscroll: boolean = false @@ -113,7 +114,13 @@ {#if newMessagesPos === i} {/if} - + {/each} {/if} diff --git a/plugins/chunter-resources/src/components/ChannelView.svelte b/plugins/chunter-resources/src/components/ChannelView.svelte index c9ad9c3948..4663758ea3 100644 --- a/plugins/chunter-resources/src/components/ChannelView.svelte +++ b/plugins/chunter-resources/src/components/ChannelView.svelte @@ -75,6 +75,12 @@ }, { limit: 1 } ) + + const preferenceQuery = createQuery() + let savedIds: Ref[] = [] + preferenceQuery.query(chunter.class.SavedMessages, {}, (res) => { + savedIds = res.map((r) => r.attachedTo) + }) @@ -84,6 +90,7 @@ openThread(e.detail) }} {pinnedIds} + {savedIds} />
diff --git a/plugins/chunter-resources/src/components/EditChannelSettingsTab.svelte b/plugins/chunter-resources/src/components/EditChannelSettingsTab.svelte index 1d83356f42..bef4061319 100644 --- a/plugins/chunter-resources/src/components/EditChannelSettingsTab.svelte +++ b/plugins/chunter-resources/src/components/EditChannelSettingsTab.svelte @@ -1,7 +1,7 @@ @@ -153,9 +160,9 @@ {#if employee}{formatName(employee.name)}{/if} {getTime(message.createOn)} {#if message.editedOn} - + - {/if} @@ -171,10 +178,7 @@ on:message={onMessageEdit} />
-
{:else} @@ -203,7 +207,14 @@ {#if !thread}
{/if} -
+
+ +
diff --git a/plugins/chunter-resources/src/components/SavedMessages.svelte b/plugins/chunter-resources/src/components/SavedMessages.svelte new file mode 100644 index 0000000000..aa75020272 --- /dev/null +++ b/plugins/chunter-resources/src/components/SavedMessages.svelte @@ -0,0 +1,108 @@ + + +{#if savedMessages.length > 0} + {#each savedMessages as message} +
openMessage(message)}> + +
+ {/each} +{:else} +
+ +
+
+ + +
+{/if} + + diff --git a/plugins/chunter-resources/src/components/ThreadView.svelte b/plugins/chunter-resources/src/components/ThreadView.svelte index bcf9c1b057..07f2f7dea4 100644 --- a/plugins/chunter-resources/src/components/ThreadView.svelte +++ b/plugins/chunter-resources/src/components/ThreadView.svelte @@ -123,6 +123,13 @@ )) ) + const preferenceQuery = createQuery() + let savedIds: Ref[] = [] + + preferenceQuery.query(chunter.class.SavedMessages, {}, (res) => { + savedIds = res.map((r) => r.attachedTo) + }) + async function onMessage (event: CustomEvent) { const { message, attachments } = event.detail const me = getCurrentAccount()._id @@ -193,7 +200,13 @@ {#if newMessagesPos === i} {/if} - + {/each} {/if} diff --git a/plugins/chunter-resources/src/index.ts b/plugins/chunter-resources/src/index.ts index c8818c67e3..772bf3be41 100644 --- a/plugins/chunter-resources/src/index.ts +++ b/plugins/chunter-resources/src/index.ts @@ -32,6 +32,8 @@ import CreateChannel from './components/CreateChannel.svelte' import EditChannel from './components/EditChannel.svelte' import ThreadView from './components/ThreadView.svelte' import Threads from './components/Threads.svelte' +import SavedMessages from './components/SavedMessages.svelte' +import preference from '@anticrm/preference' export { CommentsPresenter } @@ -125,6 +127,24 @@ async function UnarchiveChannel (channel: Channel): Promise { } ) } + +export async function AddToSaved (message: ChunterMessage): Promise { + const client = getClient() + + await client.createDoc(chunter.class.SavedMessages, preference.space.Preference, { + attachedTo: message._id + }) +} + +export async function DeleteFromSaved (message: ChunterMessage): Promise { + const client = getClient() + + const current = await client.findOne(chunter.class.SavedMessages, { attachedTo: message._id }) + if (current !== undefined) { + await client.remove(current) + } +} + export default async (): Promise => ({ component: { CommentInput, @@ -136,7 +156,8 @@ export default async (): Promise => ({ ChannelPresenter, EditChannel, Threads, - ThreadView + ThreadView, + SavedMessages }, activity: { TxCommentCreate, diff --git a/plugins/chunter-resources/src/plugin.ts b/plugins/chunter-resources/src/plugin.ts index a0227d4336..8eeec24b8d 100644 --- a/plugins/chunter-resources/src/plugin.ts +++ b/plugins/chunter-resources/src/plugin.ts @@ -61,6 +61,10 @@ export default mergeIds(chunterId, chunter, { EditMessage: '' as IntlString, Edited: '' as IntlString, AndYou: '' as IntlString, - ShowMoreReplies: '' as IntlString + ShowMoreReplies: '' as IntlString, + AddToSaved: '' as IntlString, + RemoveFromSaved: '' as IntlString, + EmptySavedHeader: '' as IntlString, + EmptySavedText: '' as IntlString } }) diff --git a/plugins/chunter/package.json b/plugins/chunter/package.json index 6dfdb1b440..6e965cba3b 100644 --- a/plugins/chunter/package.json +++ b/plugins/chunter/package.json @@ -29,6 +29,7 @@ "@anticrm/platform": "~0.6.5", "@anticrm/ui": "~0.6.0", "@anticrm/contact": "~0.6.5", - "@anticrm/core": "~0.6.16" + "@anticrm/core": "~0.6.16", + "@anticrm/preference": "~0.6.0" } } diff --git a/plugins/chunter/src/index.ts b/plugins/chunter/src/index.ts index 4ee14c8085..1ec261ed70 100644 --- a/plugins/chunter/src/index.ts +++ b/plugins/chunter/src/index.ts @@ -17,6 +17,7 @@ import type { Account, AttachedDoc, Class, Doc, Ref, Space, Timestamp } from '@a import type { Employee } from '@anticrm/contact' import type { Asset, Plugin } from '@anticrm/platform' import { IntlString, plugin } from '@anticrm/platform' +import type { Preference } from '@anticrm/preference' import { AnyComponent } from '@anticrm/ui' /** @@ -82,6 +83,13 @@ export interface Backlink extends Comment { attachedDocId?: Ref } +/** + * @public + */ +export interface SavedMessages extends Preference { + attachedTo: Ref +} + /** * @public */ @@ -92,7 +100,8 @@ export default plugin(chunterId, { Chunter: '' as Asset, Hashtag: '' as Asset, Thread: '' as Asset, - Lock: '' as Asset + Lock: '' as Asset, + Bookmark: '' as Asset }, component: { CommentInput: '' as AnyComponent, @@ -104,7 +113,8 @@ export default plugin(chunterId, { ThreadMessage: '' as Ref>, Backlink: '' as Ref>, Comment: '' as Ref>, - Channel: '' as Ref> + Channel: '' as Ref>, + SavedMessages: '' as Ref> }, space: { Backlinks: '' as Ref