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:
commit
c18408ab53
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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}`
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue