Favorites clean up

This commit is contained in:
Natsumi
2025-11-01 17:44:06 +11:00
parent 23b7c45951
commit f875aaf304
3 changed files with 32 additions and 132 deletions
+31 -129
View File
@@ -245,43 +245,20 @@ export const useFavoriteStore = defineStore('Favorite', () => {
} }
function handleFavorite(args) { function handleFavorite(args) {
const fav = applyFavoriteCached(args.json); args.ref = applyFavoriteCached(args.json);
if (!fav.$isDeleted) {
args.ref = fav;
}
applyFavorite(args.ref.type, args.ref.favoriteId, args.sortTop); applyFavorite(args.ref.type, args.ref.favoriteId, args.sortTop);
friendStore.updateFriend(args.ref.favoriteId); friendStore.updateFriend(args.ref.favoriteId);
const { ref } = args; const { ref } = args;
const userDialog = userStore.userDialog; const userDialog = userStore.userDialog;
if ( if (userDialog.visible && ref.favoriteId === userDialog.id) {
!(
userDialog.visible === false ||
ref.$isDeleted ||
ref.favoriteId !== userDialog.id
)
) {
userDialog.isFavorite = true; userDialog.isFavorite = true;
} }
const worldDialog = worldStore.worldDialog; const worldDialog = worldStore.worldDialog;
if ( if (worldDialog.visible && ref.favoriteId === worldDialog.id) {
!(
worldDialog.visible === false ||
ref.$isDeleted ||
ref.favoriteId !== worldDialog.id
)
) {
worldDialog.isFavorite = true; worldDialog.isFavorite = true;
} }
const avatarDialog = avatarStore.avatarDialog; const avatarDialog = avatarStore.avatarDialog;
if ( if (avatarDialog.visible && ref.favoriteId === avatarDialog.id) {
!(
avatarDialog.visible === false ||
ref.$isDeleted ||
ref.favoriteId !== avatarDialog.id
)
) {
avatarDialog.isFavorite = true; avatarDialog.isFavorite = true;
} }
} }
@@ -291,25 +268,18 @@ export const useFavoriteStore = defineStore('Favorite', () => {
if (typeof ref === 'undefined') { if (typeof ref === 'undefined') {
return; return;
} }
// if (ref.$isDeleted) {
// return;
// }
args.ref = ref; args.ref = ref;
handleFavoriteAtDelete(ref); handleFavoriteAtDelete(ref);
} }
function handleFavoriteGroup(args) { function handleFavoriteGroup(args) {
const ref = applyFavoriteGroup(args.json); args.ref = applyFavoriteGroup(args.json);
if (ref.$isDeleted) {
return;
}
args.ref = ref;
} }
function handleFavoriteGroupClear(args) { function handleFavoriteGroupClear(args) {
const key = `${args.params.type}:${args.params.group}`; const key = `${args.params.type}:${args.params.group}`;
for (const ref of cachedFavorites.values()) { for (const ref of cachedFavorites.values()) {
if (ref.$isDeleted || ref.$groupKey !== key) { if (ref.$groupKey !== key) {
continue; continue;
} }
handleFavoriteAtDelete(ref); handleFavoriteAtDelete(ref);
@@ -334,48 +304,29 @@ export const useFavoriteStore = defineStore('Favorite', () => {
} }
} }
function expireFavorites() {
friendStore.localFavoriteFriends.clear();
cachedFavorites.clear();
state.favoriteObjects.clear();
state.favoriteFriends_ = [];
state.favoriteWorlds_ = [];
state.favoriteAvatars_ = [];
}
function handleFavoriteAtDelete(ref) { function handleFavoriteAtDelete(ref) {
ref.$isDeleted = true; const favorite = state.favoriteObjects.get(ref.favoriteId);
removeFromArray(state.favoriteFriends_, favorite);
removeFromArray(state.favoriteWorlds_, favorite);
removeFromArray(state.favoriteAvatars_, favorite);
cachedFavorites.delete(ref.id); cachedFavorites.delete(ref.id);
state.favoriteObjects.delete(ref.favoriteId);
friendStore.localFavoriteFriends.delete(ref.favoriteId); friendStore.localFavoriteFriends.delete(ref.favoriteId);
applyFavorite(ref.type, ref.favoriteId);
friendStore.updateFriend(ref.favoriteId); friendStore.updateFriend(ref.favoriteId);
friendStore.updateSidebarFavorites(); friendStore.updateSidebarFavorites();
const userDialog = userStore.userDialog; const userDialog = userStore.userDialog;
if ( if (userDialog.visible && userDialog.id === ref.favoriteId) {
!(userDialog.visible === false || userDialog.id !== ref.favoriteId)
) {
userDialog.isFavorite = false; userDialog.isFavorite = false;
} }
const worldDialog = worldStore.worldDialog; const worldDialog = worldStore.worldDialog;
if ( if (worldDialog.visible && worldDialog.id === ref.favoriteId) {
!(
worldDialog.visible === false ||
worldDialog.id !== ref.favoriteId
)
) {
worldDialog.isFavorite = localWorldFavoritesList.value.includes( worldDialog.isFavorite = localWorldFavoritesList.value.includes(
worldDialog.id worldDialog.id
); );
} }
const avatarDialog = avatarStore.avatarDialog; const avatarDialog = avatarStore.avatarDialog;
if ( if (avatarDialog.visible && avatarDialog.id === ref.favoriteId) {
!(
avatarDialog.visible === false ||
avatarDialog.id !== ref.favoriteId
)
) {
avatarDialog.isFavorite = false; avatarDialog.isFavorite = false;
} }
} }
@@ -520,16 +471,6 @@ export const useFavoriteStore = defineStore('Favorite', () => {
} }
} }
} }
if (typeof favorite === 'undefined' && typeof ctx !== 'undefined') {
state.favoriteObjects.delete(objectId);
if (type === 'friend') {
removeFromArray(state.favoriteFriends_, ctx);
} else if (type === 'world') {
removeFromArray(state.favoriteWorlds_, ctx);
} else if (type === 'avatar') {
removeFromArray(state.favoriteAvatars_, ctx);
}
}
} }
function refreshFavoriteGroups() { function refreshFavoriteGroups() {
@@ -537,7 +478,6 @@ export const useFavoriteStore = defineStore('Favorite', () => {
return; return;
} }
isFavoriteGroupLoading.value = true; isFavoriteGroupLoading.value = true;
expireFavoriteGroups();
processBulk({ processBulk({
fn: favoriteRequest.getFavoriteGroups, fn: favoriteRequest.getFavoriteGroups,
N: -1, N: -1,
@@ -557,7 +497,6 @@ export const useFavoriteStore = defineStore('Favorite', () => {
}, },
done(ok) { done(ok) {
if (ok) { if (ok) {
deleteExpiredFavoriteGroups();
buildFavoriteGroups(); buildFavoriteGroups();
} }
isFavoriteGroupLoading.value = false; isFavoriteGroupLoading.value = false;
@@ -565,22 +504,6 @@ export const useFavoriteStore = defineStore('Favorite', () => {
}); });
} }
function expireFavoriteGroups() {
for (const key in cachedFavoriteGroups.value) {
cachedFavoriteGroups.value[key].$isExpired = true;
}
}
function deleteExpiredFavoriteGroups() {
for (const key in cachedFavoriteGroups.value) {
const ref = cachedFavoriteGroups.value[key];
if (ref.$isDeleted || ref.$isExpired === false) {
continue;
}
ref.$isDeleted = true;
}
}
function buildFavoriteGroups() { function buildFavoriteGroups() {
let group; let group;
let groups; let groups;
@@ -639,9 +562,6 @@ export const useFavoriteStore = defineStore('Favorite', () => {
// assign the same name first // assign the same name first
for (const key in cachedFavoriteGroups.value) { for (const key in cachedFavoriteGroups.value) {
const ref = cachedFavoriteGroups.value[key]; const ref = cachedFavoriteGroups.value[key];
if (ref.$isDeleted) {
continue;
}
groups = types[ref.type]; groups = types[ref.type];
if (typeof groups === 'undefined') { if (typeof groups === 'undefined') {
continue; continue;
@@ -661,7 +581,7 @@ export const useFavoriteStore = defineStore('Favorite', () => {
for (const key in cachedFavoriteGroups.value) { for (const key in cachedFavoriteGroups.value) {
const ref = cachedFavoriteGroups.value[key]; const ref = cachedFavoriteGroups.value[key];
if (ref.$isDeleted || assigns.has(ref.id)) { if (assigns.has(ref.id)) {
continue; continue;
} }
groups = types[ref.type]; groups = types[ref.type];
@@ -682,9 +602,6 @@ export const useFavoriteStore = defineStore('Favorite', () => {
// update favorites // update favorites
for (ref of cachedFavorites.values()) { for (ref of cachedFavorites.values()) {
if (ref.$isDeleted) {
continue;
}
group = cachedFavoriteGroupsByTypeName.value[ref.$groupKey]; group = cachedFavoriteGroupsByTypeName.value[ref.$groupKey];
if (typeof group === 'undefined') { if (typeof group === 'undefined') {
continue; continue;
@@ -711,7 +628,11 @@ export const useFavoriteStore = defineStore('Favorite', () => {
} catch (err) { } catch (err) {
console.error(err); console.error(err);
} }
expireFavorites(); const previousFavoriteIds = new Set();
for (const ref of cachedFavorites.values()) {
previousFavoriteIds.add(ref.favoriteId);
}
let newFavoriteIds = new Set();
processBulk({ processBulk({
fn: favoriteRequest.getFavorites, fn: favoriteRequest.getFavorites,
N: -1, N: -1,
@@ -721,6 +642,7 @@ export const useFavoriteStore = defineStore('Favorite', () => {
}, },
handle(args) { handle(args) {
for (const json of args.json) { for (const json of args.json) {
newFavoriteIds.add(json.favoriteId);
handleFavorite({ handleFavorite({
json, json,
params: { params: {
@@ -732,7 +654,12 @@ export const useFavoriteStore = defineStore('Favorite', () => {
}, },
done(ok) { done(ok) {
if (ok) { if (ok) {
deleteExpiredFavorites(); for (const objectId of previousFavoriteIds) {
const fav = cachedFavoritesByObjectId.value(objectId);
if (!newFavoriteIds.has(objectId) && fav) {
handleFavoriteAtDelete(fav);
}
}
} }
refreshFavoriteItems(); refreshFavoriteItems();
refreshFavoriteGroups(); refreshFavoriteGroups();
@@ -760,16 +687,11 @@ export const useFavoriteStore = defineStore('Favorite', () => {
type: '', type: '',
visibility: '', visibility: '',
tags: [], tags: [],
// VRCX
$isDeleted: false,
$isExpired: false,
//
...json ...json
}; };
cachedFavoriteGroups.value[ref.id] = ref; cachedFavoriteGroups.value[ref.id] = ref;
} else { } else {
Object.assign(ref, json); Object.assign(ref, json);
ref.$isExpired = false;
} }
return ref; return ref;
} }
@@ -788,8 +710,6 @@ export const useFavoriteStore = defineStore('Favorite', () => {
favoriteId: '', favoriteId: '',
tags: [], tags: [],
// VRCX // VRCX
$isDeleted: false,
$isExpired: false,
$groupKey: '', $groupKey: '',
// //
...json ...json
@@ -805,31 +725,16 @@ export const useFavoriteStore = defineStore('Favorite', () => {
friendStore.localFavoriteFriends.add(ref.favoriteId); friendStore.localFavoriteFriends.add(ref.favoriteId);
friendStore.updateSidebarFavorites(); friendStore.updateSidebarFavorites();
} }
} else {
Object.assign(ref, json);
ref.$isExpired = false;
}
ref.$groupKey = `${ref.type}:${String(ref.tags[0])}`; ref.$groupKey = `${ref.type}:${String(ref.tags[0])}`;
if (ref.$isDeleted === false) {
const group = cachedFavoriteGroupsByTypeName.value[ref.$groupKey]; const group = cachedFavoriteGroupsByTypeName.value[ref.$groupKey];
if (typeof group !== 'undefined') { if (typeof group !== 'undefined') {
++group.count; ++group.count;
} }
} } else {
return ref; Object.assign(ref, json);
} }
/** return ref;
*
*/
function deleteExpiredFavorites() {
for (const ref of cachedFavorites.values()) {
if (ref.$isDeleted || !ref.$isExpired) {
continue;
}
handleFavoriteAtDelete(ref);
}
} }
/** /**
@@ -857,9 +762,6 @@ export const useFavoriteStore = defineStore('Favorite', () => {
}; };
const tags = []; const tags = [];
for (const ref of cachedFavorites.values()) { for (const ref of cachedFavorites.values()) {
if (ref.$isDeleted) {
continue;
}
const type = types[ref.type]; const type = types[ref.type];
if (typeof type === 'undefined') { if (typeof type === 'undefined') {
continue; continue;
-1
View File
@@ -289,7 +289,6 @@ export const useFriendStore = defineStore('Friend', () => {
localFavoriteFriends.clear(); localFavoriteFriends.clear();
for (const ref of favoriteStore.cachedFavorites.values()) { for (const ref of favoriteStore.cachedFavorites.values()) {
if ( if (
!ref.$isDeleted &&
ref.type === 'friend' && ref.type === 'friend' &&
(generalSettingsStore.localFavoriteFriendsGroups.includes( (generalSettingsStore.localFavoriteFriendsGroups.includes(
ref.$groupKey ref.$groupKey
-1
View File
@@ -158,7 +158,6 @@ export const useNotificationStore = defineStore('Notification', () => {
const D = userStore.userDialog; const D = userStore.userDialog;
if ( if (
D.visible === false || D.visible === false ||
ref.$isDeleted ||
ref.type !== 'friendRequest' || ref.type !== 'friendRequest' ||
ref.senderUserId !== D.id ref.senderUserId !== D.id
) { ) {