Use /@username routes by default

https://codeberg.org/silverpill/mitra/issues/22
This commit is contained in:
silverpill 2023-02-27 23:23:56 +00:00
parent f0f2e115d1
commit e888589105
21 changed files with 73 additions and 39 deletions

View file

@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased] ## [Unreleased]
### Changed
- Use `/@username` routes by default.
## [1.15.0] - 2023-02-27 ## [1.15.0] - 2023-02-27
### Added ### Added

View file

@ -121,8 +121,8 @@ export class ProfileWrapper {
option.type === "monero-subscription" option.type === "monero-subscription"
) { ) {
return { return {
name: "profile-subscription", name: "profile-by-acct-subscription",
params: { profileId: this.id }, params: { acct: this.acct },
} }
} }
} }

View file

@ -5,7 +5,7 @@
class="floating-avatar" class="floating-avatar"
:href="post.account.url" :href="post.account.url"
:title="author.getDisplayName()" :title="author.getDisplayName()"
@click="openProfile($event, post.account.id)" @click="openProfile($event, post.account)"
> >
<avatar :profile="post.account"></avatar> <avatar :profile="post.account"></avatar>
</a> </a>
@ -13,7 +13,7 @@
class="display-name" class="display-name"
:href="post.account.url" :href="post.account.url"
:title="author.getDisplayName()" :title="author.getDisplayName()"
@click="openProfile($event, post.account.id)" @click="openProfile($event, post.account)"
> >
{{ author.getDisplayName() }} {{ author.getDisplayName() }}
</a> </a>
@ -53,7 +53,7 @@
:key="mention.id" :key="mention.id"
:href="mention.url" :href="mention.url"
:title="getActorAddress(mention)" :title="getActorAddress(mention)"
@click="openProfile($event, mention.id)" @click="openProfile($event, mention)"
> >
@{{ mention.username }} @{{ mention.username }}
</a> </a>
@ -255,7 +255,11 @@ import {
createRepost, createRepost,
deleteRepost, deleteRepost,
} from "@/api/posts" } from "@/api/posts"
import { Permissions, ProfileWrapper } from "@/api/users" import {
Permissions,
Profile,
ProfileWrapper,
} from "@/api/users"
import Avatar from "@/components/Avatar.vue" import Avatar from "@/components/Avatar.vue"
import CryptoAddress from "@/components/CryptoAddress.vue" import CryptoAddress from "@/components/CryptoAddress.vue"
import PostAttachment from "@/components/PostAttachment.vue" import PostAttachment from "@/components/PostAttachment.vue"
@ -301,13 +305,13 @@ let isWaitingForToken = $ref(false)
const blockchain = $computed(() => instance?.blockchains[0]) const blockchain = $computed(() => instance?.blockchains[0])
const author = $computed(() => new ProfileWrapper(props.post.account)) const author = $computed(() => new ProfileWrapper(props.post.account))
function openProfile(event: Event, profileId: string) { function openProfile(event: Event, profile: Mention | Profile) {
if (currentUser === null) { if (currentUser === null) {
// Viewing as guest; do not override click handler // Viewing as guest; do not override click handler
return return
} }
event.preventDefault() event.preventDefault()
router.push({ name: "profile", params: { profileId: profileId } }) router.push({ name: "profile-by-acct", params: { acct: profile.acct } })
} }
function highlight(postId: string | null) { function highlight(postId: string | null) {

View file

@ -38,7 +38,7 @@ function configureInlineLinks() {
if (mention) { if (mention) {
mentionElement.addEventListener("click", (event: Event) => { mentionElement.addEventListener("click", (event: Event) => {
event.preventDefault() event.preventDefault()
router.push({ name: "profile", params: { profileId: mention.id } }) router.push({ name: "profile-by-acct", params: { acct: mention.acct } })
}) })
} }
} }

View file

@ -3,7 +3,7 @@
<router-link <router-link
v-if="author" v-if="author"
class="floating-avatar" class="floating-avatar"
:to="{ name: 'profile', params: { profileId: author.id }}" :to="{ name: 'profile-by-acct', params: { acct: author.acct }}"
> >
<avatar :profile="author"></avatar> <avatar :profile="author"></avatar>
</router-link> </router-link>

View file

@ -3,7 +3,7 @@
<div class="action"> <div class="action">
<img :src="require('@/assets/feather/repeat.svg')"> <img :src="require('@/assets/feather/repeat.svg')">
<router-link <router-link
:to="{ name: 'profile', params: { profileId: post.account.id }}" :to="{ name: 'profile-by-acct', params: { acct: post.account.acct }}"
:title="getActorAddress(post.account)" :title="getActorAddress(post.account)"
> >
{{ author.getDisplayName() }} {{ author.getDisplayName() }}

View file

@ -15,7 +15,7 @@
<div id="profile"> <div id="profile">
<router-link <router-link
class="profile-link" class="profile-link"
:to="{ name: 'profile', params: { profileId: currentUser.id }}" :to="{ name: 'profile-by-acct', params: { acct: currentUser.acct }}"
> >
<avatar :profile="currentUser"></avatar> <avatar :profile="currentUser"></avatar>
<div class="profile-name">@{{ currentUser.username }}</div> <div class="profile-name">@{{ currentUser.username }}</div>

View file

@ -4,7 +4,7 @@
<component <component
class="profile-card" class="profile-card"
:is="sender.id ? 'router-link' : 'div'" :is="sender.id ? 'router-link' : 'div'"
:to="{ name: 'profile', params: { profileId: sender.id }}" :to="{ name: 'profile-by-acct', params: { acct: sender.acct }}"
> >
<avatar :profile="sender"></avatar> <avatar :profile="sender"></avatar>
<div class="display-name">{{ sender.getDisplayName() }}</div> <div class="display-name">{{ sender.getDisplayName() }}</div>
@ -13,7 +13,10 @@
<div class="separator"> <div class="separator">
<img :src="require('@/assets/feather/arrow-right.svg')"> <img :src="require('@/assets/feather/arrow-right.svg')">
</div> </div>
<router-link class="profile-card" :to="{ name: 'profile', params: { profileId: recipient.id }}"> <router-link
class="profile-card"
:to="{ name: 'profile-by-acct', params: { acct: recipient.acct }}"
>
<avatar :profile="recipient"></avatar> <avatar :profile="recipient"></avatar>
<div class="display-name">{{ recipient.getDisplayName() }}</div> <div class="display-name">{{ recipient.getDisplayName() }}</div>
<div class="wallet-address">{{ recipientEthereumAddress }}</div> <div class="wallet-address">{{ recipientEthereumAddress }}</div>

View file

@ -4,7 +4,7 @@
<component <component
class="profile-card" class="profile-card"
:is="sender.id ? 'router-link' : 'div'" :is="sender.id ? 'router-link' : 'div'"
:to="{ name: 'profile', params: { profileId: sender.id } }" :to="{ name: 'profile-by-acct', params: { acct: sender.acct } }"
> >
<avatar :profile="sender"></avatar> <avatar :profile="sender"></avatar>
<div class="display-name">{{ sender.getDisplayName() }}</div> <div class="display-name">{{ sender.getDisplayName() }}</div>
@ -12,7 +12,10 @@
<div class="separator"> <div class="separator">
<img :src="require('@/assets/feather/arrow-right.svg')"> <img :src="require('@/assets/feather/arrow-right.svg')">
</div> </div>
<router-link class="profile-card" :to="{ name: 'profile', params: { profileId: recipient.id }}"> <router-link
class="profile-card"
:to="{ name: 'profile-by-acct', params: { acct: recipient.acct }}"
>
<avatar :profile="recipient"></avatar> <avatar :profile="recipient"></avatar>
<div class="display-name">{{ recipient.getDisplayName() }}</div> <div class="display-name">{{ recipient.getDisplayName() }}</div>
</router-link> </router-link>

View file

@ -110,8 +110,8 @@ async function loadSubscriptionSettings() {
function getSubscriptionPagePath(): string { function getSubscriptionPagePath(): string {
const route = router.resolve({ const route = router.resolve({
name: "profile-subscription", name: "profile-by-acct-subscription",
params: { profileId: ensureCurrentUser().id }, params: { acct: ensureCurrentUser().acct },
}) })
return route.fullPath return route.fullPath
} }

View file

@ -100,12 +100,24 @@ const routes: Array<RouteRecordRaw> = [
component: ProfileView, component: ProfileView,
meta: { }, meta: { },
}, },
{
path: "/@:acct(.*)",
name: "profile-by-acct",
component: ProfileView,
meta: { },
},
{ {
path: "/profile/:profileId/subscription", path: "/profile/:profileId/subscription",
name: "profile-subscription", name: "profile-subscription",
component: SubscriptionPage, component: SubscriptionPage,
meta: { }, meta: { },
}, },
{
path: "/@:acct(.*)/subscription",
name: "profile-by-acct-subscription",
component: SubscriptionPage,
meta: { },
},
{ {
path: "/profile-directory", path: "/profile-directory",
name: "profile-directory", name: "profile-directory",
@ -160,12 +172,6 @@ const routes: Array<RouteRecordRaw> = [
.includes(Permissions.ManageSubscriptionOptions) .includes(Permissions.ManageSubscriptionOptions)
}, },
}, },
{
path: "/@:acct(.*)",
name: "profile-by-acct",
component: ProfileView,
meta: { },
},
{ {
path: "/:pathMatch(.*)*", path: "/:pathMatch(.*)*",
redirect: { name: "home" }, redirect: { name: "home" },

View file

@ -67,7 +67,7 @@ async function submit() {
did, did,
signature, signature,
) )
router.push({ name: "profile", params: { profileId: currentUser.id } }) router.push({ name: "profile-by-acct", params: { acct: currentUser.acct } })
} }
} }
</script> </script>

