From 0fd9374e8c7f4e067770b0cd2b522085cf11dadd Mon Sep 17 00:00:00 2001 From: TAKAHASHI Shuuji Date: Sun, 10 Mar 2024 04:31:40 +0900 Subject: [PATCH] fix: fix incorrect follow status on followers and following pages (#2669) --- composables/masto/relationship.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/composables/masto/relationship.ts b/composables/masto/relationship.ts index 5fb44e90..4e5349f1 100644 --- a/composables/masto/relationship.ts +++ b/composables/masto/relationship.ts @@ -11,9 +11,12 @@ let timeoutHandle: NodeJS.Timeout | undefined export function useRelationship(account: mastodon.v1.Account): Ref { if (!currentUser.value) return ref() + let relationship = requestedRelationships.get(account.id) if (relationship) return relationship + + // allow batch relationship requests relationship = ref() requestedRelationships.set(account.id, relationship) if (timeoutHandle) @@ -22,14 +25,19 @@ export function useRelationship(account: mastodon.v1.Account): Ref !r.value) const relationships = await useMastoClient().v1.accounts.relationships.fetch({ id: requested.map(([id]) => id) }) - for (let i = 0; i < requested.length; i++) - requested[i][1].value = relationships[i] + for (const relationship of relationships) { + const requestedToUpdate = requested.find(([id]) => id === relationship.id) + if (!requestedToUpdate) + continue + requestedToUpdate[1].value = relationship + } } export async function toggleFollowAccount(relationship: mastodon.v1.Relationship, account: mastodon.v1.Account) {