fix: 🐛 Don't auto mention yourself when replying/quoting yourself

This commit is contained in:
Jesse Wierzbinski 2024-04-27 21:54:13 -10:00
parent 86e254b7e7
commit a2a2149776
No known key found for this signature in database
5 changed files with 31 additions and 10 deletions

17
app.vue
View file

@ -15,11 +15,12 @@ useServerSeoMeta({
provideHeadlessUseId(() => useId()); provideHeadlessUseId(() => useId());
const code = useRequestURL().searchParams.get("code"); const code = useRequestURL().searchParams.get("code");
const appData = useAppData();
const tokenData = useTokenData();
const client = useMegalodon(tokenData);
const me = useMe();
if (code) { if (code) {
const client = useMegalodon();
const appData = useAppData();
const tokenData = useTokenData();
if (appData.value) { if (appData.value) {
client.value client.value
?.fetchAccessToken( ?.fetchAccessToken(
@ -40,6 +41,16 @@ if (code) {
}); });
} }
} }
watch(tokenData, async () => {
if (tokenData.value && !me.value) {
const response = await client.value?.verifyAccountCredentials()
if (response?.data) {
me.value = response.data;
}
}
}, { immediate: true })
</script> </script>
<style> <style>

View file

@ -40,19 +40,22 @@ const { input: content } = useTextareaAutosize({
const { Control_Enter, Command_Enter } = useMagicKeys(); const { Control_Enter, Command_Enter } = useMagicKeys();
const respondingTo = ref<Status | null>(null); const respondingTo = ref<Status | null>(null);
const respondingType = ref<"reply" | "quote" | null>(null); const respondingType = ref<"reply" | "quote" | null>(null);
const me = useMe();
onMounted(() => { onMounted(() => {
useListen("composer:reply", (note: Status) => { useListen("composer:reply", (note: Status) => {
respondingTo.value = note; respondingTo.value = note;
respondingType.value = "reply"; respondingType.value = "reply";
content.value = `@${note.account.acct} `; if (note.account.id !== me.value?.id)
content.value = `@${note.account.acct} `;
textarea.value?.focus(); textarea.value?.focus();
}); });
useListen("composer:quote", (note: Status) => { useListen("composer:quote", (note: Status) => {
respondingTo.value = note; respondingTo.value = note;
respondingType.value = "quote"; respondingType.value = "quote";
content.value = `@${note.account.acct} `; if (note.account.id !== me.value?.id)
content.value = `@${note.account.acct} `;
textarea.value?.focus(); textarea.value?.focus();
}); });
}); });

View file

@ -71,6 +71,7 @@ const loadingAuth = ref(false);
const appData = useAppData(); const appData = useAppData();
const tokenData = useTokenData(); const tokenData = useTokenData();
const client = useMegalodon(); const client = useMegalodon();
const me = useMe();
const compose = () => { const compose = () => {
useEvent("composer:open"); useEvent("composer:open");
@ -124,8 +125,9 @@ const signOut = async () => {
tokenData.value.access_token, tokenData.value.access_token,
tokenData.value.access_token, tokenData.value.access_token,
) )
.catch(() => {}); .catch(() => { });
tokenData.value = null; tokenData.value = null;
me.value = null;
}; };
</script> </script>

8
composables/Me.ts Normal file
View file

@ -0,0 +1,8 @@
import { StorageSerializers } from "@vueuse/core";
import type { Account } from "~/types/mastodon/account";
export const useMe = () => {
return useLocalStorage<Account | null>("lysand:me", null, {
serializer: StorageSerializers.object,
});
};

View file

@ -10,9 +10,6 @@ export const useMegalodon = (
return computed( return computed(
() => () =>
new Mastodon( new Mastodon(useBaseUrl().value, toValue(tokenData)?.access_token),
useBaseUrl().value,
ref(tokenData).value?.access_token,
),
); );
}; };