View file

@ -61,7 +61,7 @@ async function submit() {
} }
isLoading = false isLoading = false
errorMessage = null errorMessage = null
router.push({ name: "profile", params: { profileId: currentUser.id } }) router.push({ name: "profile-by-acct", params: { acct: currentUser.acct } })
} }
</script> </script>

View file

@ -73,7 +73,7 @@ async function move() {
isLoading = false isLoading = false
errorMessage = null errorMessage = null
setCurrentUser(user) setCurrentUser(user)
router.push({ name: "profile", params: { profileId: currentUser.id } }) router.push({ name: "profile-by-acct", params: { acct: currentUser.acct } })
} }
</script> </script>

View file

@ -19,7 +19,7 @@
<img v-else-if="notification.type === 'move'" :src="require('@/assets/feather/truck.svg')"> <img v-else-if="notification.type === 'move'" :src="require('@/assets/feather/truck.svg')">
<router-link <router-link
:title="getSenderInfo(notification)" :title="getSenderInfo(notification)"
:to="{ name: 'profile', params: { profileId: notification.account.id } }" :to="{ name: 'profile-by-acct', params: { acct: notification.account.acct } }"
> >
{{ getSenderName(notification) }} {{ getSenderName(notification) }}
</router-link> </router-link>
@ -42,7 +42,7 @@
<router-link <router-link
v-else v-else
class="profile" class="profile"
:to="{ name: 'profile', params: { profileId: notification.account.id } }" :to="{ name: 'profile-by-acct', params: { acct: notification.account.acct } }"
> >
<div class="floating-avatar"> <div class="floating-avatar">
<avatar :profile="notification.account"></avatar> <avatar :profile="notification.account"></avatar>

