Merge pull request #780 from amyspark/find-pleroma-accounts
Improve searching accounts with Pleroma/MastoFE
This commit is contained in:
commit
55cb48a0a1
|
@ -40,12 +40,16 @@ const AccountProfile = {
|
|||
rootState.TimelineSpace.account.accessToken,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1'
|
||||
)
|
||||
return client.get('/search', { q: parsedAccount.acct, resolve: true })
|
||||
return client.get('/search', { q: parsedAccount.url, resolve: true })
|
||||
.then(res => {
|
||||
if (res.data.accounts.length <= 0) throw new AccountNotFound('empty result')
|
||||
const account = res.data.accounts.find(a => `@${a.acct}` === parsedAccount.acct)
|
||||
if (account) return account
|
||||
const user = res.data.accounts.find(a => `@${a.username}@${rootState.TimelineSpace.account.domain}` === parsedAccount.acct)
|
||||
const pleromaUser = res.data.accounts.find(a => a.acct === parsedAccount.acct)
|
||||
if (pleromaUser) return pleromaUser
|
||||
const localUser = res.data.accounts.find(a => `@${a.username}@${rootState.TimelineSpace.account.domain}` === parsedAccount.acct)
|
||||
if (localUser) return localUser
|
||||
const user = res.data.accounts.find(a => a.url === parsedAccount.url)
|
||||
if (!user) throw new AccountNotFound('not found')
|
||||
return user
|
||||
})
|
||||
|
|
|
@ -36,8 +36,12 @@ export function parseTag (tagURL) {
|
|||
|
||||
export function findAccount (target, parentClass = 'toot') {
|
||||
if (target.getAttribute('class') && target.getAttribute('class').includes('u-url')) {
|
||||
if (target.href && target.href.match(/^https:\/\/[a-zA-Z0-9-.]+\/users\/[a-zA-Z0-9-_.]+/)) {
|
||||
return parsePleromaAccount(target.href)
|
||||
} else {
|
||||
return parseMastodonAccount(target.href)
|
||||
}
|
||||
}
|
||||
// In Pleroma, link does not have class.
|
||||
// So we have to check URL.
|
||||
if (target.href && target.href.match(/^https:\/\/[a-zA-Z0-9-.]+\/@[a-zA-Z0-9-_.]+/)) {
|
||||
|
@ -62,7 +66,8 @@ export function parseMastodonAccount (accountURL) {
|
|||
const accountName = res[2]
|
||||
return {
|
||||
username: accountName,
|
||||
acct: `${accountName}@${domainName}`
|
||||
acct: `${accountName}@${domainName}`,
|
||||
url: accountURL
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,6 +77,7 @@ export function parsePleromaAccount (accountURL) {
|
|||
const accountName = res[2]
|
||||
return {
|
||||
username: `@${accountName}`,
|
||||
acct: `@${accountName}@${domainName}`
|
||||
acct: `@${accountName}@${domainName}`,
|
||||
url: accountURL
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue