Read last view && minor fixes (#1067)

Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com>
This commit is contained in:
Denis Bykhov 2022-02-28 09:42:06 +06:00 committed by GitHub
parent e7479ff078
commit b103ac743c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 70 additions and 37 deletions

View File

@ -9,6 +9,6 @@
"Changed": "changed", "Changed": "changed",
"To": "to", "To": "to",
"Unset": "unset", "Unset": "unset",
"NoEmployee": "No employee" "System": "System"
} }
} }

View File

@ -9,6 +9,6 @@
"Changed": "изменил(а)", "Changed": "изменил(а)",
"To": "на", "To": "на",
"Unset": "сбросил", "Unset": "сбросил",
"NoEmployee": "Не сотрудник" "System": "Система"
} }
} }

View File

@ -124,7 +124,7 @@
{#if employee} {#if employee}
{formatName(employee.name)} {formatName(employee.name)}
{:else} {:else}
<Label label={activity.string.NoEmployee} /> <Label label={activity.string.System} />
{/if} {/if}
</div> </div>
{#if viewlet && viewlet?.editable} {#if viewlet && viewlet?.editable}

View File

@ -24,6 +24,6 @@ export default mergeIds(activityId, activity, {
Changed: '' as IntlString, Changed: '' as IntlString,
To: '' as IntlString, To: '' as IntlString,
Unset: '' as IntlString, Unset: '' as IntlString,
NoEmployee: '' as IntlString System: '' as IntlString
} }
}) })

View File

