Use external links in Post component when user is not authenticated

This commit is contained in:
silverpill 2022-09-19 15:57:13 +00:00
parent d16981c2b5
commit 10423fa5b3

View file

@ -1,16 +1,22 @@
<template> <template>
<div class="post" :class="{ 'highlighted': highlighted }" :data-post-id="post.id" :id="post.id"> <div class="post" :class="{ 'highlighted': highlighted }" :data-post-id="post.id" :id="post.id">
<div class="post-header"> <div class="post-header">
<router-link class="floating-avatar" :to="{ name: 'profile', params: { profileId: post.account.id }}"> <a
<avatar :profile="post.account"></avatar> class="floating-avatar"
</router-link> :href="post.account.url"
<router-link
class="display-name"
:to="{ name: 'profile', params: { profileId: post.account.id }}"
:title="author.getDisplayName()" :title="author.getDisplayName()"
@click="openProfile($event, post.account.id)"
>
<avatar :profile="post.account"></avatar>
</a>
<a
class="display-name"
:href="post.account.url"
:title="author.getDisplayName()"
@click="openProfile($event, post.account.id)"
> >
{{ author.getDisplayName() }} {{ author.getDisplayName() }}
</router-link> </a>
<div class="actor-address" :title="'@' + getActorAddress(post.account)"> <div class="actor-address" :title="'@' + getActorAddress(post.account)">
@{{ getActorAddress(post.account) }} @{{ getActorAddress(post.account) }}
</div> </div>
@ -34,21 +40,22 @@
<a <a
class="timestamp" class="timestamp"
:href="post.uri" :href="post.uri"
@click.prevent="navigateTo(post.id)" @click="navigateTo($event)"
> >
{{ humanizeDate(post.created_at) }} {{ humanizeDate(post.created_at) }}
</a> </a>
</div> </div>
<div class="post-subheader" v-if="getReplyMentions().length > 0"> <div class="post-subheader" v-if="getReplyMentions().length > 0">
<span>replying to</span> <span>replying to</span>
<router-link <a
v-for="mention in getReplyMentions()" v-for="mention in getReplyMentions()"
:to="{ name: 'profile', params: { profileId: mention.id }}"
:title="getActorAddress(mention)"
:key="mention.id" :key="mention.id"
:href="mention.url"
:title="getActorAddress(mention)"
@click="openProfile($event, mention.id)"
> >
@{{ mention.username }} @{{ mention.username }}
</router-link> </a>
</div> </div>
<div class="post-content" ref="postContentRef" v-html="getContent()"></div> <div class="post-content" ref="postContentRef" v-html="getContent()"></div>
<div class="post-attachment" v-if="post.media_attachments.length > 0"> <div class="post-attachment" v-if="post.media_attachments.length > 0">
@ -271,6 +278,12 @@ const blockchain = $computed(() => instance?.blockchains[0])
const author = $computed(() => new ProfileWrapper(props.post.account)) const author = $computed(() => new ProfileWrapper(props.post.account))
onMounted(() => { onMounted(() => {
if (currentUser !== null) {
configureInlineLinks()
}
})
function configureInlineLinks() {
if (postContentRef === null) { if (postContentRef === null) {
return return
} }
@ -311,13 +324,28 @@ onMounted(() => {
} }
} }
} }
}) }
function openProfile(event: Event, profileId: string) {
if (currentUser === null) {
// Viewing as guest; do not override click handler
return
}
event.preventDefault()
router.push({ name: "profile", params: { profileId: profileId } })
}
function highlight(postId: string | null) { function highlight(postId: string | null) {
emit("highlight", postId) emit("highlight", postId)
} }
function navigateTo(postId: string) { function navigateTo(event: Event) {
if (currentUser === null) {
// Viewing as guest; do not override click handler
return
}
event.preventDefault()
const postId = props.post.id
if (props.inThread) { if (props.inThread) {
emit("navigate-to", postId) emit("navigate-to", postId)
} else { } else {