refs #991 Use acccounts/search API for suggest accounts
This commit is contained in:
parent
9466130cf4
commit
58b88cbcff
|
@ -1,6 +1,6 @@
|
||||||
import { ipcRenderer } from 'electron'
|
import { ipcRenderer } from 'electron'
|
||||||
import emojilib from 'emojilib'
|
import emojilib from 'emojilib'
|
||||||
import Mastodon, { Response, Results } from 'megalodon'
|
import Mastodon, { Account, Response, Results } from 'megalodon'
|
||||||
import { Module, MutationTree, ActionTree, GetterTree } from 'vuex'
|
import { Module, MutationTree, ActionTree, GetterTree } from 'vuex'
|
||||||
import { RootState } from '@/store/index'
|
import { RootState } from '@/store/index'
|
||||||
import { LocalTag } from '~/src/types/localTag'
|
import { LocalTag } from '~/src/types/localTag'
|
||||||
|
@ -154,19 +154,19 @@ const actions: ActionTree<StatusState, RootState> = {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
const searchAPI = async () => {
|
const searchAPI = async () => {
|
||||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v2')
|
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||||
const res: Response<Results> = await client.get<Results>('/search', { q: word, resolve: false })
|
const res: Response<Array<Account>> = await client.get<Array<Account>>('/accounts/search', { q: word, resolve: false })
|
||||||
if (res.data.accounts.length === 0) throw new Error('Empty')
|
if (res.data.length === 0) throw new Error('Empty')
|
||||||
commit(MUTATION_TYPES.APPEND_FILTERED_ACCOUNTS, res.data.accounts.map(account => account.acct))
|
commit(MUTATION_TYPES.APPEND_FILTERED_ACCOUNTS, res.data.map(account => account.acct))
|
||||||
ipcRenderer.send('insert-cache-accounts', {
|
ipcRenderer.send('insert-cache-accounts', {
|
||||||
ownerID: rootState.TimelineSpace.account._id!,
|
ownerID: rootState.TimelineSpace.account._id!,
|
||||||
accts: res.data.accounts.map(a => a.acct)
|
accts: res.data.map(a => a.acct)
|
||||||
} as InsertAccountCache)
|
} as InsertAccountCache)
|
||||||
commit(MUTATION_TYPES.CHANGE_OPEN_SUGGEST, true)
|
commit(MUTATION_TYPES.CHANGE_OPEN_SUGGEST, true)
|
||||||
commit(MUTATION_TYPES.CHANGE_START_INDEX, start)
|
commit(MUTATION_TYPES.CHANGE_START_INDEX, start)
|
||||||
commit(MUTATION_TYPES.CHANGE_MATCH_WORD, word)
|
commit(MUTATION_TYPES.CHANGE_MATCH_WORD, word)
|
||||||
commit(MUTATION_TYPES.FILTERED_SUGGESTION_FROM_ACCOUNTS)
|
commit(MUTATION_TYPES.FILTERED_SUGGESTION_FROM_ACCOUNTS)
|
||||||
return res.data.accounts
|
return res.data
|
||||||
}
|
}
|
||||||
await Promise.all([searchCache(), searchAPI()])
|
await Promise.all([searchCache(), searchAPI()])
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue