forked from Mirrors/elk
fix: fix incorrect follow status on followers and following pages (#2669)
This commit is contained in:
parent
1c8e48bee4
commit
0fd9374e8c
1 changed files with 10 additions and 2 deletions
|
@ -11,9 +11,12 @@ let timeoutHandle: NodeJS.Timeout | undefined
|
||||||
export function useRelationship(account: mastodon.v1.Account): Ref<mastodon.v1.Relationship | undefined> {
|
export function useRelationship(account: mastodon.v1.Account): Ref<mastodon.v1.Relationship | undefined> {
|
||||||
if (!currentUser.value)
|
if (!currentUser.value)
|
||||||
return ref()
|
return ref()
|
||||||
|
|
||||||
let relationship = requestedRelationships.get(account.id)
|
let relationship = requestedRelationships.get(account.id)
|
||||||
if (relationship)
|
if (relationship)
|
||||||
return relationship
|
return relationship
|
||||||
|
|
||||||
|
// allow batch relationship requests
|
||||||
relationship = ref<mastodon.v1.Relationship | undefined>()
|
relationship = ref<mastodon.v1.Relationship | undefined>()
|
||||||
requestedRelationships.set(account.id, relationship)
|
requestedRelationships.set(account.id, relationship)
|
||||||
if (timeoutHandle)
|
if (timeoutHandle)
|
||||||
|
@ -22,14 +25,19 @@ export function useRelationship(account: mastodon.v1.Account): Ref<mastodon.v1.R
|
||||||
timeoutHandle = undefined
|
timeoutHandle = undefined
|
||||||
fetchRelationships()
|
fetchRelationships()
|
||||||
}, 100)
|
}, 100)
|
||||||
|
|
||||||
return relationship
|
return relationship
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchRelationships() {
|
async function fetchRelationships() {
|
||||||
const requested = Array.from(requestedRelationships.entries()).filter(([, r]) => !r.value)
|
const requested = Array.from(requestedRelationships.entries()).filter(([, r]) => !r.value)
|
||||||
const relationships = await useMastoClient().v1.accounts.relationships.fetch({ id: requested.map(([id]) => id) })
|
const relationships = await useMastoClient().v1.accounts.relationships.fetch({ id: requested.map(([id]) => id) })
|
||||||
for (let i = 0; i < requested.length; i++)
|
for (const relationship of relationships) {
|
||||||
requested[i][1].value = relationships[i]
|
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) {
|
export async function toggleFollowAccount(relationship: mastodon.v1.Relationship, account: mastodon.v1.Account) {
|
||||||
|
|
Loading…
Reference in a new issue