diff --git a/clefincode_chat/__init__.py b/clefincode_chat/__init__.py index 7459b19..19626ee 100644 --- a/clefincode_chat/__init__.py +++ b/clefincode_chat/__init__.py @@ -1 +1 @@ -__version__ = '1.3.907' \ No newline at end of file +__version__ = '1.3.908' \ No newline at end of file diff --git a/clefincode_chat/public/js/components/erpnext_chat_space.js b/clefincode_chat/public/js/components/erpnext_chat_space.js index 5edb2b7..1bad36c 100644 --- a/clefincode_chat/public/js/components/erpnext_chat_space.js +++ b/clefincode_chat/public/js/components/erpnext_chat_space.js @@ -90,6 +90,8 @@ export default class ChatSpace { this.topic_read_only = Boolean(opts.topic_read_only); this.chat_topic_status = opts.chat_topic_status || null; this.reply_to_message_name = null; + this.topicInactiveNoticeDismissed = false; + this.$topicInactiveNotice = null; this.pendingReplies = []; this.searchResults = []; this.currentSearchIndex = -1; @@ -2741,6 +2743,7 @@ async fetch_single_message(messageName) { await this.setup_messages(res.results || []); await this.setup_actions(); await this.applySavedActiveTopic(); + this.checkAndShowTopicInactiveNotice(); this.render(); } catch (error) { console.log(error); @@ -5138,6 +5141,48 @@ isDedicatedTopicContext() { ); } +checkAndShowTopicInactiveNotice() { + if (this.isDedicatedTopicContext()) return; + if (this.topicInactiveNoticeDismissed) return; + + const lastMsg = this.prevMessage; + if (!lastMsg) return; + + const topicName = lastMsg.chat_topic || lastMsg.topic || null; + if (!topicName) return; + + if (this.activeMessageTopic && String(this.activeMessageTopic) === String(topicName)) return; + + const topicSubject = lastMsg.chat_topic_subject || lastMsg.topic_subject || topicName; + this.showTopicInactiveNotice(topicSubject); +} + +showTopicInactiveNotice(topicSubject) { + const $notice = $(` +
+ ${__('No topic selected ')} +
+`); + if (this.$chat_actions && this.$chat_actions.length) { + this.$chat_actions.before($notice); + } else { + this.$chat_space.append($notice); + } + this.$topicInactiveNotice = $notice; +} + +hideTopicInactiveNotice() { + if (this.$topicInactiveNotice) { + this.$topicInactiveNotice.remove(); + this.$topicInactiveNotice = null; + } +} + +dismissTopicInactiveNotice() { + this.topicInactiveNoticeDismissed = true; + this.hideTopicInactiveNotice(); +} + getTopicReferenceTargetForSend() { const isTopicWindow = Boolean( this.is_topic_window || @@ -7457,6 +7502,8 @@ if (!is_deleted && type !== "info-message") { return; } + this.dismissTopicInactiveNotice(); + let content = this.$chat_space.find(".type-message .ql-editor").html(); (this.is_link = null), (this.is_media = null), @@ -8857,7 +8904,7 @@ openMessageActionMenu({ $trigger, messageName, isMyMessage, isTextOnly }) { ` : ""; - if (isMyMessage) { + // if (isMyMessage) { items.push(` - `); - } + // } else if (menuTopicName) { + // items.push(` + // + // `); + // } if (isMyMessage && menuTopicName) { items.push(item({ diff --git a/clefincode_chat/public/js/topic_button.js b/clefincode_chat/public/js/topic_button.js index c752331..2fa2bc7 100644 --- a/clefincode_chat/public/js/topic_button.js +++ b/clefincode_chat/public/js/topic_button.js @@ -41,6 +41,7 @@ console.log("topic_button.js loaded"); function add_topic_chat_button(frm) { if (!frm || !frm.page || !frm.doc) return; + if (frappe.session.user === "Administrator") return; const container = get_action_buttons_container(frm); if (!container.length) return; @@ -236,27 +237,35 @@ async function link_current_doc_to_room(frm, room) { const mention_doctypes = JSON.stringify([current_ref]); - if (!existing_topic) { - const createdTopic = await frappe.call({ - method: "clefincode_chat.api.api_1_3_4.api.create_chat_topic_with_message", - args: { - mention_doctypes, - chat_channel: room, - user_email: frappe.session.user, - user_name: frappe.session.user_fullname || frappe.session.user - } - }); +if (!existing_topic) { + const createdTopic = await frappe.call({ + method: "clefincode_chat.api.api_1_3_4.api.create_chat_topic_with_message", + args: { + mention_doctypes, + chat_channel: room, + user_email: frappe.session.user, + user_name: frappe.session.user_fullname || frappe.session.user + } + }); - return { - room, - chat_topic: - createdTopic.message?.results?.[0]?.name || - createdTopic.message?.name || - null, - mode: "created" - }; + const new_chat_topic = + createdTopic.message?.results?.[0]?.chat_topic || + createdTopic.message?.results?.[0]?.name || + createdTopic.message?.chat_topic || + createdTopic.message?.name || + null; + + if (!new_chat_topic) { + throw new Error("Topic was created but chat_topic was not returned"); } + return { + room, + chat_topic: new_chat_topic, + mode: "created" + }; +} + const refs = get_topic_references(topicRow); @@ -597,10 +606,10 @@ function open_chat_room(profile, chat_status = null) { } - if (window.CCCheckIfChatWindowOpen(profile.room, "room")) { - $(".expand-chat-window[data-id|='" + profile.room + "']").click(); - return; - } +if (!profile.chat_topic && window.CCCheckIfChatWindowOpen(profile.room, "room")) { + $(".expand-chat-window[data-id|='" + profile.room + "']").click(); + return; +} const chat_window = new window.CCChatWindow({ profile: { room: profile.room } diff --git a/setup.py b/setup.py index f49af7b..00298c1 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name="clefincode_chat", - version='1.3.907', + version='1.3.908', description="ERPNext & Frappe Business Chat: A self-hosted communication solution.", author="ClefinCode L.L.C-FZ", author_email="info@clefincode.com",