From d9e0f78a71db1507902ab8a4c7ca175172a4e3d7 Mon Sep 17 00:00:00 2001 From: Janhvi Patil Date: Fri, 19 Jan 2024 18:01:10 +0530 Subject: [PATCH] show 'edited' label when message is edited by user --- .../Renderers/TiptapRenderer/TiptapRenderer.tsx | 7 ++++--- raven/api/raven_message.py | 2 +- .../doctype/raven_message/raven_message.json | 11 +++++++++-- .../doctype/raven_message/raven_message.py | 6 ++++++ types/Messaging/Message.ts | 1 + 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/raven-app/src/components/feature/chat/ChatMessage/Renderers/TiptapRenderer/TiptapRenderer.tsx b/raven-app/src/components/feature/chat/ChatMessage/Renderers/TiptapRenderer/TiptapRenderer.tsx index c3eb82e70..9bcf69740 100644 --- a/raven-app/src/components/feature/chat/ChatMessage/Renderers/TiptapRenderer/TiptapRenderer.tsx +++ b/raven-app/src/components/feature/chat/ChatMessage/Renderers/TiptapRenderer/TiptapRenderer.tsx @@ -1,8 +1,8 @@ -import { EditorContent, EditorContext, EditorProvider, Extension, ReactRenderer, useEditor } from '@tiptap/react' -import { Message, TextMessage } from '../../../../../../../../types/Messaging/Message' +import { EditorContent, EditorContext, useEditor } from '@tiptap/react' +import { TextMessage } from '../../../../../../../../types/Messaging/Message' import { UserFields } from '@/utils/users/UserListProvider' import { BoxProps } from '@radix-ui/themes/dist/cjs/components/box' -import { Box } from '@radix-ui/themes' +import { Box, Text } from '@radix-ui/themes' import Highlight from '@tiptap/extension-highlight' import StarterKit from '@tiptap/starter-kit' import css from 'highlight.js/lib/languages/css' @@ -93,6 +93,7 @@ export const TiptapRenderer = ({ message, user, isScrolling = false, isTruncated editor={editor} readOnly /> {showLinkPreview && } + {message.is_edited === 1 && (edited)} ) diff --git a/raven/api/raven_message.py b/raven/api/raven_message.py index 040c15d4c..8beaf8425 100644 --- a/raven/api/raven_message.py +++ b/raven/api/raven_message.py @@ -95,7 +95,7 @@ def get_messages(channel_id): messages = frappe.db.get_all('Raven Message', filters={'channel_id': channel_id}, fields=['name', 'owner', 'creation', 'modified', 'text', - 'file', 'message_type', 'message_reactions', 'is_reply', 'linked_message', '_liked_by', 'channel_id', 'thumbnail_width', 'thumbnail_height', 'file_thumbnail', 'link_doctype', 'link_document'], + 'file', 'message_type', 'message_reactions', 'is_reply', 'linked_message', '_liked_by', 'channel_id', 'thumbnail_width', 'thumbnail_height', 'file_thumbnail', 'link_doctype', 'link_document', 'is_edited'], order_by='creation asc' ) diff --git a/raven/raven_messaging/doctype/raven_message/raven_message.json b/raven/raven_messaging/doctype/raven_message/raven_message.json index ff7d32024..588fd4c3b 100644 --- a/raven/raven_messaging/doctype/raven_message/raven_message.json +++ b/raven/raven_messaging/doctype/raven_message/raven_message.json @@ -23,7 +23,8 @@ "linked_message", "link_doctype", "link_document", - "content" + "content", + "is_edited" ], "fields": [ { @@ -116,11 +117,17 @@ "fieldtype": "Long Text", "label": "Content", "read_only": 1 + }, + { + "default": "0", + "fieldname": "is_edited", + "fieldtype": "Check", + "label": "Is Edited" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2024-01-19 14:56:44.534433", + "modified": "2024-01-19 17:14:52.266110", "modified_by": "Administrator", "module": "Raven Messaging", "name": "Raven Message", diff --git a/raven/raven_messaging/doctype/raven_message/raven_message.py b/raven/raven_messaging/doctype/raven_message/raven_message.py index baf802442..aacd84101 100644 --- a/raven/raven_messaging/doctype/raven_message/raven_message.py +++ b/raven/raven_messaging/doctype/raven_message/raven_message.py @@ -22,6 +22,7 @@ class RavenMessage(Document): file_thumbnail: DF.Attach | None image_height: DF.Data | None image_width: DF.Data | None + is_edited: DF.Check is_reply: DF.Check json: DF.JSON | None link_doctype: DF.Link | None @@ -41,6 +42,11 @@ def before_validate(self): '\ufeff', '').replace(' ', ' ') except Exception: pass + + if not self.is_new(): + # this is not a new message, so it's a previous message being edited + self.is_edited = True + def validate(self): ''' 1. Message can be created if the channel is open diff --git a/types/Messaging/Message.ts b/types/Messaging/Message.ts index dd516b009..d23b251e1 100644 --- a/types/Messaging/Message.ts +++ b/types/Messaging/Message.ts @@ -14,6 +14,7 @@ export interface BaseMessage { linked_message?: string | null link_doctype?: string link_document?: string + is_edited: 1 | 0 } export interface FileMessage extends BaseMessage {