Skip to content

Commit

Permalink
Fixed issue with submind state display and little performance optimiz…
Browse files Browse the repository at this point in the history
…ations (#128)
  • Loading branch information
NeonKirill authored Jan 5, 2025
1 parent b94ccc4 commit 2dc6d9c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
11 changes: 10 additions & 1 deletion chat_client/static/js/chat_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ const setAllCountersToZero = () => {
*/
const refreshSubmindsCount = (cid) => {
const participantsCountNode = document.getElementById(`participants-count-${cid}`);
if (participantsCountNode && !isEmpty(submindsState)) participantsCountNode.innerText = submindsState["subminds_per_cid"][cid].length;
if (participantsCountNode){
let submindsCount = 0
if (!isEmpty(submindsState)){
submindsCount = submindsState["subminds_per_cid"][cid].filter(submind => {
const connectedSubmind = submindsState.connected_subminds[submind.submind_id];
return connectedSubmind && connectedSubmind.bot_type === "submind" && submind.status === "active";
}).length;
}
participantsCountNode.innerText = submindsCount;
}
}


Expand Down
9 changes: 4 additions & 5 deletions chat_client/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
{% endif %}
<title>{% if title is defined %}{{ title }}{% else %}Klatchat{% endif %}</title>
{% block css_imports %}
<link rel="stylesheet" href="{{ url_for('css', path='libs/bootstrap.min.css') }}"
crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/3.2.1/css/flag-icon.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css">
<link rel="stylesheet" href="{{ url_for('css', path='libs/bootstrap.min.css') }}">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/3.5.0/css/flag-icon.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css">
{% endblock %}
</head>
<body>
Expand All @@ -36,7 +35,7 @@
{% include 'base_footer.html' %}
{% endblock %}
</footer>
<script type="text/javascript" src="{{ url_for('js', path="libs/lazysizes.min.js") }}" async></script>
{# <script type="text/javascript" src="{{ url_for('js', path="libs/lazysizes.min.js") }}" async></script>#}
<script type="text/javascript" src="{{ url_for('js', path="libs/jquery.min.js") }}"></script>
<script type="text/javascript" src="{{ url_for('js', path="libs/popper.min.js") }}"></script>
<script type="text/javascript" src="{{ url_for('js', path="libs/bootstrap.min.js") }}"></script>
Expand Down
19 changes: 13 additions & 6 deletions utils/database_utils/mongo_utils/queries/mongo_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,33 @@ def fetch_message_data(
limit=limit,
creation_time_filter=creation_time_filter,
)

for message in message_data:
message["message_type"] = "plain"

if skin == ConversationSkins.PROMPTS:
detected_prompts = list(
set(item.get("prompt_id") for item in message_data if item.get("prompt_id"))
)
detected_prompts = {
item.get("prompt_id") for item in message_data if item.get("prompt_id")
}

prompt_data = fetch_prompt_data(
cid=conversation_data["_id"], prompt_ids=detected_prompts
cid=conversation_data["_id"],
prompt_ids=list(detected_prompts),
)

if prompt_data:
detected_prompt_ids = []
detected_prompt_ids = set()
for prompt in prompt_data:
prompt["message_type"] = "prompt"
detected_prompt_ids.append(prompt["_id"])
detected_prompt_ids.add(prompt["_id"])

message_data = [
message
for message in message_data
if message.get("prompt_id") not in detected_prompt_ids
]
message_data.extend(prompt_data)

return sorted(message_data, key=lambda shout: int(shout["created_on"]))


Expand Down

0 comments on commit 2dc6d9c

Please sign in to comment.