mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Improve account page
This commit is contained in:
@ -15,7 +15,6 @@ import { useNavState } from '@utils/navigation/navigators'
|
||||
import { queryClient } from '@utils/queryHooks'
|
||||
import { getAccountStorage, setAccountStorage } from '@utils/storage/actions'
|
||||
import { AxiosError } from 'axios'
|
||||
import { uniqBy } from 'lodash'
|
||||
import { searchLocalStatus } from './search'
|
||||
import deleteItem from './timeline/deleteItem'
|
||||
import editItem from './timeline/editItem'
|
||||
@ -43,10 +42,9 @@ export type QueryKeyTimeline = [
|
||||
}
|
||||
| {
|
||||
page: 'Account'
|
||||
type: 'default' | 'attachments'
|
||||
id?: Mastodon.Account['id']
|
||||
exclude_reblogs: boolean
|
||||
only_media: boolean
|
||||
// remote info
|
||||
// remote
|
||||
remote_id?: Mastodon.Account['id']
|
||||
remote_domain?: string
|
||||
}
|
||||
@ -163,139 +161,82 @@ export const queryFunctionTimeline = async ({
|
||||
})
|
||||
|
||||
case 'Account':
|
||||
const reject = Promise.reject('Timeline query account id not provided')
|
||||
if (!page.id) return Promise.reject('Timeline account missing id')
|
||||
|
||||
if (page.only_media) {
|
||||
let res
|
||||
if (page.remote_domain && page.remote_id) {
|
||||
res = await apiGeneral<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
domain: page.remote_domain,
|
||||
url: `api/v1/accounts/${page.remote_id}/statuses`,
|
||||
params: {
|
||||
only_media: true,
|
||||
...params
|
||||
}
|
||||
})
|
||||
.then(res => ({
|
||||
...res,
|
||||
body: res.body.map(status => appendRemote.status(status, page.remote_domain!))
|
||||
}))
|
||||
.catch(() => {})
|
||||
}
|
||||
if (!res && page.id) {
|
||||
res = await apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
url: `accounts/${page.id}/statuses`,
|
||||
params: {
|
||||
only_media: true,
|
||||
...params
|
||||
}
|
||||
})
|
||||
}
|
||||
return res || reject
|
||||
} else if (page.exclude_reblogs) {
|
||||
if (pageParam && pageParam.hasOwnProperty('max_id')) {
|
||||
let res
|
||||
if (page.remote_domain && page.remote_id) {
|
||||
res = await apiGeneral<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
domain: page.remote_domain,
|
||||
url: `api/v1/accounts/${page.remote_id}/statuses`,
|
||||
params: {
|
||||
exclude_replies: true,
|
||||
...params
|
||||
}
|
||||
})
|
||||
.then(res => ({
|
||||
...res,
|
||||
body: res.body.map(status => appendRemote.status(status, page.remote_domain!))
|
||||
}))
|
||||
.catch(() => {})
|
||||
let typeParams
|
||||
switch (page.type) {
|
||||
case 'default':
|
||||
const filters = getAccountStorage.object('page_account_timeline')
|
||||
typeParams = {
|
||||
exclude_reblogs:
|
||||
typeof filters?.excludeBoosts === 'boolean' ? filters.excludeBoosts : true,
|
||||
exclude_replies:
|
||||
typeof filters?.excludeReplies === 'boolean' ? filters.excludeReplies : true
|
||||
}
|
||||
if (!res && page.id) {
|
||||
res = await apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
url: `accounts/${page.id}/statuses`,
|
||||
params: {
|
||||
exclude_replies: true,
|
||||
...params
|
||||
}
|
||||
})
|
||||
}
|
||||
return res || reject
|
||||
} else {
|
||||
let res
|
||||
if (page.remote_domain && page.remote_id) {
|
||||
res = await apiGeneral<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
domain: page.remote_domain,
|
||||
url: `api/v1/accounts/${page.remote_id}/statuses`,
|
||||
params: { exclude_replies: true }
|
||||
})
|
||||
.then(res => ({
|
||||
...res,
|
||||
body: res.body.map(status => appendRemote.status(status, page.remote_domain!))
|
||||
}))
|
||||
.catch(() => {})
|
||||
}
|
||||
if (!res && page.id) {
|
||||
const resPinned = await apiInstance<(Mastodon.Status & { _pinned: boolean })[]>({
|
||||
method: 'get',
|
||||
url: `accounts/${page.id}/statuses`,
|
||||
params: { pinned: true }
|
||||
}).then(res => ({
|
||||
...res,
|
||||
body: res.body.map(status => {
|
||||
status._pinned = true
|
||||
return status
|
||||
})
|
||||
}))
|
||||
const resDefault = await apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
url: `accounts/${page.id}/statuses`,
|
||||
params: { exclude_replies: true }
|
||||
})
|
||||
return {
|
||||
body: uniqBy([...resPinned.body, ...resDefault.body], 'id'),
|
||||
links: resDefault.links
|
||||
}
|
||||
}
|
||||
return res || reject
|
||||
}
|
||||
} else {
|
||||
let res
|
||||
if (page.remote_domain && page.remote_id) {
|
||||
res = await apiGeneral<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
domain: page.remote_domain,
|
||||
url: `api/v1/accounts/${page.remote_id}/statuses`,
|
||||
params: {
|
||||
...params,
|
||||
exclude_replies: false,
|
||||
only_media: false
|
||||
}
|
||||
})
|
||||
.then(res => ({
|
||||
...res,
|
||||
body: res.body.map(status => appendRemote.status(status, page.remote_domain!))
|
||||
}))
|
||||
.catch(() => {})
|
||||
}
|
||||
if (!res && page.id) {
|
||||
res = await apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
url: `accounts/${page.id}/statuses`,
|
||||
params: {
|
||||
...params,
|
||||
exclude_replies: false,
|
||||
only_media: false
|
||||
}
|
||||
})
|
||||
}
|
||||
return res || reject
|
||||
break
|
||||
case 'attachments':
|
||||
typeParams = { only_media: true, exclude_reblogs: true }
|
||||
break
|
||||
}
|
||||
|
||||
let pinned
|
||||
if (page.type === 'default' && !params.hasOwnProperty('max_id')) {
|
||||
if (page.remote_domain && page.remote_id) {
|
||||
pinned = await apiGeneral<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
domain: page.remote_domain,
|
||||
url: `api/v1/accounts/${page.remote_id}/statuses`,
|
||||
params: { pinned: true }
|
||||
})
|
||||
.then(res => ({
|
||||
...res,
|
||||
body: res.body.map(status => appendRemote.status(status, page.remote_domain!))
|
||||
}))
|
||||
.catch(() => {})
|
||||
}
|
||||
if (!pinned) {
|
||||
pinned = await apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
url: `accounts/${page.id}/statuses`,
|
||||
params: { pinned: true }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
let res
|
||||
if (page.remote_domain && page.remote_id) {
|
||||
res = await apiGeneral<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
domain: page.remote_domain,
|
||||
url: `api/v1/accounts/${page.remote_id}/statuses`,
|
||||
params: {
|
||||
...typeParams,
|
||||
...params
|
||||
}
|
||||
})
|
||||
.then(res => ({
|
||||
...res,
|
||||
body: res.body.map(status => appendRemote.status(status, page.remote_domain!))
|
||||
}))
|
||||
.catch(() => {})
|
||||
}
|
||||
if (!res) {
|
||||
res = await apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
url: `accounts/${page.id}/statuses`,
|
||||
params: {
|
||||
...typeParams,
|
||||
...params
|
||||
}
|
||||
})
|
||||
}
|
||||
return pinned
|
||||
? {
|
||||
body: [...pinned.body.map(status => ({ ...status, _pinned: true })), ...res.body],
|
||||
links: res.links
|
||||
}
|
||||
: res
|
||||
|
||||
case 'Hashtag':
|
||||
return apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
|
@ -53,6 +53,10 @@ export type AccountV0 = {
|
||||
unread: number
|
||||
}
|
||||
}
|
||||
page_account_timeline: {
|
||||
excludeBoosts: boolean
|
||||
excludeReplies: boolean
|
||||
}
|
||||
drafts: ComposeStateDraft[]
|
||||
emojis_frequent: {
|
||||
emoji: Pick<Mastodon.Emoji, 'url' | 'shortcode' | 'static_url'>
|
||||
|
Reference in New Issue
Block a user