Skip to content

Commit 006e341

Browse files
committed
Mobile: display assistant name
1 parent e42e297 commit 006e341

File tree

3 files changed

+6
-17
lines changed

3 files changed

+6
-17
lines changed

classes/output/mobile.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,28 +67,15 @@ public static function get_block_content($args) {
6767
}
6868
$assistantname = format_string($assistantname, true, ['context' => $context]);
6969
$username = format_string($username, true, ['context' => $context]);
70-
$content = new \stdClass;
71-
$content->text = '
72-
<script>
73-
var assistantName = "' . $assistantname . '";
74-
var userName = "' . $username . '";
75-
</script>
76-
77-
<style>
78-
' . $showlabelscss . '
79-
.openai_message.user:before {
80-
content: "' . $username . '";
81-
}
82-
.openai_message.bot:before {
83-
content: "' . $assistantname . '";
84-
}
85-
</style>';
8670

8771
$contextdata = [
8872
'logging_enabled' => get_config('block_openai_chat', 'logging'),
8973
'pix_popout' => '/blocks/openai_chat/pix/arrow-up-right-from-square.svg',
9074
'pix_arrow_right' => '/blocks/openai_chat/pix/arrow-right.svg',
9175
'pix_refresh' => '/blocks/openai_chat/pix/refresh.svg',
76+
'username' => $username,
77+
'assistantname' => $assistantname,
78+
'showlabelscss' => $showlabelscss,
9279
'contextid' => $context->id,
9380
];
9481

mobile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ this.update_history = function(msg) {
2424
let container = document.querySelector('#openai_chat_log');
2525
container.scrollTop = lq.offsetTop;
2626
}
27-
let newHtml = '<div class="openai_message bot"><span><p>' + msg + '</p></span></div>';
27+
let assistantname = document.getElementById('openai_assistantname');
28+
let newHtml = '<span style="color: gray; margin-bottom: .2em">' + assistantname.innerHTML + '</span><div class="openai_message bot"><span><p>' + msg + '</p></span></div>';
2829

2930
document.querySelector('.chat-loading').remove();
3031
document.getElementById('openai_chat_log').insertAdjacentHTML('beforeend', newHtml);

templates/mobile.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@
5050
<img style="transform: scale(1.3)" src="<%config.wwwroot%><% pix_refresh %>" class='openai_input_refresh_btn_icon' alt="<%#str%>new_chat, block_openai_chat <%/str%>" />
5151
</ion-button>
5252
</div>
53+
<span style="display: none" id="openai_assistantname"><% assistantname %></span>
5354
</div>

0 commit comments

Comments
 (0)