[mirotalksfu] - improve streamMessage
هذا الالتزام موجود في:
@@ -4400,50 +4400,17 @@ class RoomClient {
|
||||
}
|
||||
|
||||
streamMessage(element, message, speed = 100) {
|
||||
const codeBlockRegex = /```([a-zA-Z0-9]+)?\n([\s\S]*?)```/g;
|
||||
const parts = [];
|
||||
const parts = this.processMessage(message);
|
||||
const words = parts.split(' ');
|
||||
|
||||
let lastIndex = 0;
|
||||
|
||||
message.replace(codeBlockRegex, (match, lang, code, offset) => {
|
||||
if (offset > lastIndex) {
|
||||
parts.push({ type: 'text', value: message.slice(lastIndex, offset) });
|
||||
}
|
||||
parts.push({ type: 'code', lang, value: code });
|
||||
lastIndex = offset + match.length;
|
||||
});
|
||||
|
||||
if (lastIndex < message.length) {
|
||||
parts.push({ type: 'text', value: message.slice(lastIndex) });
|
||||
}
|
||||
|
||||
let index = 0;
|
||||
let textBuffer = '';
|
||||
let wordIndex = 0;
|
||||
|
||||
const interval = setInterval(() => {
|
||||
if (index < parts.length) {
|
||||
const part = parts[index];
|
||||
|
||||
if (part.type === 'text') {
|
||||
const words = part.value.split(' ');
|
||||
if (wordIndex < words.length) {
|
||||
textBuffer += words[wordIndex] + ' ';
|
||||
wordIndex++;
|
||||
element.innerHTML = textBuffer;
|
||||
} else {
|
||||
wordIndex = 0;
|
||||
index++;
|
||||
}
|
||||
} else if (part.type === 'code') {
|
||||
textBuffer += `<pre><code class="language-${part.lang || ''}">${part.value}</code></pre>`;
|
||||
element.innerHTML = textBuffer;
|
||||
index++;
|
||||
}
|
||||
|
||||
if (index % 5 === 0 || index === parts.length) {
|
||||
highlightCodeBlocks(element);
|
||||
}
|
||||
if (wordIndex < words.length) {
|
||||
textBuffer += words[wordIndex] + ' ';
|
||||
element.innerHTML = textBuffer;
|
||||
wordIndex++;
|
||||
} else {
|
||||
clearInterval(interval);
|
||||
highlightCodeBlocks(element);
|
||||
@@ -4462,7 +4429,7 @@ class RoomClient {
|
||||
const codeBlockRegex = /```([a-zA-Z0-9]+)?\n([\s\S]*?)```/g;
|
||||
let parts = [];
|
||||
let lastIndex = 0;
|
||||
|
||||
|
||||
message.replace(codeBlockRegex, (match, lang, code, offset) => {
|
||||
if (offset > lastIndex) {
|
||||
parts.push({ type: 'text', value: message.slice(lastIndex, offset) });
|
||||
@@ -4470,18 +4437,20 @@ class RoomClient {
|
||||
parts.push({ type: 'code', lang, value: code });
|
||||
lastIndex = offset + match.length;
|
||||
});
|
||||
|
||||
|
||||
if (lastIndex < message.length) {
|
||||
parts.push({ type: 'text', value: message.slice(lastIndex) });
|
||||
}
|
||||
|
||||
return parts.map(part => {
|
||||
if (part.type === 'text') {
|
||||
return part.value;
|
||||
} else if (part.type === 'code') {
|
||||
return `<pre><code class="language-${part.lang || ''}">${part.value}</code></pre>`;
|
||||
}
|
||||
}).join('');
|
||||
|
||||
return parts
|
||||
.map((part) => {
|
||||
if (part.type === 'text') {
|
||||
return part.value;
|
||||
} else if (part.type === 'code') {
|
||||
return `<pre><code class="language-${part.lang || ''}">${part.value}</code></pre>`;
|
||||
}
|
||||
})
|
||||
.join('');
|
||||
}
|
||||
|
||||
deleteMessage(id) {
|
||||
|
||||
المرجع في مشكلة جديدة
حظر مستخدم