1304 Edit message (#1395)

Signed-off-by: Denis Bunakalya <denis.bunakalya@xored.com>
This commit is contained in:
Denis Bunakalya 2022-04-14 10:36:11 +03:00 committed by GitHub
parent e83ffd3804
commit da45faf7d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 76 additions and 9 deletions

View File

@ -31,6 +31,7 @@
"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",
"EditMessage": "Edit message",
"DeleteMessage": "Delete message" "DeleteMessage": "Delete message"
} }
} }

View File

@ -30,6 +30,7 @@
"MarkUnread": "Отметить как непрочитанное", "MarkUnread": "Отметить как непрочитанное",
"GetNewReplies": "Получать уведомления о новых ответах", "GetNewReplies": "Получать уведомления о новых ответах",
"TurnOffReplies": "Выключить уведомления об ответах", "TurnOffReplies": "Выключить уведомления об ответах",
"EditMessage": "Редактировать сообщение",
"DeleteMessage": "Удалить сообщение" "DeleteMessage": "Удалить сообщение"
} }
} }

View File

@ -14,7 +14,7 @@
--> -->
<script lang="ts"> <script lang="ts">
import { Attachment } from '@anticrm/attachment' import { Attachment } from '@anticrm/attachment'
import { AttachmentList } from '@anticrm/attachment-resources' import { AttachmentList, AttachmentRefInput } 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, getCurrentAccount } from '@anticrm/core' import { Ref, WithLookup, getCurrentAccount } from '@anticrm/core'
@ -59,6 +59,13 @@
action: chunter.actionImpl.SubscribeMessage action: chunter.actionImpl.SubscribeMessage
} as Action) } as Action)
$: isEditing = false;
const editAction = {
label: chunter.string.EditMessage,
action: () => isEditing = true
}
const deleteAction = { const deleteAction = {
label: chunter.string.DeleteMessage, label: chunter.string.DeleteMessage,
action: async () => await client.remove(message) action: async () => await client.remove(message)
@ -79,13 +86,28 @@
await impl(message) await impl(message)
} }
})), })),
...(getCurrentAccount()._id === message.createBy ? [deleteAction] : []) ...(getCurrentAccount()._id === message.createBy ? [editAction, deleteAction] : [])
] ]
}, },
ev.target as HTMLElement ev.target as HTMLElement
) )
} }
async function onMessageEdit (event: CustomEvent) {
const { message: newContent, attachments: newAttachments } = event.detail
if (newContent !== message.content || newAttachments !== attachments) {
await client.update(
message,
{
content: newContent,
attachments: newAttachments
}
)
}
isEditing = false
}
function getEmployee (message: WithLookup<Message>): Employee | undefined { function getEmployee (message: WithLookup<Message>): Employee | undefined {
const employee = (message.$lookup?.createBy as EmployeeAccount).employee const employee = (message.$lookup?.createBy as EmployeeAccount).employee
if (employee !== undefined) { if (employee !== undefined) {
@ -105,8 +127,18 @@
{#if employee}{formatName(employee.name)}{/if} {#if employee}{formatName(employee.name)}{/if}
<span>{getTime(message.createOn)}</span> <span>{getTime(message.createOn)}</span>
</div> </div>
<div class="text"><MessageViewer message={message.content} /></div> {#if isEditing}
{#if message.attachments}<div class="attachments"><AttachmentList {attachments} /></div>{/if} <AttachmentRefInput
space={message.space}
_class={chunter.class.Comment}
objectId={message._id}
content={message.content}
on:message={onMessageEdit}
/>
{:else}
<div class="text"><MessageViewer message={message.content} /></div>
{#if message.attachments}<div class="attachments"><AttachmentList {attachments} /></div>{/if}
{/if}
{#if reactions || message.replies} {#if reactions || message.replies}
<div class="footer flex-col"> <div class="footer flex-col">
<div> <div>

View File

@ -14,7 +14,7 @@
--> -->
<script lang="ts"> <script lang="ts">
import { Attachment } from '@anticrm/attachment' import { Attachment } from '@anticrm/attachment'
import { AttachmentList } from '@anticrm/attachment-resources' import { AttachmentList, AttachmentRefInput } 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, getCurrentAccount } from '@anticrm/core' import { Ref, WithLookup, getCurrentAccount } from '@anticrm/core'
@ -53,6 +53,13 @@
action: chunter.actionImpl.SubscribeComment action: chunter.actionImpl.SubscribeComment
} as Action) } as Action)
$: isEditing = false;
const editAction = {
label: chunter.string.EditMessage,
action: () => isEditing = true
}
const deleteAction = { const deleteAction = {
label: chunter.string.DeleteMessage, label: chunter.string.DeleteMessage,
action: async () => await client.removeDoc(message._class, message.space, message._id) action: async () => await client.removeDoc(message._class, message.space, message._id)
@ -73,13 +80,28 @@
await impl(message) await impl(message)
} }
})), })),
...(getCurrentAccount()._id === message.createBy ? [deleteAction] : []) ...(getCurrentAccount()._id === message.createBy ? [editAction, deleteAction] : [])
] ]
}, },
ev.target as HTMLElement ev.target as HTMLElement
) )
} }
async function onMessageEdit (event: CustomEvent) {
const { message: newContent, attachments: newAttachments } = event.detail
if (newContent !== message.content || newAttachments !== attachments) {
await client.update(
message,
{
content: newContent,
attachments: newAttachments
}
)
}
isEditing = false
}
$: employee = getEmployee(message) $: employee = getEmployee(message)
function getEmployee (comment: WithLookup<ThreadMessage>): Employee | undefined { function getEmployee (comment: WithLookup<ThreadMessage>): Employee | undefined {
@ -97,8 +119,18 @@
{#if employee}{formatName(employee.name)}{/if} {#if employee}{formatName(employee.name)}{/if}
<span>{getTime(message.createOn)}</span> <span>{getTime(message.createOn)}</span>
</div> </div>
<div class="text"><MessageViewer message={message.content} /></div> {#if isEditing}
{#if message.attachments}<div class="attachments"><AttachmentList {attachments} /></div>{/if} <AttachmentRefInput
space={message.space}
_class={chunter.class.Comment}
objectId={message._id}
content={message.content}
on:message={onMessageEdit}
/>
{:else}
<div class="text"><MessageViewer message={message.content} /></div>
{#if message.attachments}<div class="attachments"><AttachmentList {attachments} /></div>{/if}
{/if}
{#if reactions} {#if reactions}
<div class="footer"> <div class="footer">
<div><Reactions /></div> <div><Reactions /></div>

View File

@ -51,6 +51,7 @@ export default mergeIds(chunterId, chunter, {
New: '' as IntlString, New: '' as IntlString,
GetNewReplies: '' as IntlString, GetNewReplies: '' as IntlString,
TurnOffReplies: '' as IntlString, TurnOffReplies: '' as IntlString,
DeleteMessage: '' as IntlString DeleteMessage: '' as IntlString,
EditMessage: '' as IntlString
} }
}) })