fix: load mutual friends button and mutual opt-out status in friend list

This commit is contained in:
pa
2026-03-27 12:20:49 +09:00
parent b3b1d68cc9
commit f71ac77377
8 changed files with 94 additions and 21 deletions
+8 -11
View File
@@ -322,6 +322,14 @@ export const useChartsStore = defineStore('Charts', () => {
mutualGraphStatus.friendSignature = friendCount.value;
mutualGraphStatus.needsRefetch = false;
// Write meta first so saveMutualGraphSnapshot's DELETE
// uses up-to-date opted_out flags to decide what to preserve.
// If this fails, we must NOT proceed with snapshot save because
// the DELETE would use stale meta and corrupt data.
if (metaEntries.size > 0) {
await database.bulkUpsertMutualGraphMeta(metaEntries);
}
try {
const entries = new Map();
mutualMap.forEach((value, friendId) => {
@@ -348,17 +356,6 @@ export const useChartsStore = defineStore('Charts', () => {
);
}
try {
if (metaEntries.size > 0) {
await database.bulkUpsertMutualGraphMeta(metaEntries);
}
} catch (metaErr) {
console.error(
'[MutualNetworkGraph] Failed to write meta',
metaErr
);
}
markMutualGraphLoaded({ notify: true });
return mutualMap;
} catch (err) {
+34
View File
@@ -61,6 +61,7 @@ export const useFriendStore = defineStore('Friend', () => {
let pendingSortedFriendsRebuild = false;
let allUserStatsRequestId = 0;
let allUserMutualCountRequestId = 0;
let allUserMutualOptedOutRequestId = 0;
const derivedDebugCounters = reactive({
allFavoriteFriendIds: 0,
@@ -904,6 +905,11 @@ export const useFriendStore = defineStore('Friend', () => {
return;
}
runInSortedFriendsBatch(() => {
for (const ctx of friends.values()) {
if (ctx?.ref) {
ctx.ref.$mutualCount = 0;
}
}
for (const [userId, mutualCount] of mutualCountMap.entries()) {
const ref = friends.get(userId);
if (ref?.ref) {
@@ -914,6 +920,33 @@ export const useFriendStore = defineStore('Friend', () => {
});
}
/**
*
*/
async function getAllUserMutualOptedOut() {
if (!friends.size) {
return;
}
const requestId = ++allUserMutualOptedOutRequestId;
const metaMap = await database.getMutualGraphMeta();
if (requestId !== allUserMutualOptedOutRequestId) {
return;
}
runInSortedFriendsBatch(() => {
for (const ctx of friends.values()) {
if (ctx?.ref) {
ctx.ref.$mutualOptedOut = false;
}
}
for (const [userId, meta] of metaMap.entries()) {
const ref = friends.get(userId);
if (ref?.ref) {
ref.ref.$mutualOptedOut = Boolean(meta.optedOut);
}
}
});
}
/**
*
* @param {string} id
@@ -1398,6 +1431,7 @@ export const useFriendStore = defineStore('Friend', () => {
updateOnlineFriendCounter,
getAllUserStats,
getAllUserMutualCount,
getAllUserMutualOptedOut,
initFriendLog,
migrateFriendLog,
getFriendLog,