diff --git a/src/renderer/components/TimelineSpace/Contents/Cards/Notification/Favourite.vue b/src/renderer/components/TimelineSpace/Contents/Cards/Notification/Favourite.vue index 4321ceb0..1b624a9f 100644 --- a/src/renderer/components/TimelineSpace/Contents/Cards/Notification/Favourite.vue +++ b/src/renderer/components/TimelineSpace/Contents/Cards/Notification/Favourite.vue @@ -153,7 +153,7 @@ export default { } }, tootClick (e) { - const parsedTag = findTag(e.target, 'favourit') + const parsedTag = findTag(e.target, 'favourite') if (parsedTag !== null) { const tag = `/${this.$route.params.id}/hashtag/${parsedTag}` this.$router.push({ path: tag }) @@ -167,15 +167,16 @@ export default { this.$store.dispatch('TimelineSpace/Contents/SideBar/openAccountComponent') this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/changeAccount', account) }) - .catch(() => { - this.$message({ - message: this.$t('message.find_account_error'), - type: 'error' - }) + .catch((err) => { + console.error(err) + this.openLink(e) this.$store.commit('TimelineSpace/Contents/SideBar/changeOpenSideBar', false) }) return parsedAccount.acct } + this.openLink(e) + }, + openLink (e) { const link = findLink(e.target, 'favourite') if (link !== null) { return shell.openExternal(link) diff --git a/src/renderer/components/TimelineSpace/Contents/Cards/Notification/Reblog.vue b/src/renderer/components/TimelineSpace/Contents/Cards/Notification/Reblog.vue index 8ab5b36c..05a144d2 100644 --- a/src/renderer/components/TimelineSpace/Contents/Cards/Notification/Reblog.vue +++ b/src/renderer/components/TimelineSpace/Contents/Cards/Notification/Reblog.vue @@ -167,14 +167,14 @@ export default { this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/changeAccount', account) }) .catch(() => { - this.$message({ - message: this.$t('message.find_account_error'), - type: 'error' - }) + this.openLink(e) this.$store.commit('TimelineSpace/Contents/SideBar/changeOpenSideBar', false) }) return parsedAccount } + this.openLink(e) + }, + openLink (e) { const link = findLink(e.target, 'reblog') if (link !== null) { return shell.openExternal(link) diff --git a/src/renderer/components/TimelineSpace/Contents/Cards/Toot.vue b/src/renderer/components/TimelineSpace/Contents/Cards/Toot.vue index 3681337a..75bf4f8d 100644 --- a/src/renderer/components/TimelineSpace/Contents/Cards/Toot.vue +++ b/src/renderer/components/TimelineSpace/Contents/Cards/Toot.vue @@ -244,7 +244,6 @@ export default { const parsedTag = findTag(e.target, 'toot') if (parsedTag !== null) { const tag = `/${this.$route.params.id}/hashtag/${parsedTag}` - console.log(tag) this.$router.push({ path: tag }) return tag } @@ -256,15 +255,16 @@ export default { this.$store.dispatch('TimelineSpace/Contents/SideBar/openAccountComponent') this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/changeAccount', account) }) - .catch(() => { - this.$message({ - message: this.$t('message.find_account_error'), - type: 'error' - }) + .catch((err) => { + console.error(err) + this.openLink(e) this.$store.commit('TimelineSpace/Contents/SideBar/changeOpenSideBar', false) }) return parsedAccount.acct } + this.openLink(e) + }, + openLink (e) { const link = findLink(e.target, 'toot') if (link !== null) { return shell.openExternal(link) diff --git a/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile.js b/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile.js index d25b7b7b..cb7949d5 100644 --- a/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile.js +++ b/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile.js @@ -42,9 +42,9 @@ const AccountProfile = { ) return client.get('/search', { q: parsedAccount.acct, resolve: true }) .then(res => { - if (res.data.accounts.length <= 0) throw new AccountNotFound('not found') - const account = res.data.accounts[0] - if (`@${account.username}` !== parsedAccount.username) throw new AccountNotFound('not found') + if (res.data.accounts.length <= 0) throw new AccountNotFound('empty result') + const account = res.data.accounts.find(a => `@${a.username}` === parsedAccount.username) + if (!account) throw new AccountNotFound('not found') return account }) }, diff --git a/src/renderer/utils/tootParser.js b/src/renderer/utils/tootParser.js index 73407dc0..a05abe3c 100644 --- a/src/renderer/utils/tootParser.js +++ b/src/renderer/utils/tootParser.js @@ -36,12 +36,16 @@ export function parseTag (tagURL) { export function findAccount (target, parentClass = 'toot') { if (target.getAttribute('class') && target.getAttribute('class').includes('u-url')) { - return parseAccount(target.href) + return parseMastodonAccount(target.href) } // In Pleroma, link does not have class. - // So I have to check URL. + // So we have to check URL. if (target.href && target.href.match(/^https:\/\/[a-zA-Z0-9-.]+\/@[a-zA-Z0-9-_.]+/)) { - return parseAccount(target.href) + return parseMastodonAccount(target.href) + } + // Toot URL of Pleroma does not contain @. + if (target.href && target.href.match(/^https:\/\/[a-zA-Z0-9-.]+\/users\/[a-zA-Z0-9-_.]+/)) { + return parsePleromaAccount(target.href) } if (target.parentNode === undefined || target.parentNode === null) { return null @@ -52,7 +56,7 @@ export function findAccount (target, parentClass = 'toot') { return findAccount(target.parentNode, parentClass) } -export function parseAccount (accountURL) { +export function parseMastodonAccount (accountURL) { const res = accountURL.match(/^https:\/\/([a-zA-Z0-9-.]+)\/(@[a-zA-Z0-9-_.]+)/) const domainName = res[1] const accountName = res[2] @@ -61,3 +65,13 @@ export function parseAccount (accountURL) { acct: `${accountName}@${domainName}` } } + +export function parsePleromaAccount (accountURL) { + const res = accountURL.match(/^https:\/\/([a-zA-Z0-9-.]+)\/users\/([a-zA-Z0-9-_.]+)/) + const domainName = res[1] + const accountName = res[2] + return { + username: `@${accountName}`, + acct: `@${accountName}@${domainName}` + } +} diff --git a/test/mocha/tootParser.spec.js b/test/mocha/tootParser.spec.js index 5191bd47..fb7a6613 100644 --- a/test/mocha/tootParser.spec.js +++ b/test/mocha/tootParser.spec.js @@ -56,18 +56,35 @@ I released Whalebird version 2.4.1. In version 2.4.0, Whalebird supports streami }) describe('findAccount', () => { - context('Pleroma', () => { - const doc = (new JSDOM(` + context('in Pleroma', () => { + context('from Mastodon', () => { + const doc = (new JSDOM(`

@h3_poteto hogehoge

`)).window.document - const target = doc.getElementById('user') - it('should find', () => { - const res = findAccount(target) - assert.strictEqual(res.username, '@h3_poteto') - assert.strictEqual(res.acct, '@h3_poteto@social.mikutter.hachune.net') + const target = doc.getElementById('user') + it('should find', () => { + const res = findAccount(target) + assert.strictEqual(res.username, '@h3_poteto') + assert.strictEqual(res.acct, '@h3_poteto@social.mikutter.hachune.net') + }) + }) + + context('from Pleroma', () => { + const doc = (new JSDOM(` +
+

@h3_poteto hogehoge

+
+ +`)).window.document + const target = doc.getElementById('user') + it('should find', () => { + const res = findAccount(target) + assert.strictEqual(res.username, '@h3poteto') + assert.strictEqual(res.acct, '@h3poteto@pleroma.io') + }) }) }) })