View file

@ -13,7 +13,10 @@
</div> </div>
</div> </div>
<div class="token-info"> <div class="token-info">
<router-link class="profile" :to="{ name: 'profile', params: { profileId: post.account.id }}"> <router-link
class="profile"
:to="{ name: 'profile-by-acct', params: { acct: post.account.acct }}"
>
<avatar :profile="post.account"></avatar> <avatar :profile="post.account"></avatar>
<div class="actor-address">@{{ actorAddress }}</div> <div class="actor-address">@{{ actorAddress }}</div>
</router-link> </router-link>

View file

@ -231,7 +231,7 @@
<router-link <router-link
v-for="profile in followList" v-for="profile in followList"
:key="profile.id" :key="profile.id"
:to="{ name: 'profile', params: { profileId: profile.id } }" :to="{ name: 'profile-by-acct', params: { acct: profile.acct } }"
> >
<profile-list-item :profile="profile"></profile-list-item> <profile-list-item :profile="profile"></profile-list-item>
</router-link> </router-link>

View file

@ -5,7 +5,7 @@
<router-link <router-link
v-for="profile in profiles" v-for="profile in profiles"
class="profile-list-item" class="profile-list-item"
:to="{ name: 'profile', params: { profileId: profile.id }}" :to="{ name: 'profile-by-acct', params: { acct: profile.acct }}"
:key="profile.id" :key="profile.id"
> >
<profile-card :profile="profile" :compact="false"></profile-card> <profile-card :profile="profile" :compact="false"></profile-card>

View file

@ -217,7 +217,7 @@ async function save() {
} }
isLoading = false isLoading = false
setCurrentUser(user) setCurrentUser(user)
router.push({ name: "profile", params: { profileId: user.id } }) router.push({ name: "profile-by-acct", params: { acct: user.acct } })
} }
</script> </script>

View file

@ -14,7 +14,7 @@
class="search-result" class="search-result"
v-for="profile in profiles" v-for="profile in profiles"
:key="profile.id" :key="profile.id"
:to="{ name: 'profile', params: { profileId: profile.id } }" :to="{ name: 'profile-by-acct', params: { acct: profile.acct } }"
> >
<profile-list-item :profile="profile"></profile-list-item> <profile-list-item :profile="profile"></profile-list-item>
</router-link> </router-link>

View file

@ -13,7 +13,11 @@ import { onMounted } from "vue"
import { $, $computed, $ref } from "vue/macros" import { $, $computed, $ref } from "vue/macros"
import { useRoute } from "vue-router" import { useRoute } from "vue-router"
import { getProfile, Profile } from "@/api/users" import {
lookupProfile,
getProfile,
Profile,
} from "@/api/users"
import SidebarLayout from "@/components/SidebarLayout.vue" import SidebarLayout from "@/components/SidebarLayout.vue"
import SubscriptionEthereum from "@/components/SubscriptionEthereum.vue" import SubscriptionEthereum from "@/components/SubscriptionEthereum.vue"
import SubscriptionMonero from "@/components/SubscriptionMonero.vue" import SubscriptionMonero from "@/components/SubscriptionMonero.vue"
@ -29,10 +33,17 @@ const blockchain = $computed(() => instance?.blockchains[0])
onMounted(async () => { onMounted(async () => {
// Recipient // Recipient
if (route.params.acct) {
profile = await lookupProfile(
authToken,
route.params.acct as string,
)
} else {
profile = await getProfile( profile = await getProfile(
authToken, authToken,
route.params.profileId as string, route.params.profileId as string,
) )
}
}) })
function isLocalUser(): boolean { function isLocalUser(): boolean {