Make printMessages async

This commit is contained in:
Cohee 2023-09-08 12:10:41 +03:00
parent 96df705409
commit 02bdd56e20
2 changed files with 13 additions and 12 deletions

View File

@ -1144,10 +1144,11 @@ async function replaceCurrentChat() {
} }
} }
function printMessages() { async function printMessages() {
chat.forEach(function (item, i, arr) { for (let i = 0; i < chat.length; i++) {
addOneMessage(item, { scroll: i === arr.length - 1 }); const item = chat[i];
}); addOneMessage(item, { scroll: i === chat.length - 1 });
}
if (power_user.lazy_load > 0) { if (power_user.lazy_load > 0) {
const height = $('#chat').height(); const height = $('#chat').height();
@ -1190,7 +1191,7 @@ export async function reloadCurrentChat() {
} }
else { else {
resetChatState(); resetChatState();
printMessages(); await printMessages();
} }
await eventSource.emit(event_types.CHAT_CHANGED, getCurrentChatId()); await eventSource.emit(event_types.CHAT_CHANGED, getCurrentChatId());
@ -4448,7 +4449,7 @@ async function getChatResult() {
chat.push(message); chat.push(message);
await saveChatConditional(); await saveChatConditional();
} }
printMessages(); await printMessages();
select_selected_character(this_chid); select_selected_character(this_chid);
await eventSource.emit(event_types.CHAT_CHANGED, (getCurrentChatId())); await eventSource.emit(event_types.CHAT_CHANGED, (getCurrentChatId()));
@ -5010,12 +5011,12 @@ async function saveSettings(type) {
dataType: "json", dataType: "json",
contentType: "application/json", contentType: "application/json",
//processData: false, //processData: false,
success: function (data) { success: async function (data) {
//online_status = data.result; //online_status = data.result;
eventSource.emit(event_types.SETTINGS_UPDATED); eventSource.emit(event_types.SETTINGS_UPDATED);
if (type == "change_name") { if (type == "change_name") {
clearChat(); clearChat();
printMessages(); await printMessages();
} }
}, },
error: function (jqXHR, exception) { error: function (jqXHR, exception) {
@ -6289,7 +6290,7 @@ async function createOrEditCharacter(e) {
await eventSource.emit(event_types.MESSAGE_RECEIVED, (chat.length - 1)); await eventSource.emit(event_types.MESSAGE_RECEIVED, (chat.length - 1));
clearChat(); clearChat();
printMessages(); await printMessages();
await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, (chat.length - 1)); await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, (chat.length - 1));
await saveChatConditional(); await saveChatConditional();
} }
@ -6918,7 +6919,7 @@ export async function deleteCharacter(name, avatar) {
delete tag_map[avatar]; delete tag_map[avatar];
await getCharacters(); await getCharacters();
select_rm_info("char_delete", name); select_rm_info("char_delete", name);
printMessages(); await printMessages();
saveSettingsDebounced(); saveSettingsDebounced();
} }

View File

@ -166,7 +166,7 @@ export async function getGroupChat(groupId) {
for (let key of data) { for (let key of data) {
chat.push(key); chat.push(key);
} }
printMessages(); await printMessages();
} else { } else {
sendSystemMessage(system_message_types.GROUP, '', { isSmallSys: true }); sendSystemMessage(system_message_types.GROUP, '', { isSmallSys: true });
if (group && Array.isArray(group.members)) { if (group && Array.isArray(group.members)) {
@ -832,7 +832,7 @@ async function deleteGroup(id) {
delete tag_map[id]; delete tag_map[id];
resetChatState(); resetChatState();
clearChat(); clearChat();
printMessages(); await printMessages();
await getCharacters(); await getCharacters();
select_rm_info("group_delete", id); select_rm_info("group_delete", id);