Skip to content

Commit

Permalink
fix: fix incorrect follow status on followers and following pages (#2669
Browse files Browse the repository at this point in the history
)
  • Loading branch information
shuuji3 authored Mar 9, 2024
1 parent 1c8e48b commit 0fd9374
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions composables/masto/relationship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ let timeoutHandle: NodeJS.Timeout | undefined
export function useRelationship(account: mastodon.v1.Account): Ref<mastodon.v1.Relationship | undefined> {
if (!currentUser.value)
return ref()

let relationship = requestedRelationships.get(account.id)
if (relationship)
return relationship

// allow batch relationship requests
relationship = ref<mastodon.v1.Relationship | undefined>()
requestedRelationships.set(account.id, relationship)
if (timeoutHandle)
Expand All @@ -22,14 +25,19 @@ export function useRelationship(account: mastodon.v1.Account): Ref<mastodon.v1.R
timeoutHandle = undefined
fetchRelationships()
}, 100)

return relationship
}

async function fetchRelationships() {
const requested = Array.from(requestedRelationships.entries()).filter(([, r]) => !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) {
Expand Down

0 comments on commit 0fd9374

Please sign in to comment.