2024-08-28 00:23:29 +02:00
|
|
|
import type { Client } from "@versia/client";
|
|
|
|
|
import type { Status } from "@versia/client/types";
|
2024-06-19 08:16:28 +02:00
|
|
|
import { SettingIds, type Settings } from "~/settings";
|
2024-04-28 07:02:27 +02:00
|
|
|
|
|
|
|
|
export const useNoteData = (
|
|
|
|
|
noteProp: MaybeRef<Status | undefined>,
|
2024-08-28 00:23:29 +02:00
|
|
|
client: Ref<Client>,
|
2024-06-19 08:16:28 +02:00
|
|
|
settings: MaybeRef<Settings>,
|
2024-04-28 07:02:27 +02:00
|
|
|
) => {
|
2024-05-12 04:33:40 +02:00
|
|
|
const isReply = computed(() => !!toValue(noteProp)?.in_reply_to_id);
|
2024-04-28 08:35:26 +02:00
|
|
|
const isQuote = computed(() => !!toValue(noteProp)?.quote);
|
|
|
|
|
const isReblog = computed(
|
|
|
|
|
() => !isQuote.value && !!toValue(noteProp)?.reblog,
|
|
|
|
|
);
|
|
|
|
|
const renderedNote = computed(() =>
|
|
|
|
|
isReblog.value
|
2024-09-14 13:18:49 +02:00
|
|
|
? (toValue(noteProp)?.reblog ?? toValue(noteProp))
|
2024-04-28 08:35:26 +02:00
|
|
|
: toValue(noteProp),
|
2024-04-28 07:02:27 +02:00
|
|
|
);
|
2024-06-19 08:16:28 +02:00
|
|
|
const showContentWarning = useSetting(SettingIds.ShowContentWarning);
|
2024-04-28 07:02:27 +02:00
|
|
|
const shouldHide = computed(
|
|
|
|
|
() =>
|
2024-06-19 08:16:28 +02:00
|
|
|
(renderedNote.value?.sensitive ||
|
2024-06-20 02:07:56 +02:00
|
|
|
!!renderedNote.value?.spoiler_text) &&
|
2024-06-19 08:16:28 +02:00
|
|
|
(showContentWarning.value.value as boolean),
|
2024-04-28 07:02:27 +02:00
|
|
|
);
|
|
|
|
|
const mentions = useResolveMentions(
|
2024-06-06 08:42:44 +02:00
|
|
|
computed(() => renderedNote.value?.mentions ?? []),
|
2024-04-28 07:02:27 +02:00
|
|
|
client.value,
|
|
|
|
|
);
|
|
|
|
|
const content = useParsedContent(
|
2024-06-06 08:42:44 +02:00
|
|
|
computed(() => renderedNote.value?.content ?? ""),
|
|
|
|
|
computed(() => renderedNote.value?.emojis ?? []),
|
2024-04-28 07:02:27 +02:00
|
|
|
mentions,
|
2024-06-19 08:16:28 +02:00
|
|
|
settings,
|
2024-04-28 07:02:27 +02:00
|
|
|
);
|
|
|
|
|
const loaded = computed(() => content.value !== null);
|
|
|
|
|
|
|
|
|
|
const reblogDisplayName = useParsedContent(
|
2024-06-12 01:54:35 +02:00
|
|
|
toValue(noteProp)?.account.display_name ?? "",
|
|
|
|
|
toValue(noteProp)?.account.emojis ?? [],
|
2024-06-19 08:16:28 +02:00
|
|
|
undefined,
|
|
|
|
|
settings,
|
2024-04-28 07:02:27 +02:00
|
|
|
);
|
|
|
|
|
const reblog = computed(() =>
|
2024-06-12 01:54:35 +02:00
|
|
|
isReblog.value && toValue(noteProp) && !isQuote.value
|
2024-04-28 07:02:27 +02:00
|
|
|
? {
|
2024-06-12 01:54:35 +02:00
|
|
|
avatar: toValue(noteProp)?.account.avatar,
|
|
|
|
|
acct: toValue(noteProp)?.account.acct,
|
2024-04-28 07:02:27 +02:00
|
|
|
}
|
|
|
|
|
: null,
|
|
|
|
|
);
|
|
|
|
|
|
2024-06-05 02:03:15 +02:00
|
|
|
const url = computed(() =>
|
|
|
|
|
new URL(
|
|
|
|
|
`/@${renderedNote.value?.account.acct}/${renderedNote.value?.id}`,
|
|
|
|
|
window.location.origin,
|
|
|
|
|
).toString(),
|
2024-04-28 07:02:27 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const remove = async () => {
|
2024-06-10 05:24:55 +02:00
|
|
|
const result = await client.value.deleteStatus(
|
2024-04-28 07:02:27 +02:00
|
|
|
renderedNote.value?.id ?? "",
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (result?.data) {
|
2024-06-12 03:02:30 +02:00
|
|
|
useEvent("note:delete", result.data);
|
2024-04-28 07:02:27 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
loaded,
|
|
|
|
|
note: renderedNote,
|
|
|
|
|
content,
|
2024-04-28 08:35:26 +02:00
|
|
|
isQuote,
|
2024-04-28 07:02:27 +02:00
|
|
|
reblog,
|
|
|
|
|
reblogDisplayName,
|
|
|
|
|
shouldHide,
|
2024-05-12 04:33:40 +02:00
|
|
|
isReply,
|
2024-04-28 07:02:27 +02:00
|
|
|
url,
|
|
|
|
|
remove,
|
|
|
|
|
};
|
|
|
|
|
};
|