diff --git a/frontend/src/components/feature/chat/ChatStream/useChatStream.ts b/frontend/src/components/feature/chat/ChatStream/useChatStream.ts
index 49a55b201..b6dd1c231 100644
--- a/frontend/src/components/feature/chat/ChatStream/useChatStream.ts
+++ b/frontend/src/components/feature/chat/ChatStream/useChatStream.ts
@@ -462,7 +462,9 @@ const useChatStream = (channelID: string, scrollRef: MutableRefObject 0
@@ -61,6 +69,40 @@ def after_delete(self):
)
frappe.db.set_value("Raven Channel Member", first_member.name, "is_admin", 1)
+ first_member_name = frappe.get_cached_value("Raven User", first_member.user_id, "full_name")
+
+ # Add a system message to the channel mentioning the new admin
+ frappe.get_doc(
+ {
+ "doctype": "Raven Message",
+ "channel_id": self.channel_id,
+ "message_type": "System",
+ "text": f"{member_name} was removed by {current_user_name} and {first_member_name} is the new admin of this channel.",
+ }
+ ).insert()
+ else:
+ # If the member who left is the current user, then add a system message to the channel mentioning that the user left
+ if member_name == current_user_name:
+ # Add a system message to the channel mentioning the member who left
+ frappe.get_doc(
+ {
+ "doctype": "Raven Message",
+ "channel_id": self.channel_id,
+ "message_type": "System",
+ "text": f"{member_name} left.",
+ }
+ ).insert(ignore_permissions=True)
+ else:
+ # Add a system message to the channel mentioning the member who left
+ frappe.get_doc(
+ {
+ "doctype": "Raven Message",
+ "channel_id": self.channel_id,
+ "message_type": "System",
+ "text": f"{current_user_name} removed {member_name}.",
+ }
+ ).insert()
+
def on_trash(self):
# if the leaving member is admin, then the first member becomes new admin
if (
@@ -119,6 +161,33 @@ def after_insert(self):
if not is_direct_message and self.allow_notifications:
subscribe_user_to_topic(self.channel_id, self.user_id)
+ if not is_direct_message:
+
+ is_thread = self.is_thread()
+
+ # Send a system message to the channel mentioning the member who joined
+ if not is_thread:
+ member_name = frappe.get_cached_value("Raven User", self.user_id, "full_name")
+ if self.user_id == frappe.session.user:
+ frappe.get_doc(
+ {
+ "doctype": "Raven Message",
+ "channel_id": self.channel_id,
+ "message_type": "System",
+ "text": f"{member_name} joined.",
+ }
+ ).insert()
+ else:
+ current_user_name = frappe.get_cached_value("Raven User", frappe.session.user, "full_name")
+ frappe.get_doc(
+ {
+ "doctype": "Raven Message",
+ "channel_id": self.channel_id,
+ "message_type": "System",
+ "text": f"{current_user_name} added {member_name}.",
+ }
+ ).insert()
+
def on_update(self):
"""
Check if the notification preference is changed and update the subscription
@@ -134,9 +203,27 @@ def on_update(self):
else:
unsubscribe_user_to_topic(self.channel_id, self.user_id)
+ if self.has_value_changed("is_admin") and not self.flags.in_insert and not self.is_thread():
+ # Send a system message to the channel mentioning the member who became admin
+ member_name = frappe.get_cached_value("Raven User", self.user_id, "full_name")
+ text = (
+ f"{member_name} is now an admin." if self.is_admin else f"{member_name} is no longer an admin."
+ )
+ frappe.get_doc(
+ {
+ "doctype": "Raven Message",
+ "channel_id": self.channel_id,
+ "message_type": "System",
+ "text": text,
+ }
+ ).insert()
+
def get_admin_count(self):
return frappe.db.count("Raven Channel Member", {"channel_id": self.channel_id, "is_admin": 1})
+ def is_thread(self):
+ return frappe.get_cached_value("Raven Channel", self.channel_id, "is_thread")
+
def on_doctype_update():
"""
diff --git a/raven/raven_messaging/doctype/raven_message/raven_message.json b/raven/raven_messaging/doctype/raven_message/raven_message.json
index 860d1b08a..19f5e3dcc 100644
--- a/raven/raven_messaging/doctype/raven_message/raven_message.json
+++ b/raven/raven_messaging/doctype/raven_message/raven_message.json
@@ -65,7 +65,7 @@
"fieldname": "message_type",
"fieldtype": "Select",
"label": "Message Type",
- "options": "Text\nImage\nFile\nPoll"
+ "options": "Text\nImage\nFile\nPoll\nSystem"
},
{
"fieldname": "message_reactions",
@@ -191,7 +191,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
- "modified": "2024-08-16 16:09:36.292391",
+ "modified": "2024-10-11 18:42:44.984706",
"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 12b078ee3..4d40b27be 100644
--- a/raven/raven_messaging/doctype/raven_message/raven_message.py
+++ b/raven/raven_messaging/doctype/raven_message/raven_message.py
@@ -45,7 +45,7 @@ class RavenMessage(Document):
linked_message: DF.Link | None
mentions: DF.Table[RavenMention]
message_reactions: DF.JSON | None
- message_type: DF.Literal["Text", "Image", "File", "Poll"]
+ message_type: DF.Literal["Text", "Image", "File", "Poll", "System"]
poll_id: DF.Link | None
replied_message_details: DF.JSON | None
text: DF.LongText | None
@@ -55,7 +55,7 @@ class RavenMessage(Document):
def before_validate(self):
try:
- if self.text:
+ if self.text and not self.message_type == "System":
content = html2text(self.text)
# Remove trailing new line characters and white spaces
self.content = content.rstrip()
diff --git a/types/Messaging/Message.ts b/types/Messaging/Message.ts
index 37c5c7f29..0a50a860a 100644
--- a/types/Messaging/Message.ts
+++ b/types/Messaging/Message.ts
@@ -1,4 +1,4 @@
-export type Message = FileMessage | TextMessage | ImageMessage | PollMessage
+export type Message = FileMessage | TextMessage | ImageMessage | PollMessage | SystemMessage
export interface BaseMessage {
name: string,
@@ -7,7 +7,7 @@ export interface BaseMessage {
channel_id: string,
creation: string,
modified: string,
- message_type: 'Text' | 'File' | 'Image' | 'Poll',
+ message_type: 'Text' | 'File' | 'Image' | 'Poll' | 'System',
message_reactions?: string | null,
is_continuation: 1 | 0
is_reply: 1 | 0
@@ -53,6 +53,11 @@ export interface PollMessage extends BaseMessage {
content?: string
}
+export interface SystemMessage extends BaseMessage {
+ message_type: 'System',
+ text: string,
+}
+
export type DateBlock = {
block_type: 'date',
data: string