diff --git a/public/script.js b/public/script.js
index 97fbf15d6..85ed6408b 100644
--- a/public/script.js
+++ b/public/script.js
@@ -733,13 +733,11 @@ function printCharacters() {
// Add to the list
$("#rm_print_characters_block").append(template);
});
- $("#rm_print_characters_block").prepend(`
`);
printTags();
printGroups();
- sortCharactersList();
favsToHotswap();
-
+ sortCharactersList();
}
async function getCharacters() {
diff --git a/public/scripts/group-chats.js b/public/scripts/group-chats.js
index b39a92a3e..b8f24c444 100644
--- a/public/scripts/group-chats.js
+++ b/public/scripts/group-chats.js
@@ -5,7 +5,7 @@ import {
delay,
} from './utils.js';
import { RA_CountCharTokens, humanizedDateTime } from "./RossAscends-mods.js";
-import { sortCharactersList } from './power-user.js';
+import { sortCharactersList, sortGroupMembers } from './power-user.js';
import {
chat,
@@ -201,6 +201,7 @@ async function saveGroupChat(groupId, shouldSaveGroup) {
if (shouldSaveGroup && response.ok) {
await editGroup(groupId);
}
+ sortCharactersList();
}
export async function renameGroupMember(oldAvatar, newAvatar, newName) {
@@ -899,7 +900,7 @@ function select_group_chats(groupId, skipAnimation) {
}
}
- sortCharactersList("#rm_group_add_members .group_member");
+ sortGroupMembers("#rm_group_add_members .group_member");
filterMembersByFavorites(false);
const groupHasMembers = !!$("#rm_group_members").children().length;
@@ -989,7 +990,7 @@ function select_group_chats(groupId, skipAnimation) {
}
}
- sortCharactersList("#rm_group_add_members .group_member");
+ sortGroupMembers("#rm_group_add_members .group_member");
});
}
@@ -1195,10 +1196,12 @@ export async function openGroupChat(groupId, chatId) {
group.past_metadata[previousChat] = Object.assign({}, chat_metadata);
group.chat_id = chatId;
group.chat_metadata = group.past_metadata[chatId] || {};
+ group['date_last_chat'] = Date.now();
updateChatMetadata(group.chat_metadata, true);
await editGroup(groupId, true);
await getGroupChat(groupId);
+ sortCharactersList();
}
export async function renameGroupChat(groupId, oldChatId, newChatId) {
diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js
index e053f615e..627330690 100644
--- a/public/scripts/power-user.js
+++ b/public/scripts/power-user.js
@@ -8,11 +8,15 @@ import {
reloadCurrentChat,
getRequestHeaders,
} from "../script.js";
+import {
+ groups,
+} from "./group-chats.js";
export {
loadPowerUserSettings,
collapseNewlines,
playMessageSound,
+ sortGroupMembers,
sortCharactersList,
fixMarkdown,
power_user,
@@ -409,19 +413,46 @@ function loadPowerUserSettings(settings, data) {
reloadMarkdownProcessor(power_user.render_formulas);
}
-function sortCharactersList(selector = '.character_select') {
- const sortFunc = (a, b) => power_user.sort_order == 'asc' ? compareFunc(a, b) : compareFunc(b, a);
- const compareFunc = (first, second) => {
- switch (power_user.sort_rule) {
- case 'boolean':
- return Number(first[power_user.sort_field] == "true") - Number(second[power_user.sort_field] == "true");
- default:
- return typeof first[power_user.sort_field] == "string"
- ? first[power_user.sort_field].localeCompare(second[power_user.sort_field])
- : first[power_user.sort_field] - second[power_user.sort_field];
- }
- };
+const sortFunc = (a, b) => power_user.sort_order == 'asc' ? compareFunc(a, b) : compareFunc(b, a);
+const compareFunc = (first, second) => {
+ switch (power_user.sort_rule) {
+ case 'boolean':
+ return Number(first[power_user.sort_field] == "true") - Number(second[power_user.sort_field] == "true");
+ default:
+ return typeof first[power_user.sort_field] == "string"
+ ? first[power_user.sort_field].localeCompare(second[power_user.sort_field])
+ : first[power_user.sort_field] - second[power_user.sort_field];
+ }
+};
+function sortCharactersList() {
+ const arr1 = groups.map(x => ({
+ item: x,
+ id: x.id,
+ selector: '.group_select',
+ attribute: 'grid',
+ }))
+ const arr2 = characters.map((x, index) => ({
+ item: x,
+ id: index,
+ selector: '.character_select',
+ attribute: 'chid',
+ }));
+
+ const array = [...arr1, ...arr2];
+
+ if (power_user.sort_field == undefined || array.length === 0) {
+ return;
+ }
+
+ let orderedList = array.slice().sort((a, b) => sortFunc(a.item, b.item));
+
+ for (const item of array) {
+ $(`${item.selector}[${item.attribute}="${item.id}"]`).css({ 'order': orderedList.indexOf(item) });
+ }
+}
+
+function sortGroupMembers(selector) {
if (power_user.sort_field == undefined || characters.length === 0) {
return;
}