Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clefincode_chat/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.3.907'
__version__ = '1.3.908'
87 changes: 67 additions & 20 deletions clefincode_chat/public/js/components/erpnext_chat_space.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 = $(`
<div class="topic-inactive-notice" style="font-size:12px;opacity:0.6;text-align:center;padding:4px 8px;background:var(--bg-light,#f9f9f9);border-top:1px solid var(--border-color,#eee);">
${__('No topic selected ')}
</div>
`);
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 ||
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -8857,7 +8904,7 @@ openMessageActionMenu({ $trigger, messageName, isMyMessage, isTextOnly }) {
`
: "";

if (isMyMessage) {
// if (isMyMessage) {
items.push(`
<div class="menu-item relink-topic-menu-row ${menuTopicName ? "" : "no-linked-topic"}" role="group">
<button
Expand All @@ -8873,25 +8920,25 @@ openMessageActionMenu({ $trigger, messageName, isMyMessage, isTextOnly }) {
${openTopicButtonHtml}
</div>
`);
} else if (menuTopicName) {
items.push(`
<div class="menu-item relink-topic-menu-row" role="group">
<button
type="button"
class="relink-topic-menu-main topic-open-window-btn message-topic-open-action"
data-message-name="${safeMessageName}"
data-topic-name="${safeMenuTopicName}"
data-topic-subject="${safeMenuTopicSubject}"
data-topic-color="${safeMenuTopicColor}"
title="${__("Open topic in new window")}"
aria-label="${__("Open topic in new window")}"
>
${icon("relink")}
<span class="menu-label">${__("Open Topic")}</span>
</button>
</div>
`);
}
// } else if (menuTopicName) {
// items.push(`
// <div class="menu-item relink-topic-menu-row" role="group">
// <button
// type="button"
// class="relink-topic-menu-main topic-open-window-btn message-topic-open-action"
// data-message-name="${safeMessageName}"
// data-topic-name="${safeMenuTopicName}"
// data-topic-subject="${safeMenuTopicSubject}"
// data-topic-color="${safeMenuTopicColor}"
// title="${__("Open topic in new window")}"
// aria-label="${__("Open topic in new window")}"
// >
// ${icon("relink")}
// <span class="menu-label">${__("Open Topic")}</span>
// </button>
// </div>
// `);
// }

if (isMyMessage && menuTopicName) {
items.push(item({
Expand Down
53 changes: 31 additions & 22 deletions clefincode_chat/public/js/topic_button.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);


Expand Down Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down