refactor friends sort

This commit is contained in:
pa
2026-03-14 20:57:23 +09:00
parent 84f46a5645
commit a8d1b7a905
8 changed files with 477 additions and 193 deletions

View File

@@ -371,10 +371,16 @@
return ids;
});
const vipFriendsByGroupStatus = computed(() => {
const visibleFavoriteOnlineFriends = computed(() => {
const selectedGroups = sidebarFavoriteGroups.value;
if (selectedGroups.length === 0) return allFavoriteOnlineFriends.value;
return allFavoriteOnlineFriends.value.filter((f) => displayedVipIds.value.has(f.id));
if (selectedGroups.length === 0) {
return allFavoriteOnlineFriends.value;
}
return allFavoriteOnlineFriends.value.filter((friend) => displayedVipIds.value.has(friend.id));
});
const vipFriendsByGroupStatus = computed(() => {
return visibleFavoriteOnlineFriends.value;
});
const onlineFriendsByGroupStatus = computed(() => {
@@ -382,10 +388,11 @@
if (selectedGroups.length === 0) {
return onlineFriends.value.filter((f) => !allFavoriteFriendIds.value.has(f.id));
}
const nonFavOnline = onlineFriends.value.filter((f) => !displayedVipIds.value.has(f.id));
const selectedIds = displayedVipIds.value;
const nonFavOnline = onlineFriends.value.filter((f) => !selectedIds.has(f.id));
const existingIds = new Set(nonFavOnline.map((f) => f.id));
const unselectedGroupFriends = allFavoriteOnlineFriends.value.filter(
(f) => !displayedVipIds.value.has(f.id) && !existingIds.has(f.id)
(f) => !selectedIds.has(f.id) && !existingIds.has(f.id)
);
return [...nonFavOnline, ...unselectedGroupFriends].sort(getFriendsSortFunction(sidebarSortMethods.value));
});
@@ -415,7 +422,7 @@
const result = [];
for (const { key, groupName, memberIds } of groups) {
const filteredFriends = allFavoriteOnlineFriends.value.filter((friend) => memberIds.has(friend.id));
const filteredFriends = visibleFavoriteOnlineFriends.value.filter((friend) => memberIds.has(friend.id));
if (filteredFriends.length > 0) {
result.push({ key, groupName, friends: filteredFriends });
}
@@ -432,6 +439,15 @@
});
});
const searchableEntries = computed(() =>
uniqueEntries([
...toEntries(allFavoriteOnlineFriends.value),
...toEntries(onlineFriends.value),
...toEntries(activeFriends.value),
...toEntries(offlineFriends.value)
])
);
/**
*
* @param groupKey
@@ -446,14 +462,7 @@
const filteredFriends = computed(() => {
if (normalizedSearchTerm.value) {
const pools = [
...toEntries(allFavoriteOnlineFriends.value),
...toEntries(onlineFriends.value),
...toEntries(activeFriends.value),
...toEntries(offlineFriends.value)
];
return uniqueEntries(pools).filter(({ friend }) => {
return searchableEntries.value.filter(({ friend }) => {
const haystack =
`${friend.displayName ?? friend.name ?? ''} ${friend.signature ?? ''} ${friend.worldName ?? ''}`.toLowerCase();
return haystack.includes(normalizedSearchTerm.value);

View File

@@ -275,6 +275,36 @@
const shouldHideSameInstance = computed(() => isSidebarGroupByInstance.value && isHideFriendsInSameInstance.value);
const selectedFavoriteGroupIds = computed(() => {
const selectedGroups = sidebarFavoriteGroups.value;
const hasFilter = selectedGroups.length > 0;
if (!hasFilter) {
return allFavoriteFriendIds.value;
}
const ids = new Set();
const remoteFriendsByGroup = groupedByGroupKeyFavoriteFriends.value;
for (const key of selectedGroups) {
if (key.startsWith('local:')) {
const groupName = key.slice(6);
const userIds = localFriendFavorites.value?.[groupName];
if (userIds) {
for (const id of userIds) ids.add(id);
}
} else if (remoteFriendsByGroup[key]) {
for (const friend of remoteFriendsByGroup[key]) ids.add(friend.id);
}
}
return ids;
});
const visibleFavoriteOnlineFriends = computed(() => {
const filtered = allFavoriteOnlineFriends.value.filter((friend) =>
selectedFavoriteGroupIds.value.has(friend.id)
);
return excludeSameInstance(filtered);
});
/**
*
* @param list
@@ -293,23 +323,11 @@
return excludeSameInstance(onlineFriends.value.filter((f) => !allFavoriteFriendIds.value.has(f.id)));
}
// When group filter is active, friends in unselected groups should appear in the online list
const displayedVipIds = new Set();
const remoteFriendsByGroup = groupedByGroupKeyFavoriteFriends.value;
for (const key of selectedGroups) {
if (key.startsWith('local:')) {
const groupName = key.slice(6);
const userIds = localFriendFavorites.value?.[groupName];
if (userIds) {
for (const id of userIds) displayedVipIds.add(id);
}
} else if (remoteFriendsByGroup[key]) {
for (const f of remoteFriendsByGroup[key]) displayedVipIds.add(f.id);
}
}
const nonFavOnline = onlineFriends.value.filter((f) => !displayedVipIds.has(f.id));
const selectedIds = selectedFavoriteGroupIds.value;
const nonFavOnline = onlineFriends.value.filter((f) => !selectedIds.has(f.id));
const existingIds = new Set(nonFavOnline.map((f) => f.id));
const unselectedGroupFriends = allFavoriteOnlineFriends.value.filter(
(f) => !displayedVipIds.has(f.id) && !existingIds.has(f.id)
(f) => !selectedIds.has(f.id) && !existingIds.has(f.id)
);
return excludeSameInstance(
[...nonFavOnline, ...unselectedGroupFriends].sort(getFriendsSortFunction(sidebarSortMethods.value))
@@ -317,26 +335,7 @@
});
const vipFriendsByGroupStatus = computed(() => {
const selectedGroups = sidebarFavoriteGroups.value;
const hasFilter = selectedGroups.length > 0;
if (!hasFilter) {
return excludeSameInstance(allFavoriteOnlineFriends.value);
}
// Filter to only include VIP friends whose group key is in selectedGroups
const allowedIds = new Set();
const remoteFriendsByGroup = groupedByGroupKeyFavoriteFriends.value;
for (const key of selectedGroups) {
if (key.startsWith('local:')) {
const groupName = key.slice(6);
const userIds = localFriendFavorites.value?.[groupName];
if (userIds) {
for (const id of userIds) allowedIds.add(id);
}
} else if (remoteFriendsByGroup[key]) {
for (const f of remoteFriendsByGroup[key]) allowedIds.add(f.id);
}
}
return excludeSameInstance(allFavoriteOnlineFriends.value.filter((f) => allowedIds.has(f.id)));
return visibleFavoriteOnlineFriends.value;
});
// VIP friends divide by group
@@ -369,9 +368,7 @@
// Filter vipFriends per group, preserving vipFriends sort order
const result = [];
for (const { key, groupName, memberIds } of groups) {
const filteredFriends = excludeSameInstance(
allFavoriteOnlineFriends.value.filter((friend) => memberIds.has(friend.id))
);
const filteredFriends = visibleFavoriteOnlineFriends.value.filter((friend) => memberIds.has(friend.id));
if (filteredFriends.length > 0) {
result.push(filteredFriends.map((item) => ({ groupName, key, ...item })));
}