feat: Friends Sidebar Group By Instance (#1069) (#1087)

* feat: Friends Sidebar Group By Instance

* fix and improve performance of filter data

* rm log
This commit is contained in:
pa
2025-01-22 01:43:58 +09:00
committed by GitHub
parent f27d213a0d
commit fbf4c7cd4b
4 changed files with 187 additions and 26 deletions

View File

@@ -185,6 +185,10 @@ console.log(`isLinux: ${LINUX}`);
this.checkForVRCXUpdate();
}
await AppApi.CheckGameRunning();
this.isSidebarGroupByInstance =
(await configRepository.getBool(
'VRCX_sidebarGroupByInstance'
)) ?? true;
this.isGameNoVR = await configRepository.getBool('isGameNoVR');
await AppApi.SetAppLauncherSettings(
this.enableAppLauncher,
@@ -23108,6 +23112,91 @@ console.log(`isLinux: ${LINUX}`);
return LINUX;
};
// friendsListSiderBar
$app.methods.handleSwitchGroupByInstance = async function () {
this.isSidebarGroupByInstance = !this.isSidebarGroupByInstance;
await configRepository.setBool(
'VRCX_sidebarGroupByInstance',
this.isSidebarGroupByInstance
);
};
// friendsListSidebar
// - SidebarGroupByInstance
$app.data.isSidebarGroupByInstance = true;
$app.computed.onlineFriendsInSameInstance = function () {
const groupedItems = {};
this.onlineFriends.forEach((item) => {
const key = item.ref?.$location.tag;
if (!key || key === 'private' || key === 'offline') return;
if (!groupedItems[key]) {
groupedItems[key] = [];
}
groupedItems[key].push(item);
});
const sortedGroups = [];
for (const group of Object.values(groupedItems)) {
if (group.length > 1) {
sortedGroups.push(
group.sort(
(a, b) => a.ref?.$location_at - b.ref?.$location_at
)
);
}
}
return sortedGroups.sort((a, b) => b.length - a.length);
};
$app.computed.onlineFriendsNotInSameInstance = function () {
const friendsInSameInstance = new Set(
this.onlineFriendsInSameInstance.flat().map((friend) => friend.id)
);
return this.onlineFriends.filter(
(friend) => !friendsInSameInstance.has(friend.id)
);
};
$app.computed.vipFriendsInSameInstance = function () {
const groupedItems = {};
this.vipFriends.forEach((item) => {
const key = item.ref?.$location.tag;
if (!key || key === 'private' || key === 'offline') return;
if (!groupedItems[key]) {
groupedItems[key] = [];
}
groupedItems[key].push(item);
});
const sortedGroups = [];
for (const group of Object.values(groupedItems)) {
if (group.length > 1) {
sortedGroups.push(
group.sort(
(a, b) => a.ref?.$location_at - b.ref?.$location_at
)
);
}
}
return sortedGroups.sort((a, b) => b.length - a.length);
};
$app.computed.vipFriendsNotInSameInstance = function () {
const friendsInSameInstance = new Set(
this.vipFriendsInSameInstance.flat().map((friend) => friend.id)
);
return this.vipFriends.filter(
(friend) => !friendsInSameInstance.has(friend.id)
);
};
// #endregion
// #region | Electron