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",
"To": "to",
"Unset": "unset",
"NoEmployee": "No employee"
"System": "System"
}
}

View File

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

View File

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

View File

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

View File

@ -22,13 +22,13 @@
import { createEventDispatcher } from 'svelte'
import { getChannelProviders } from '../utils'
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 size: 'small' | 'medium' | 'large' | 'x-large' = 'large'
export let reverse: boolean = false
export let integrations: Set<Ref<Doc>> = new Set<Ref<Doc>>()
const notificationClient = NotificationClient.getClient()
const notificationClient = NotificationClientImpl.getClient()
const lastViews = notificationClient.getLastViews()
interface Item {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -15,15 +15,15 @@
//
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 { writable, Writable } from 'svelte/store'
/**
* @public
*/
export class NotificationClient {
protected static _instance: NotificationClient | undefined = undefined
export class NotificationClientImpl implements NotificationClient {
protected static _instance: NotificationClientImpl | undefined = undefined
private lastViews = new Map<Ref<Doc>, LastView>()
private readonly lastViewsStore = writable(new Map<Ref<Doc>, Timestamp>())
@ -42,11 +42,11 @@ export class NotificationClient {
})
}
static getClient (): NotificationClient {
if (NotificationClient._instance === undefined) {
NotificationClient._instance = new NotificationClient()
static getClient (): NotificationClientImpl {
if (NotificationClientImpl._instance === undefined) {
NotificationClientImpl._instance = new NotificationClientImpl()
}
return NotificationClient._instance
return NotificationClientImpl._instance
}
getLastViews (): Writable<Map<Ref<Doc>, Timestamp>> {
@ -61,9 +61,6 @@ export class NotificationClient {
): Promise<void> {
const client = getClient()
const user = getCurrentAccount()._id
console.log('SUBSCRIBE')
console.log('USER')
console.log(user)
const lastView = time ?? new Date().getTime()
const current = this.lastViews.get(_id)
if (current !== undefined) {
@ -90,9 +87,6 @@ export class NotificationClient {
async unsubscribe (_id: Ref<Doc>): Promise<void> {
const client = getClient()
const user = getCurrentAccount()._id
console.log('UNSUBSCRIBE')
console.log('USER')
console.log(user)
const current = await client.findOne(notification.class.LastView, { attachedTo: _id, user })
if (current !== undefined) {
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 { Asset, IntlString, Plugin } from '@anticrm/platform'
import type { Asset, IntlString, Plugin, Resource } from '@anticrm/platform'
import { plugin } from '@anticrm/platform'
import { AnyComponent } from '@anticrm/ui'
@ -83,6 +83,18 @@ export interface NotificationSetting extends Doc {
*/
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
*/
@ -117,6 +129,9 @@ const notification = plugin(notificationId, {
string: {
Notification: '' as IntlString,
Notifications: '' as IntlString
},
function: {
GetNotificationClient: '' as Resource<NotificationClientFactoy>
}
})

View File

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

View File

@ -17,7 +17,7 @@
import contact, { formatName } from '@anticrm/contact'
import core, { Class, ClassifierKind, Doc, Mixin, Obj, Ref } from '@anticrm/core'
import { Panel } from '@anticrm/panel'
import { Asset, translate } from '@anticrm/platform'
import { Asset, getResource, translate } from '@anticrm/platform'
import {
AttributesBar,
createQuery,
@ -27,12 +27,15 @@
} from '@anticrm/presentation'
import { AnyComponent, Component, Label } from '@anticrm/ui'
import view from '@anticrm/view'
import { createEventDispatcher } from 'svelte'
import { createEventDispatcher, afterUpdate, onDestroy } from 'svelte'
import { getCollectionCounter, getMixinStyle } from '../utils'
import notification from '@anticrm/notification'
export let _id: Ref<Doc>
export let _class: Ref<Class<Doc>>
export let rightSection: AnyComponent | undefined = undefined
let lastId: Ref<Doc> = _id
let lastClass: Ref<Class<Doc>> = _class
let object: Doc
let objectClass: Class<Doc>
let parentClass: Ref<Class<Doc>>
@ -40,8 +43,25 @@
const client = getClient()
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())
$: 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()
$: _id &&
_class &&

View File

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

View File

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