diff --git a/src/boot/routes.js b/src/boot/routes.js index 5670236c..7400a682 100644 --- a/src/boot/routes.js +++ b/src/boot/routes.js @@ -18,6 +18,7 @@ import AuthForm from 'components/auth_form/auth_form.js' import ChatPanel from 'components/chat_panel/chat_panel.vue' import WhoToFollow from 'components/who_to_follow/who_to_follow.vue' import About from 'components/about/about.vue' +import RemoteUserResolver from 'components/remote_user_resolver/remote_user_resolver.vue' export default (store) => { const validateAuthenticatedRoute = (to, from, next) => { @@ -42,6 +43,16 @@ export default (store) => { { name: 'friends', path: '/main/friends', component: FriendsTimeline, beforeEnter: validateAuthenticatedRoute }, { name: 'tag-timeline', path: '/tag/:tag', component: TagTimeline }, { name: 'conversation', path: '/notice/:id', component: ConversationPage, meta: { dontScroll: true } }, + { name: 'remote-user-profile-acct', + path: '/remote-users/(@?):username([^/@]+)@:hostname([^/@]+)', + component: RemoteUserResolver, + beforeEnter: validateAuthenticatedRoute + }, + { name: 'remote-user-profile', + path: '/remote-users/:hostname/:username', + component: RemoteUserResolver, + beforeEnter: validateAuthenticatedRoute + }, { name: 'external-user-profile', path: '/users/:id', component: UserProfile }, { name: 'interactions', path: '/users/:username/interactions', component: Interactions, beforeEnter: validateAuthenticatedRoute }, { name: 'dms', path: '/users/:username/dms', component: DMs, beforeEnter: validateAuthenticatedRoute }, diff --git a/src/components/remote_user_resolver/remote_user_resolver.js b/src/components/remote_user_resolver/remote_user_resolver.js new file mode 100644 index 00000000..9b5e511e --- /dev/null +++ b/src/components/remote_user_resolver/remote_user_resolver.js @@ -0,0 +1,31 @@ +const RemoteUserResolver = { + data: () => ({ + error: false + }), + mounted () { + this.redirect() + }, + methods: { + redirect () { + const acct = this.$route.params.username + '@' + this.$route.params.hostname + this.$store.state.api.backendInteractor.fetchUser({ id: acct }) + .then((externalUser) => { + if (externalUser.error) { + this.error = true + } else { + this.$store.commit('addNewUsers', [externalUser]) + const id = externalUser.id + this.$router.replace({ + name: 'external-user-profile', + params: { id } + }) + } + }) + .catch(() => { + this.error = true + }) + } + } +} + +export default RemoteUserResolver diff --git a/src/components/remote_user_resolver/remote_user_resolver.vue b/src/components/remote_user_resolver/remote_user_resolver.vue new file mode 100644 index 00000000..f8945225 --- /dev/null +++ b/src/components/remote_user_resolver/remote_user_resolver.vue @@ -0,0 +1,20 @@ + + + + {{ $t('remote_user_resolver.remote_user_resolver') }} + + + + {{ $t('remote_user_resolver.searching_for') }} @{{ $route.params.username }}@{{ $route.params.hostname }} + + + {{ $t('remote_user_resolver.error') }} + + + + + + + + diff --git a/src/i18n/en.json b/src/i18n/en.json index 8ecb3f3d..483432ff 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -172,6 +172,11 @@ "password_confirmation_match": "should be the same as password" } }, + "remote_user_resolver": { + "remote_user_resolver": "Remote user resolver", + "searching_for": "Searching for", + "error": "Not found." + }, "selectable_list": { "select_all": "Select all" },
+ {{ $t('remote_user_resolver.searching_for') }} @{{ $route.params.username }}@{{ $route.params.hostname }} +
+ {{ $t('remote_user_resolver.error') }} +