Skip to content

Commit

Permalink
show 'edited' label when message is edited by user
Browse files Browse the repository at this point in the history
  • Loading branch information
janhvipatil committed Jan 19, 2024
1 parent 89d843f commit d9e0f78
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -93,6 +93,7 @@ export const TiptapRenderer = ({ message, user, isScrolling = false, isTruncated
editor={editor}
readOnly />
{showLinkPreview && <LinkPreview isScrolling={isScrolling} />}
{message.is_edited === 1 && <Text size='1' className='text-gray-10'>(edited)</Text>}
</EditorContext.Provider>
</Box>
)
Expand Down
2 changes: 1 addition & 1 deletion raven/api/raven_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)

Expand Down
11 changes: 9 additions & 2 deletions raven/raven_messaging/doctype/raven_message/raven_message.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"linked_message",
"link_doctype",
"link_document",
"content"
"content",
"is_edited"
],
"fields": [
{
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions raven/raven_messaging/doctype/raven_message/raven_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,6 +42,11 @@ def before_validate(self):
'\ufeff', '').replace('&nbsp;', ' ')
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
Expand Down
1 change: 1 addition & 0 deletions types/Messaging/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d9e0f78

Please sign in to comment.