diff --git a/src/renderer/components/TimelineSpace/Contents/Cards/Notification/Favourite.vue b/src/renderer/components/TimelineSpace/Contents/Cards/Notification/Favourite.vue index c2e095f5..12618df4 100644 --- a/src/renderer/components/TimelineSpace/Contents/Cards/Notification/Favourite.vue +++ b/src/renderer/components/TimelineSpace/Contents/Cards/Notification/Favourite.vue @@ -156,10 +156,10 @@ export default { this.$router.push({ path: tag }) return tag } - const accountURL = findAccount(e.target) - if (accountURL !== null) { + const parsedAccount = findAccount(e.target) + if (parsedAccount !== null) { this.$store.commit('TimelineSpace/Contents/SideBar/changeOpenSideBar', true) - this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/searchAccount', accountURL) + this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/searchAccount', parsedAccount) .then((account) => { this.$store.dispatch('TimelineSpace/Contents/SideBar/openAccountComponent') this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/changeAccount', account) @@ -171,7 +171,7 @@ export default { }) this.$store.commit('TimelineSpace/Contents/SideBar/changeOpenSideBar', false) }) - return accountURL + return parsedAccount.acct } const link = findLink(e.target) if (link !== null) { diff --git a/src/renderer/components/TimelineSpace/Contents/Cards/Notification/Reblog.vue b/src/renderer/components/TimelineSpace/Contents/Cards/Notification/Reblog.vue index d71eab79..971a851b 100644 --- a/src/renderer/components/TimelineSpace/Contents/Cards/Notification/Reblog.vue +++ b/src/renderer/components/TimelineSpace/Contents/Cards/Notification/Reblog.vue @@ -155,10 +155,10 @@ export default { this.$router.push({ path: tag }) return tag } - const accountURL = findAccount(e.target) - if (accountURL !== null) { + const parsedAccount = findAccount(e.target) + if (parsedAccount !== null) { this.$store.commit('TimelineSpace/Contents/SideBar/changeOpenSideBar', true) - this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/searchAccount', accountURL) + this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/searchAccount', parsedAccount) .then((account) => { this.$store.dispatch('TimelineSpace/Contents/SideBar/openAccountComponent') this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/changeAccount', account) @@ -170,7 +170,7 @@ export default { }) this.$store.commit('TimelineSpace/Contents/SideBar/changeOpenSideBar', false) }) - return accountURL + return parsedAccount } const link = findLink(e.target) if (link !== null) { diff --git a/src/renderer/components/TimelineSpace/Contents/Cards/Toot.vue b/src/renderer/components/TimelineSpace/Contents/Cards/Toot.vue index a6091f02..2b98ef29 100644 --- a/src/renderer/components/TimelineSpace/Contents/Cards/Toot.vue +++ b/src/renderer/components/TimelineSpace/Contents/Cards/Toot.vue @@ -236,10 +236,10 @@ export default { this.$router.push({ path: tag }) return tag } - const accountURL = findAccount(e.target) - if (accountURL !== null) { + const parsedAccount = findAccount(e.target) + if (parsedAccount !== null) { this.$store.commit('TimelineSpace/Contents/SideBar/changeOpenSideBar', true) - this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/searchAccount', accountURL) + this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/searchAccount', parsedAccount) .then((account) => { this.$store.dispatch('TimelineSpace/Contents/SideBar/openAccountComponent') this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/changeAccount', account) @@ -251,7 +251,7 @@ export default { }) this.$store.commit('TimelineSpace/Contents/SideBar/changeOpenSideBar', false) }) - return accountURL + return parsedAccount.acct } const link = findLink(e.target) if (link !== null) { diff --git a/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile.js b/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile.js index 47247e3e..d25b7b7b 100644 --- a/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile.js +++ b/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile.js @@ -35,15 +35,17 @@ const AccountProfile = { return client.get(`/accounts/${accountID}`) .then(res => res.data) }, - searchAccount ({ commit, rootState }, accountURL) { + searchAccount ({ commit, rootState }, parsedAccount) { const client = new Mastodon( rootState.TimelineSpace.account.accessToken, rootState.TimelineSpace.account.baseURL + '/api/v1' ) - return client.get('/search', { q: accountURL, resolve: true }) + return client.get('/search', { q: parsedAccount.acct, resolve: true }) .then(res => { if (res.data.accounts.length <= 0) throw new AccountNotFound('not found') - return res.data.accounts[0] + const account = res.data.accounts[0] + if (`@${account.username}` !== parsedAccount.username) throw new AccountNotFound('not found') + return account }) }, changeAccount ({ commit, dispatch }, account) { diff --git a/src/renderer/utils/tootParser.js b/src/renderer/utils/tootParser.js index a4d8800e..c2398f4d 100644 --- a/src/renderer/utils/tootParser.js +++ b/src/renderer/utils/tootParser.js @@ -57,5 +57,8 @@ export function parseAccount (accountURL) { const res = accountURL.match(/^https:\/\/([a-zA-Z0-9-.]+)\/(@[a-zA-Z0-9-_.]+)/) const domainName = res[1] const accountName = res[2] - return `${accountName}@${domainName}` + return { + username: accountName, + acct: `${accountName}@${domainName}` + } } diff --git a/test/mocha/tootParser.spec.js b/test/mocha/tootParser.spec.js index f176c456..8cca9b7c 100644 --- a/test/mocha/tootParser.spec.js +++ b/test/mocha/tootParser.spec.js @@ -50,7 +50,8 @@ describe('findAccount', () => { const target = doc.getElementById('user') it('should find', () => { const res = findAccount(target) - assert.strictEqual(res, '@h3_poteto@social.mikutter.hachune.net') + assert.strictEqual(res.username, '@h3_poteto') + assert.strictEqual(res.acct, '@h3_poteto@social.mikutter.hachune.net') }) }) })