@ -22,13 +22,13 @@
import { createEventDispatcher } from 'svelte' import { createEventDispatcher } from 'svelte'
import { getChannelProviders } from '../utils' import { getChannelProviders } from '../utils'
import ChannelsPopup from './ChannelsPopup.svelte' import ChannelsPopup from './ChannelsPopup.svelte'
import { NotificationClient } from '@anticrm/notification-resources' import { NotificationClientImpl } from '@anticrm/notification-resources'
export let value: AttachedData<Channel>[] | Channel | null export let value: AttachedData<Channel>[] | Channel | null
export let size: 'small' | 'medium' | 'large' | 'x-large' = 'large' export let size: 'small' | 'medium' | 'large' | 'x-large' = 'large'
export let reverse: boolean = false export let reverse: boolean = false
export let integrations: Set<Ref<Doc>> = new Set<Ref<Doc>>() export let integrations: Set<Ref<Doc>> = new Set<Ref<Doc>>()
const notificationClient = NotificationClient.getClient() const notificationClient = NotificationClientImpl.getClient()
const lastViews = notificationClient.getLastViews() const lastViews = notificationClient.getLastViews()
interface Item { interface Item {

View File

@ -24,7 +24,7 @@
import setting from '@anticrm/setting' import setting from '@anticrm/setting'
import Connect from './Connect.svelte' import Connect from './Connect.svelte'
import Messages from './Messages.svelte' import Messages from './Messages.svelte'
import { NotificationClient } from '@anticrm/notification-resources' import { NotificationClientImpl } from '@anticrm/notification-resources'
export let object: Contact export let object: Contact
export let channel: Channel export let channel: Channel
@ -43,7 +43,7 @@
const accauntsQuery = createQuery() const accauntsQuery = createQuery()
const settingsQuery = createQuery() const settingsQuery = createQuery()
const accountId = getCurrentAccount()._id const accountId = getCurrentAccount()._id
const notificationClient = NotificationClient.getClient() const notificationClient = NotificationClientImpl.getClient()
function updateMessagesQuery (channelId: Ref<Channel>): void { function updateMessagesQuery (channelId: Ref<Channel>): void {
messagesQuery.query( messagesQuery.query(

View File

@ -20,13 +20,13 @@
import FullMessage from './FullMessage.svelte' import FullMessage from './FullMessage.svelte'
import Chats from './Chats.svelte' import Chats from './Chats.svelte'
import { getClient } from '@anticrm/presentation' import { getClient } from '@anticrm/presentation'
import { NotificationClient } from '@anticrm/notification-resources' import { NotificationClientImpl } from '@anticrm/notification-resources'
export let object: Contact export let object: Contact
let newMessage: boolean = false let newMessage: boolean = false
let currentMessage: SharedMessage | undefined = undefined let currentMessage: SharedMessage | undefined = undefined
let channel: Channel | undefined = undefined let channel: Channel | undefined = undefined
const notificationClient = NotificationClient.getClient() const notificationClient = NotificationClientImpl.getClient()
const client = getClient() const client = getClient()

View File

@ -24,12 +24,12 @@
import { Channel, Contact, formatName } from '@anticrm/contact' import { Channel, Contact, formatName } from '@anticrm/contact'
import { TextEditor } from '@anticrm/text-editor' import { TextEditor } from '@anticrm/text-editor'
import plugin from '../plugin' import plugin from '../plugin'
import { NotificationClient } from '@anticrm/notification-resources' import { NotificationClientImpl } from '@anticrm/notification-resources'
export let object: Contact export let object: Contact
export let channel: Channel export let channel: Channel
export let currentMessage: SharedMessage | undefined export let currentMessage: SharedMessage | undefined
const notificationClient = NotificationClient.getClient() const notificationClient = NotificationClientImpl.getClient()
let editor: TextEditor let editor: TextEditor
let copy: string = '' let copy: string = ''

View File

@ -16,11 +16,11 @@
import { Doc } from '@anticrm/core' import { Doc } from '@anticrm/core'
import { ActionIcon } from '@anticrm/ui' import { ActionIcon } from '@anticrm/ui'
import notification from '../plugin' import notification from '../plugin'
import { NotificationClient } from '../utils' import { NotificationClientImpl } from '../utils'
export let value: Doc export let value: Doc
const notificationClient = NotificationClient.getClient() const notificationClient = NotificationClientImpl.getClient()
const lastViews = notificationClient.getLastViews() const lastViews = notificationClient.getLastViews()
$: subscribed = $lastViews.has(value._id) $: subscribed = $lastViews.has(value._id)

View File

@ -15,11 +15,11 @@
<script lang="ts"> <script lang="ts">
import { Doc } from '@anticrm/core' import { Doc } from '@anticrm/core'
import { getPlatformColor } from '@anticrm/ui' import { getPlatformColor } from '@anticrm/ui'
import { NotificationClient } from '../utils' import { NotificationClientImpl } from '../utils'
export let value: Doc export let value: Doc
const notificationClient = NotificationClient.getClient() const notificationClient = NotificationClientImpl.getClient()
const lastViews = notificationClient.getLastViews() const lastViews = notificationClient.getLastViews()
$: lastView = $lastViews.get(value._id) $: lastView = $lastViews.get(value._id)

View File

@ -19,6 +19,7 @@ import NotificationsPopup from './components/NotificationsPopup.svelte'
import NotificationSettings from './components/NotificationSettings.svelte' import NotificationSettings from './components/NotificationSettings.svelte'
import NotificationPresenter from './components/NotificationPresenter.svelte' import NotificationPresenter from './components/NotificationPresenter.svelte'
import LastViewEditor from './components/LastViewEditor.svelte' import LastViewEditor from './components/LastViewEditor.svelte'
import { NotificationClientImpl } from './utils'
export * from './utils' export * from './utils'
@ -28,5 +29,8 @@ export default async (): Promise<Resources> => ({
NotificationPresenter, NotificationPresenter,
NotificationSettings, NotificationSettings,
LastViewEditor LastViewEditor
},
function: {
GetNotificationClient: NotificationClientImpl.getClient
} }
}) })

View File

@ -15,15 +15,15 @@
// //
import core, { Class, Doc, getCurrentAccount, Ref, Timestamp } from '@anticrm/core' import core, { Class, Doc, getCurrentAccount, Ref, Timestamp } from '@anticrm/core'
import notification, { LastView } from '@anticrm/notification' import notification, { LastView, NotificationClient } from '@anticrm/notification'
import { createQuery, getClient } from '@anticrm/presentation' import { createQuery, getClient } from '@anticrm/presentation'
import { writable, Writable } from 'svelte/store' import { writable, Writable } from 'svelte/store'
/** /**
* @public * @public
*/ */
export class NotificationClient { export class NotificationClientImpl implements NotificationClient {
protected static _instance: NotificationClient | undefined = undefined protected static _instance: NotificationClientImpl | undefined = undefined
private lastViews = new Map<Ref<Doc>, LastView>() private lastViews = new Map<Ref<Doc>, LastView>()
private readonly lastViewsStore = writable(new Map<Ref<Doc>, Timestamp>()) private readonly lastViewsStore = writable(new Map<Ref<Doc>, Timestamp>())
@ -42,11 +42,11 @@ export class NotificationClient {
}) })
} }
static getClient (): NotificationClient { static getClient (): NotificationClientImpl {
if (NotificationClient._instance === undefined) { if (NotificationClientImpl._instance === undefined) {
NotificationClient._instance = new NotificationClient() NotificationClientImpl._instance = new NotificationClientImpl()
} }
return NotificationClient._instance return NotificationClientImpl._instance
} }
getLastViews (): Writable<Map<Ref<Doc>, Timestamp>> { getLastViews (): Writable<Map<Ref<Doc>, Timestamp>> {
@ -61,9 +61,6 @@ export class NotificationClient {
): Promise<void> { ): Promise<void> {
const client = getClient() const client = getClient()
const user = getCurrentAccount()._id const user = getCurrentAccount()._id
console.log('SUBSCRIBE')
console.log('USER')
console.log(user)
const lastView = time ?? new Date().getTime() const lastView = time ?? new Date().getTime()
const current = this.lastViews.get(_id) const current = this.lastViews.get(_id)
if (current !== undefined) { if (current !== undefined) {
@ -90,9 +87,6 @@ export class NotificationClient {
async unsubscribe (_id: Ref<Doc>): Promise<void> { async unsubscribe (_id: Ref<Doc>): Promise<void> {
const client = getClient() const client = getClient()
const user = getCurrentAccount()._id const user = getCurrentAccount()._id
console.log('UNSUBSCRIBE')
console.log('USER')
console.log(user)
const current = await client.findOne(notification.class.LastView, { attachedTo: _id, user }) const current = await client.findOne(notification.class.LastView, { attachedTo: _id, user })
if (current !== undefined) { if (current !== undefined) {
await client.removeDoc(current._class, current.space, current._id) await client.removeDoc(current._class, current.space, current._id)

View File

@ -15,7 +15,7 @@
// //
import type { Account, AttachedDoc, Class, Doc, Ref, Space, Timestamp, TxCUD } from '@anticrm/core' import type { Account, AttachedDoc, Class, Doc, Ref, Space, Timestamp, TxCUD } from '@anticrm/core'
import type { Asset, IntlString, Plugin } from '@anticrm/platform' import type { Asset, IntlString, Plugin, Resource } from '@anticrm/platform'
import { plugin } from '@anticrm/platform' import { plugin } from '@anticrm/platform'
import { AnyComponent } from '@anticrm/ui' import { AnyComponent } from '@anticrm/ui'
@ -83,6 +83,18 @@ export interface NotificationSetting extends Doc {
*/ */
export const notificationId = 'notification' as Plugin export const notificationId = 'notification' as Plugin
/**
* @public
*/
export interface NotificationClient {
updateLastView: (_id: Ref<Doc>, _class: Ref<Class<Doc>>, time?: Timestamp, force?: boolean) => Promise<void>
}
/**
* @public
*/
export type NotificationClientFactoy = () => NotificationClient
/** /**
* @public * @public
*/ */
@ -117,6 +129,9 @@ const notification = plugin(notificationId, {
string: { string: {
Notification: '' as IntlString, Notification: '' as IntlString,
Notifications: '' as IntlString Notifications: '' as IntlString
},
function: {
GetNotificationClient: '' as Resource<NotificationClientFactoy>
} }
}) })

View File

@ -27,12 +27,12 @@
import Connect from './Connect.svelte' import Connect from './Connect.svelte'
import TelegramIcon from './icons/Telegram.svelte' import TelegramIcon from './icons/Telegram.svelte'
import Messages from './Messages.svelte' import Messages from './Messages.svelte'
import { NotificationClient } from '@anticrm/notification-resources' import { NotificationClientImpl } from '@anticrm/notification-resources'
export let object: Contact export let object: Contact
let channel: Channel | undefined = undefined let channel: Channel | undefined = undefined
const client = getClient() const client = getClient()
const notificationClient = NotificationClient.getClient() const notificationClient = NotificationClientImpl.getClient()
client client
.findOne(contact.class.Channel, { .findOne(contact.class.Channel, {

View File

@ -17,7 +17,7 @@
import contact, { formatName } from '@anticrm/contact' import contact, { formatName } from '@anticrm/contact'
import core, { Class, ClassifierKind, Doc, Mixin, Obj, Ref } from '@anticrm/core' import core, { Class, ClassifierKind, Doc, Mixin, Obj, Ref } from '@anticrm/core'
import { Panel } from '@anticrm/panel' import { Panel } from '@anticrm/panel'
import { Asset, translate } from '@anticrm/platform' import { Asset, getResource, translate } from '@anticrm/platform'
import { import {
AttributesBar, AttributesBar,
createQuery, createQuery,
@ -27,12 +27,15 @@
} from '@anticrm/presentation' } from '@anticrm/presentation'
import { AnyComponent, Component, Label } from '@anticrm/ui' import { AnyComponent, Component, Label } from '@anticrm/ui'
import view from '@anticrm/view' import view from '@anticrm/view'
import { createEventDispatcher } from 'svelte' import { createEventDispatcher, afterUpdate, onDestroy } from 'svelte'
import { getCollectionCounter, getMixinStyle } from '../utils' import { getCollectionCounter, getMixinStyle } from '../utils'
import notification from '@anticrm/notification'
export let _id: Ref<Doc> export let _id: Ref<Doc>
export let _class: Ref<Class<Doc>> export let _class: Ref<Class<Doc>>
export let rightSection: AnyComponent | undefined = undefined export let rightSection: AnyComponent | undefined = undefined
let lastId: Ref<Doc> = _id
let lastClass: Ref<Class<Doc>> = _class
let object: Doc let object: Doc
let objectClass: Class<Doc> let objectClass: Class<Doc>
let parentClass: Ref<Class<Doc>> let parentClass: Ref<Class<Doc>>
@ -40,8 +43,25 @@
const client = getClient() const client = getClient()
const hierarchy = client.getHierarchy() const hierarchy = client.getHierarchy()
const notificationClient = getResource(notification.function.GetNotificationClient).then((res) => res())
const docKeys: Set<string> = new Set<string>(hierarchy.getAllAttributes(core.class.AttachedDoc).keys()) const docKeys: Set<string> = new Set<string>(hierarchy.getAllAttributes(core.class.AttachedDoc).keys())
$: read(_id)
function read (_id: Ref<Doc>) {
if (lastId !== _id) {
const prev = lastId
const prevClass = lastClass
lastId = _id
lastClass = _class
notificationClient.then((client) => client.updateLastView(prev, prevClass))
}
}
onDestroy(async () => {
notificationClient.then((client) => client.updateLastView(_id, _class))
})
const query = createQuery() const query = createQuery()
$: _id && $: _id &&
_class && _class &&

View File

@ -4,7 +4,7 @@
"Delete": "Удалить", "Delete": "Удалить",
"ShowMenu": "Показать меню", "ShowMenu": "Показать меню",
"HideMenu": "Спрятать меню", "HideMenu": "Спрятать меню",
"Archive": "Архивировать", "Archive": "Архив",
"Archived": "Архивировал {object}", "Archived": "Архивировал {object}",
"Open": "Открыть", "Open": "Открыть",
"General": "Общее", "General": "Общее",

View File

@ -42,12 +42,12 @@
import Navigator from './Navigator.svelte' import Navigator from './Navigator.svelte'
import SpaceView from './SpaceView.svelte' import SpaceView from './SpaceView.svelte'
import notification, { NotificationStatus } from '@anticrm/notification' import notification, { NotificationStatus } from '@anticrm/notification'
import { NotificationClient } from '@anticrm/notification-resources' import { NotificationClientImpl } from '@anticrm/notification-resources'
export let client: Client export let client: Client
setClient(client) setClient(client)
NotificationClient.getClient() NotificationClientImpl.getClient()
let currentApp: Ref<Application> | undefined let currentApp: Ref<Application> | undefined
let currentSpace: Ref<Space> | undefined let currentSpace: Ref<Space> | undefined