Merge pull request #670 from h3poteto/iss-668

closes #668 Block to open account profile when the account is not found
This commit is contained in:
AkiraFukushima 2018-10-20 21:57:20 +09:00 committed by GitHub
commit c18408ab53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 17 deletions

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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}`
}
}

View File

@ -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')
})
})
})