2024-08-28 00:23:29 +02:00
|
|
|
import type { Client } from "@versia/client";
|
|
|
|
|
import type { Account, Mention } from "@versia/client/types";
|
2024-04-22 09:38:51 +02:00
|
|
|
|
2024-04-28 07:02:27 +02:00
|
|
|
export const useResolveMentions = (
|
2024-06-06 08:42:44 +02:00
|
|
|
mentions: Ref<Mention[]>,
|
2024-08-28 00:23:29 +02:00
|
|
|
client: Client | null,
|
2024-04-28 07:02:27 +02:00
|
|
|
): Ref<Account[]> => {
|
2024-04-22 09:38:51 +02:00
|
|
|
if (!client) {
|
|
|
|
|
return ref([]);
|
|
|
|
|
}
|
2024-04-28 07:02:27 +02:00
|
|
|
|
|
|
|
|
const output = ref<Account[]>([]);
|
|
|
|
|
|
2024-07-21 15:33:32 +02:00
|
|
|
watch(
|
|
|
|
|
mentions,
|
|
|
|
|
async () => {
|
|
|
|
|
output.value = await Promise.all(
|
|
|
|
|
toValue(mentions).map(async (mention) => {
|
|
|
|
|
const response = await client.getAccount(mention.id);
|
|
|
|
|
return response.data;
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
{ immediate: true },
|
|
|
|
|
);
|
2024-04-28 07:02:27 +02:00
|
|
|
|
|
|
|
|
return output;
|
2024-04-22 09:38:51 +02:00
|
|
|
};
|