mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-25 19:58:30 +03:00
Chunter: Update channel last message and close thread on deletion from other user (#1389)
* 1300 Update channel last message on deletion Signed-off-by: Denis Bunakalya <denis.bunakalya@xored.com> * 1300 Close thread on deletion even from other user Signed-off-by: Denis Bunakalya <denis.bunakalya@xored.com>
This commit is contained in:
parent
ca91425d6f
commit
e205f31391
@ -21,7 +21,7 @@
|
||||
import { NotificationClientImpl } from '@anticrm/notification-resources'
|
||||
import { getResource } from '@anticrm/platform'
|
||||
import { Avatar, getClient, MessageViewer } from '@anticrm/presentation'
|
||||
import { ActionIcon, IconMoreH, Menu, showPopup, getCurrentLocation, navigate } from '@anticrm/ui'
|
||||
import { ActionIcon, IconMoreH, Menu, showPopup } from '@anticrm/ui'
|
||||
import { Action } from '@anticrm/view'
|
||||
import { getActions } from '@anticrm/view-resources'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
@ -59,19 +59,9 @@
|
||||
action: chunter.actionImpl.SubscribeMessage
|
||||
} as Action)
|
||||
|
||||
async function deleteMessage () {
|
||||
await client.remove(message)
|
||||
const loc = getCurrentLocation()
|
||||
|
||||
if (loc.path[3] === message._id) {
|
||||
loc.path.length = 3
|
||||
navigate(loc)
|
||||
}
|
||||
}
|
||||
|
||||
const deleteAction = {
|
||||
label: chunter.string.DeleteMessage,
|
||||
action: deleteMessage
|
||||
action: async () => await client.remove(message)
|
||||
}
|
||||
|
||||
const showMenu = async (ev: Event): Promise<void> => {
|
||||
|
@ -20,7 +20,7 @@
|
||||
import core, { Doc, generateId, getCurrentAccount, Ref, Space, TxFactory } from '@anticrm/core'
|
||||
import { NotificationClientImpl } from '@anticrm/notification-resources'
|
||||
import { createQuery, getClient } from '@anticrm/presentation'
|
||||
import { IconClose, Label } from '@anticrm/ui'
|
||||
import { IconClose, Label, getCurrentLocation, navigate } from '@anticrm/ui'
|
||||
import { afterUpdate, beforeUpdate, createEventDispatcher } from 'svelte'
|
||||
import { createBacklinks } from '../backlinks'
|
||||
import chunter from '../plugin'
|
||||
@ -65,7 +65,15 @@
|
||||
{
|
||||
_id: id
|
||||
},
|
||||
(res) => (message = res[0]),
|
||||
(res) => {
|
||||
message = res[0]
|
||||
|
||||
if (!message) {
|
||||
const loc = getCurrentLocation()
|
||||
loc.path.length = 3
|
||||
navigate(loc)
|
||||
}
|
||||
},
|
||||
{
|
||||
lookup: {
|
||||
_id: { attachments: attachment.class.Attachment },
|
||||
|
@ -15,7 +15,21 @@
|
||||
|
||||
import chunter, { Channel, Comment, Message, ThreadMessage } from '@anticrm/chunter'
|
||||
import { EmployeeAccount } from '@anticrm/contact'
|
||||
import core, { Class, Doc, DocumentQuery, FindOptions, FindResult, Hierarchy, Ref, Tx, TxCreateDoc, TxProcessor, TxUpdateDoc, TxRemoveDoc } from '@anticrm/core'
|
||||
import core, {
|
||||
Class,
|
||||
Doc,
|
||||
DocumentQuery,
|
||||
FindOptions,
|
||||
FindResult,
|
||||
Hierarchy,
|
||||
Ref,
|
||||
Tx,
|
||||
TxCreateDoc,
|
||||
TxProcessor,
|
||||
TxUpdateDoc,
|
||||
TxRemoveDoc,
|
||||
TxCollectionCUD
|
||||
} from '@anticrm/core'
|
||||
import login from '@anticrm/login'
|
||||
import { getMetadata } from '@anticrm/platform'
|
||||
import { TriggerControl } from '@anticrm/server-core'
|
||||
@ -144,12 +158,50 @@ export async function MessageCreate (tx: Tx, control: TriggerControl): Promise<T
|
||||
return []
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export async function MessageDelete (tx: Tx, control: TriggerControl): Promise<Tx[]> {
|
||||
const hierarchy = control.hierarchy
|
||||
if (tx._class !== core.class.TxCollectionCUD) return []
|
||||
|
||||
const rmTx = (tx as TxCollectionCUD<Channel, Message>).tx
|
||||
if (!hierarchy.isDerived(rmTx.objectClass, chunter.class.Message)) {
|
||||
return []
|
||||
}
|
||||
const createTx = (await control.findAll(core.class.TxCreateDoc, {
|
||||
objectId: rmTx.objectId
|
||||
}, { limit: 1 }))[0]
|
||||
|
||||
const message = TxProcessor.createDoc2Doc(createTx as TxCreateDoc<Message>)
|
||||
|
||||
const channel = (await control.findAll(chunter.class.Channel, {
|
||||
_id: message.space
|
||||
}, { limit: 1 }))[0]
|
||||
|
||||
if (channel.lastMessage === message.createOn) {
|
||||
const messages = await control.findAll(chunter.class.Message, {
|
||||
attachedTo: channel._id
|
||||
})
|
||||
const lastMessageDate = messages.reduce((maxDate, mess) => mess.createOn > maxDate ? mess.createOn : maxDate, 0)
|
||||
|
||||
const updateTx = control.txFactory.createTxUpdateDoc<Channel>(channel._class, channel.space, channel._id, {
|
||||
lastMessage: lastMessageDate > 0 ? lastMessageDate : undefined
|
||||
})
|
||||
|
||||
return [updateTx]
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export async function ChunterTrigger (tx: Tx, control: TriggerControl): Promise<Tx[]> {
|
||||
const promises = [
|
||||
MessageCreate(tx, control),
|
||||
MessageDelete(tx, control),
|
||||
CommentCreate(tx, control),
|
||||
CommentDelete(tx, control)
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user