mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-08 08:51:12 +00:00
Chunter: Delete message (#1336)
Signed-off-by: Denis Bunakalya <denis.bunakalya@xored.com>
This commit is contained in:
parent
17ef11daf6
commit
24c547ab39
@ -30,6 +30,7 @@
|
|||||||
"New": "New",
|
"New": "New",
|
||||||
"MarkUnread": "Mark unread",
|
"MarkUnread": "Mark unread",
|
||||||
"GetNewReplies": "Get notified about new replies",
|
"GetNewReplies": "Get notified about new replies",
|
||||||
"TurnOffReplies": "Turn off notifications for replies"
|
"TurnOffReplies": "Turn off notifications for replies",
|
||||||
|
"DeleteMessage": "Delete message"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -29,6 +29,7 @@
|
|||||||
"New": "Новое",
|
"New": "Новое",
|
||||||
"MarkUnread": "Отметить как непрочитанное",
|
"MarkUnread": "Отметить как непрочитанное",
|
||||||
"GetNewReplies": "Получать уведомления о новых ответах",
|
"GetNewReplies": "Получать уведомления о новых ответах",
|
||||||
"TurnOffReplies": "Выключить уведомления об ответах"
|
"TurnOffReplies": "Выключить уведомления об ответах",
|
||||||
|
"DeleteMessage": "Удалить сообщение"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,11 +17,11 @@
|
|||||||
import { AttachmentList } from '@anticrm/attachment-resources'
|
import { AttachmentList } from '@anticrm/attachment-resources'
|
||||||
import type { Message } from '@anticrm/chunter'
|
import type { Message } from '@anticrm/chunter'
|
||||||
import { Employee, EmployeeAccount, formatName } from '@anticrm/contact'
|
import { Employee, EmployeeAccount, formatName } from '@anticrm/contact'
|
||||||
import { Ref, WithLookup } from '@anticrm/core'
|
import { Ref, WithLookup, getCurrentAccount } from '@anticrm/core'
|
||||||
import { NotificationClientImpl } from '@anticrm/notification-resources'
|
import { NotificationClientImpl } from '@anticrm/notification-resources'
|
||||||
import { getResource } from '@anticrm/platform'
|
import { getResource } from '@anticrm/platform'
|
||||||
import { Avatar, getClient, MessageViewer } from '@anticrm/presentation'
|
import { Avatar, getClient, MessageViewer } from '@anticrm/presentation'
|
||||||
import { ActionIcon, IconMoreH, Menu, showPopup } from '@anticrm/ui'
|
import { ActionIcon, IconMoreH, Menu, showPopup, getCurrentLocation, navigate } from '@anticrm/ui'
|
||||||
import { Action } from '@anticrm/view'
|
import { Action } from '@anticrm/view'
|
||||||
import { getActions } from '@anticrm/view-resources'
|
import { getActions } from '@anticrm/view-resources'
|
||||||
import { createEventDispatcher } from 'svelte'
|
import { createEventDispatcher } from 'svelte'
|
||||||
@ -59,6 +59,21 @@
|
|||||||
action: chunter.actionImpl.SubscribeMessage
|
action: chunter.actionImpl.SubscribeMessage
|
||||||
} as Action)
|
} 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
|
||||||
|
}
|
||||||
|
|
||||||
const showMenu = async (ev: Event): Promise<void> => {
|
const showMenu = async (ev: Event): Promise<void> => {
|
||||||
const actions = await getActions(client, message, chunter.class.Message)
|
const actions = await getActions(client, message, chunter.class.Message)
|
||||||
actions.push(subscribeAction)
|
actions.push(subscribeAction)
|
||||||
@ -73,7 +88,8 @@
|
|||||||
const impl = await getResource(a.action)
|
const impl = await getResource(a.action)
|
||||||
await impl(message)
|
await impl(message)
|
||||||
}
|
}
|
||||||
}))
|
})),
|
||||||
|
...(getCurrentAccount()._id === message.createBy ? [deleteAction] : [])
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
ev.target as HTMLElement
|
ev.target as HTMLElement
|
||||||
@ -108,7 +124,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{#if !thread}
|
{#if !thread}
|
||||||
<div>
|
<div>
|
||||||
{#if message.replies}<Replies
|
{#if message.replies?.length}<Replies
|
||||||
replies={message.replies}
|
replies={message.replies}
|
||||||
lastReply={message.lastReply}
|
lastReply={message.lastReply}
|
||||||
on:click={openThread}
|
on:click={openThread}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
import { AttachmentList } from '@anticrm/attachment-resources'
|
import { AttachmentList } from '@anticrm/attachment-resources'
|
||||||
import type { ThreadMessage } from '@anticrm/chunter'
|
import type { ThreadMessage } from '@anticrm/chunter'
|
||||||
import { Employee, EmployeeAccount, formatName } from '@anticrm/contact'
|
import { Employee, EmployeeAccount, formatName } from '@anticrm/contact'
|
||||||
import { Ref, WithLookup } from '@anticrm/core'
|
import { Ref, WithLookup, getCurrentAccount } from '@anticrm/core'
|
||||||
import { NotificationClientImpl } from '@anticrm/notification-resources'
|
import { NotificationClientImpl } from '@anticrm/notification-resources'
|
||||||
import { getResource } from '@anticrm/platform'
|
import { getResource } from '@anticrm/platform'
|
||||||
import { Avatar, getClient, MessageViewer } from '@anticrm/presentation'
|
import { Avatar, getClient, MessageViewer } from '@anticrm/presentation'
|
||||||
@ -53,6 +53,11 @@
|
|||||||
action: chunter.actionImpl.SubscribeComment
|
action: chunter.actionImpl.SubscribeComment
|
||||||
} as Action)
|
} as Action)
|
||||||
|
|
||||||
|
const deleteAction = {
|
||||||
|
label: chunter.string.DeleteMessage,
|
||||||
|
action: async () => await client.removeDoc(message._class, message.space, message._id)
|
||||||
|
}
|
||||||
|
|
||||||
const showMenu = async (ev: Event): Promise<void> => {
|
const showMenu = async (ev: Event): Promise<void> => {
|
||||||
const actions = await getActions(client, message, chunter.class.ThreadMessage)
|
const actions = await getActions(client, message, chunter.class.ThreadMessage)
|
||||||
actions.push(subscribeAction)
|
actions.push(subscribeAction)
|
||||||
@ -67,7 +72,8 @@
|
|||||||
const impl = await getResource(a.action)
|
const impl = await getResource(a.action)
|
||||||
await impl(message)
|
await impl(message)
|
||||||
}
|
}
|
||||||
}))
|
})),
|
||||||
|
...(getCurrentAccount()._id === message.createBy ? [deleteAction] : [])
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
ev.target as HTMLElement
|
ev.target as HTMLElement
|
||||||
|
@ -50,6 +50,7 @@ export default mergeIds(chunterId, chunter, {
|
|||||||
LastReply: '' as IntlString,
|
LastReply: '' as IntlString,
|
||||||
New: '' as IntlString,
|
New: '' as IntlString,
|
||||||
GetNewReplies: '' as IntlString,
|
GetNewReplies: '' as IntlString,
|
||||||
TurnOffReplies: '' as IntlString
|
TurnOffReplies: '' as IntlString,
|
||||||
|
DeleteMessage: '' as IntlString
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
|
|
||||||
import chunter, { Channel, Comment, Message } from '@anticrm/chunter'
|
import chunter, { Channel, Comment, Message, ThreadMessage } from '@anticrm/chunter'
|
||||||
import { EmployeeAccount } from '@anticrm/contact'
|
import { EmployeeAccount } from '@anticrm/contact'
|
||||||
import core, { Class, Doc, DocumentQuery, FindOptions, FindResult, Hierarchy, Ref, Tx, TxCreateDoc, TxProcessor, TxUpdateDoc } from '@anticrm/core'
|
import core, { Class, Doc, DocumentQuery, FindOptions, FindResult, Hierarchy, Ref, Tx, TxCreateDoc, TxProcessor, TxUpdateDoc, TxRemoveDoc } from '@anticrm/core'
|
||||||
import login from '@anticrm/login'
|
import login from '@anticrm/login'
|
||||||
import { getMetadata } from '@anticrm/platform'
|
import { getMetadata } from '@anticrm/platform'
|
||||||
import { TriggerControl } from '@anticrm/server-core'
|
import { TriggerControl } from '@anticrm/server-core'
|
||||||
@ -58,7 +58,7 @@ export async function CommentCreate (tx: Tx, control: TriggerControl): Promise<T
|
|||||||
const hierarchy = control.hierarchy
|
const hierarchy = control.hierarchy
|
||||||
if (tx._class !== core.class.TxCreateDoc) return []
|
if (tx._class !== core.class.TxCreateDoc) return []
|
||||||
const doc = TxProcessor.createDoc2Doc(tx as TxCreateDoc<Doc>)
|
const doc = TxProcessor.createDoc2Doc(tx as TxCreateDoc<Doc>)
|
||||||
if (!hierarchy.isDerived(doc._class, chunter.class.Comment)) {
|
if (!hierarchy.isDerived(doc._class, chunter.class.ThreadMessage)) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +80,44 @@ export async function CommentCreate (tx: Tx, control: TriggerControl): Promise<T
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export async function CommentDelete (tx: Tx, control: TriggerControl): Promise<Tx[]> {
|
||||||
|
const hierarchy = control.hierarchy
|
||||||
|
if (tx._class !== core.class.TxRemoveDoc) return []
|
||||||
|
|
||||||
|
const rmTx = tx as TxRemoveDoc<ThreadMessage>
|
||||||
|
if (!hierarchy.isDerived(rmTx.objectClass, chunter.class.ThreadMessage)) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
const createTx = (await control.findAll(core.class.TxCreateDoc, {
|
||||||
|
objectId: rmTx.objectId
|
||||||
|
}, { limit: 1 }))[0]
|
||||||
|
|
||||||
|
const comment = TxProcessor.createDoc2Doc(createTx as TxCreateDoc<ThreadMessage>)
|
||||||
|
|
||||||
|
const comments = await control.findAll(chunter.class.ThreadMessage, {
|
||||||
|
attachedTo: comment.attachedTo
|
||||||
|
})
|
||||||
|
const updateTx = control.txFactory.createTxUpdateDoc<Message>(
|
||||||
|
chunter.class.Message,
|
||||||
|
comment.space,
|
||||||
|
comment.attachedTo,
|
||||||
|
{
|
||||||
|
replies:
|
||||||
|
comments
|
||||||
|
.map(comm => (control.modelDb.getObject(comm.createBy) as EmployeeAccount).employee),
|
||||||
|
lastReply:
|
||||||
|
comments.length > 0
|
||||||
|
? Math.max(...comments.map(comm => comm.createOn))
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return [updateTx]
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
@ -112,7 +150,8 @@ export async function MessageCreate (tx: Tx, control: TriggerControl): Promise<T
|
|||||||
export async function ChunterTrigger (tx: Tx, control: TriggerControl): Promise<Tx[]> {
|
export async function ChunterTrigger (tx: Tx, control: TriggerControl): Promise<Tx[]> {
|
||||||
const promises = [
|
const promises = [
|
||||||
MessageCreate(tx, control),
|
MessageCreate(tx, control),
|
||||||
CommentCreate(tx, control)
|
CommentCreate(tx, control),
|
||||||
|
CommentDelete(tx, control)
|
||||||
]
|
]
|
||||||
const res = await Promise.all(promises)
|
const res = await Promise.all(promises)
|
||||||
return res.flat()
|
return res.flat()
|
||||||
|
Loading…
Reference in New Issue
Block a user