split timelines part into its own file
This commit is contained in:
parent
0908d2bb65
commit
495e6143d4
5 changed files with 202 additions and 195 deletions
|
|
@ -1,8 +1,7 @@
|
|||
import { paramsString, promisedRequest } from './helpers.js'
|
||||
import { MASTODON_USER_TIMELINE_URL } from './timelines.js'
|
||||
|
||||
import {
|
||||
parseLinkHeaderPagination,
|
||||
parseNotification,
|
||||
parseSource,
|
||||
parseStatus,
|
||||
parseUser,
|
||||
|
|
@ -15,15 +14,6 @@ const MASTODON_REGISTRATION_URL = '/api/v1/accounts'
|
|||
const MASTODON_PASSWORD_RESET_URL = ({ email }) =>
|
||||
`/auth/password${paramsString({ email })}`
|
||||
|
||||
const MASTODON_USER_NOTIFICATIONS_URL = ({
|
||||
minId,
|
||||
sinceId,
|
||||
maxId,
|
||||
limit,
|
||||
includeTypes,
|
||||
replyVisibility,
|
||||
}) =>
|
||||
`/api/v1/notifications${paramsString({ minId, sinceId, maxId, limit, includeTypes, replyVisibility })}`
|
||||
const MASTODON_FOLLOWING_URL = (
|
||||
id,
|
||||
{ minId, maxId, sinceId, limit, withRelationships },
|
||||
|
|
@ -35,84 +25,6 @@ const MASTODON_FOLLOWERS_URL = (
|
|||
) =>
|
||||
`/api/v1/accounts/${id}/followers${paramsString({ minId, maxId, sinceId, limit, withRelationships })}`
|
||||
|
||||
const MASTODON_USER_HOME_TIMELINE_URL = ({
|
||||
minId,
|
||||
sinceId,
|
||||
maxId,
|
||||
limit,
|
||||
replyVisibility,
|
||||
}) =>
|
||||
`/api/v1/timelines/home${paramsString({ minId, sinceId, maxId, limit, replyVisibility })}`
|
||||
const MASTODON_LIST_TIMELINE_URL = (
|
||||
id,
|
||||
{ minId, sinceId, maxId, limit, replyVisibility },
|
||||
) =>
|
||||
`/api/v1/timelines/list/${id}${paramsString({ minId, sinceId, maxId, limit, replyVisibility })}`
|
||||
const MASTODON_DIRECT_MESSAGES_TIMELINE_URL = ({
|
||||
minId,
|
||||
sinceId,
|
||||
maxId,
|
||||
limit,
|
||||
replyVisibility,
|
||||
}) =>
|
||||
`/api/v1/timelines/direct${paramsString({ minId, sinceId, maxId, limit, replyVisibility })}`
|
||||
const MASTODON_PUBLIC_TIMELINE = ({
|
||||
minId,
|
||||
sinceId,
|
||||
maxId,
|
||||
limit,
|
||||
replyVisibility,
|
||||
local,
|
||||
remote,
|
||||
onlyMedia,
|
||||
}) =>
|
||||
`/api/v1/timelines/public${paramsString({ minId, sinceId, maxId, limit, replyVisibility, local, remote, onlyMedia })}`
|
||||
const MASTODON_TAG_TIMELINE_URL = (
|
||||
tag,
|
||||
{ minId, sinceId, maxId, limit, replyVisibility },
|
||||
) =>
|
||||
`/api/v1/timelines/tag/${tag}${paramsString({ minId, sinceId, maxId, limit, replyVisibility })}`
|
||||
const MASTODON_USER_TIMELINE_URL = (
|
||||
id,
|
||||
{ minId, sinceId, maxId, limit, replyVisibility, pinned, onlyMedia },
|
||||
) =>
|
||||
`/api/v1/accounts/${id}/statuses${paramsString({ minId, sinceId, maxId, limit, replyVisibility, pinned, onlyMedia })}`
|
||||
const MASTODON_USER_FAVORITES_TIMELINE_URL = ({
|
||||
minId,
|
||||
sinceId,
|
||||
maxId,
|
||||
limit,
|
||||
replyVisibility,
|
||||
}) =>
|
||||
`/api/v1/favourites${paramsString({ minId, sinceId, maxId, limit, replyVisibility })}`
|
||||
const MASTODON_BOOKMARK_TIMELINE_URL = ({
|
||||
minId,
|
||||
sinceId,
|
||||
maxId,
|
||||
limit,
|
||||
replyVisibility,
|
||||
folderId,
|
||||
}) =>
|
||||
`/api/v1/bookmarks${paramsString({ minId, sinceId, maxId, limit, replyVisibility, folderId })}`
|
||||
const PLEROMA_STATUS_QUOTES_URL = (
|
||||
id,
|
||||
{ minId, sinceId, maxId, limit, replyVisibility },
|
||||
) =>
|
||||
`/api/v1/pleroma/statuses/${id}/quotes${paramsString({ minId, sinceId, maxId, limit, replyVisibility })}`
|
||||
const PLEROMA_USER_FAVORITES_TIMELINE_URL = (
|
||||
id,
|
||||
{ minId, sinceId, maxId, limit, replyVisibility },
|
||||
) =>
|
||||
`/api/v1/pleroma/accounts/${id}/favourites${paramsString({ minId, sinceId, maxId, limit, replyVisibility })}`
|
||||
const AKKOMA_BUBBLE_TIMELINE_URL = ({
|
||||
minId,
|
||||
sinceId,
|
||||
maxId,
|
||||
limit,
|
||||
replyVisibility,
|
||||
}) =>
|
||||
`/api/v1/timelines/bubble${paramsString({ minId, sinceId, maxId, limit, replyVisibility })}`
|
||||
|
||||
export const MASTODON_STATUS_URL = (id) => `/api/v1/statuses/${id}`
|
||||
const MASTODON_STATUS_CONTEXT_URL = (id) => `/api/v1/statuses/${id}/context`
|
||||
const MASTODON_STATUS_SOURCE_URL = (id) => `/api/v1/statuses/${id}/source`
|
||||
|
|
@ -275,109 +187,6 @@ export const fetchStatusHistory = ({ status, credentials }) =>
|
|||
})
|
||||
})
|
||||
|
||||
export const fetchTimeline = ({
|
||||
timeline,
|
||||
credentials,
|
||||
sinceId,
|
||||
minId,
|
||||
maxId,
|
||||
userId,
|
||||
listId,
|
||||
statusId,
|
||||
tag,
|
||||
withMuted,
|
||||
replyVisibility = 'all',
|
||||
includeTypes = [],
|
||||
bookmarkFolderId,
|
||||
}) => {
|
||||
const timelineUrls = {
|
||||
friends: MASTODON_USER_HOME_TIMELINE_URL,
|
||||
public: MASTODON_PUBLIC_TIMELINE,
|
||||
publicAndExternal: MASTODON_PUBLIC_TIMELINE,
|
||||
dms: MASTODON_DIRECT_MESSAGES_TIMELINE_URL,
|
||||
user: MASTODON_USER_TIMELINE_URL,
|
||||
media: MASTODON_USER_TIMELINE_URL,
|
||||
list: MASTODON_LIST_TIMELINE_URL,
|
||||
favorites: MASTODON_USER_FAVORITES_TIMELINE_URL,
|
||||
publicFavorites: PLEROMA_USER_FAVORITES_TIMELINE_URL,
|
||||
bookmarks: MASTODON_BOOKMARK_TIMELINE_URL,
|
||||
bubble: AKKOMA_BUBBLE_TIMELINE_URL,
|
||||
tag: MASTODON_TAG_TIMELINE_URL,
|
||||
quotes: PLEROMA_STATUS_QUOTES_URL,
|
||||
|
||||
notifications: MASTODON_USER_NOTIFICATIONS_URL,
|
||||
}
|
||||
const urlFunc = timelineUrls[timeline]
|
||||
|
||||
const twoArgs = new Set([
|
||||
'user',
|
||||
'media',
|
||||
'list',
|
||||
'publicFavorites',
|
||||
'tag',
|
||||
'quotes',
|
||||
])
|
||||
|
||||
const params = {
|
||||
minId,
|
||||
sinceId,
|
||||
maxId,
|
||||
limit: 20,
|
||||
}
|
||||
|
||||
const id = (() => {
|
||||
switch (timeline) {
|
||||
case 'user':
|
||||
case 'media':
|
||||
return userId
|
||||
case 'list':
|
||||
return listId
|
||||
case 'quotes':
|
||||
return statusId
|
||||
case 'tag':
|
||||
return tag
|
||||
}
|
||||
})()
|
||||
|
||||
const isNotifications = timeline === 'notifications'
|
||||
|
||||
if (timeline === 'media') {
|
||||
params.onlyMedia = true
|
||||
}
|
||||
if (timeline === 'public') {
|
||||
params.local = true
|
||||
}
|
||||
if (timeline !== 'favorites' && timeline !== 'bookmarks') {
|
||||
params.withMuted = withMuted
|
||||
}
|
||||
if (replyVisibility !== 'all') {
|
||||
params.replyVisibility = replyVisibility
|
||||
}
|
||||
if (timeline === 'bookmarks' && bookmarkFolderId) {
|
||||
params.folderId = bookmarkFolderId
|
||||
}
|
||||
|
||||
if (isNotifications && includeTypes.length > 0) {
|
||||
params.includeTypes = includeTypes
|
||||
}
|
||||
|
||||
const url = twoArgs.has(timeline) ? urlFunc(id, params) : urlFunc(params)
|
||||
return promisedRequest({ url, credentials }).then((result) => {
|
||||
const pagination = parseLinkHeaderPagination(
|
||||
result.response.headers.get('Link'),
|
||||
{
|
||||
flakeId: timeline !== 'bookmarks' && timeline !== 'notifications',
|
||||
},
|
||||
)
|
||||
|
||||
return {
|
||||
...result,
|
||||
data: result.data.map(isNotifications ? parseNotification : parseStatus),
|
||||
pagination,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const listEmojiPacks = ({ page, pageSize, credentials }) =>
|
||||
promisedRequest({
|
||||
url: EMOJI_PACKS_URL(page, pageSize),
|
||||
|
|
|
|||
198
src/api/timelines.js
Normal file
198
src/api/timelines.js
Normal file
|
|
@ -0,0 +1,198 @@
|
|||
import { paramsString, promisedRequest } from './helpers.js'
|
||||
|
||||
import {
|
||||
parseLinkHeaderPagination,
|
||||
parseNotification,
|
||||
parseStatus,
|
||||
} from 'src/services/entity_normalizer/entity_normalizer.service.js'
|
||||
|
||||
const MASTODON_USER_HOME_TIMELINE_URL = ({
|
||||
minId,
|
||||
sinceId,
|
||||
maxId,
|
||||
limit,
|
||||
replyVisibility,
|
||||
}) =>
|
||||
`/api/v1/timelines/home${paramsString({ minId, sinceId, maxId, limit, replyVisibility })}`
|
||||
const MASTODON_LIST_TIMELINE_URL = (
|
||||
id,
|
||||
{ minId, sinceId, maxId, limit, replyVisibility },
|
||||
) =>
|
||||
`/api/v1/timelines/list/${id}${paramsString({ minId, sinceId, maxId, limit, replyVisibility })}`
|
||||
const MASTODON_DIRECT_MESSAGES_TIMELINE_URL = ({
|
||||
minId,
|
||||
sinceId,
|
||||
maxId,
|
||||
limit,
|
||||
replyVisibility,
|
||||
}) =>
|
||||
`/api/v1/timelines/direct${paramsString({ minId, sinceId, maxId, limit, replyVisibility })}`
|
||||
const MASTODON_PUBLIC_TIMELINE = ({
|
||||
minId,
|
||||
sinceId,
|
||||
maxId,
|
||||
limit,
|
||||
replyVisibility,
|
||||
local,
|
||||
remote,
|
||||
onlyMedia,
|
||||
}) =>
|
||||
`/api/v1/timelines/public${paramsString({ minId, sinceId, maxId, limit, replyVisibility, local, remote, onlyMedia })}`
|
||||
const MASTODON_TAG_TIMELINE_URL = (
|
||||
tag,
|
||||
{ minId, sinceId, maxId, limit, replyVisibility },
|
||||
) =>
|
||||
`/api/v1/timelines/tag/${tag}${paramsString({ minId, sinceId, maxId, limit, replyVisibility })}`
|
||||
export const MASTODON_USER_TIMELINE_URL = (
|
||||
id,
|
||||
{ minId, sinceId, maxId, limit, replyVisibility, pinned, onlyMedia },
|
||||
) =>
|
||||
`/api/v1/accounts/${id}/statuses${paramsString({ minId, sinceId, maxId, limit, replyVisibility, pinned, onlyMedia })}`
|
||||
const MASTODON_USER_FAVORITES_TIMELINE_URL = ({
|
||||
minId,
|
||||
sinceId,
|
||||
maxId,
|
||||
limit,
|
||||
replyVisibility,
|
||||
}) =>
|
||||
`/api/v1/favourites${paramsString({ minId, sinceId, maxId, limit, replyVisibility })}`
|
||||
const MASTODON_BOOKMARK_TIMELINE_URL = ({
|
||||
minId,
|
||||
sinceId,
|
||||
maxId,
|
||||
limit,
|
||||
replyVisibility,
|
||||
folderId,
|
||||
}) =>
|
||||
`/api/v1/bookmarks${paramsString({ minId, sinceId, maxId, limit, replyVisibility, folderId })}`
|
||||
const PLEROMA_STATUS_QUOTES_URL = (
|
||||
id,
|
||||
{ minId, sinceId, maxId, limit, replyVisibility },
|
||||
) =>
|
||||
`/api/v1/pleroma/statuses/${id}/quotes${paramsString({ minId, sinceId, maxId, limit, replyVisibility })}`
|
||||
const PLEROMA_USER_FAVORITES_TIMELINE_URL = (
|
||||
id,
|
||||
{ minId, sinceId, maxId, limit, replyVisibility },
|
||||
) =>
|
||||
`/api/v1/pleroma/accounts/${id}/favourites${paramsString({ minId, sinceId, maxId, limit, replyVisibility })}`
|
||||
const AKKOMA_BUBBLE_TIMELINE_URL = ({
|
||||
minId,
|
||||
sinceId,
|
||||
maxId,
|
||||
limit,
|
||||
replyVisibility,
|
||||
}) =>
|
||||
`/api/v1/timelines/bubble${paramsString({ minId, sinceId, maxId, limit, replyVisibility })}`
|
||||
|
||||
const MASTODON_USER_NOTIFICATIONS_URL = ({
|
||||
minId,
|
||||
sinceId,
|
||||
maxId,
|
||||
limit,
|
||||
includeTypes,
|
||||
replyVisibility,
|
||||
}) =>
|
||||
`/api/v1/notifications${paramsString({ minId, sinceId, maxId, limit, includeTypes, replyVisibility })}`
|
||||
|
||||
export const fetchTimeline = ({
|
||||
timeline,
|
||||
credentials,
|
||||
sinceId,
|
||||
minId,
|
||||
maxId,
|
||||
userId,
|
||||
listId,
|
||||
statusId,
|
||||
tag,
|
||||
withMuted,
|
||||
replyVisibility = 'all',
|
||||
includeTypes = [],
|
||||
bookmarkFolderId,
|
||||
}) => {
|
||||
const timelineUrls = {
|
||||
friends: MASTODON_USER_HOME_TIMELINE_URL,
|
||||
public: MASTODON_PUBLIC_TIMELINE,
|
||||
publicAndExternal: MASTODON_PUBLIC_TIMELINE,
|
||||
dms: MASTODON_DIRECT_MESSAGES_TIMELINE_URL,
|
||||
user: MASTODON_USER_TIMELINE_URL,
|
||||
media: MASTODON_USER_TIMELINE_URL,
|
||||
list: MASTODON_LIST_TIMELINE_URL,
|
||||
favorites: MASTODON_USER_FAVORITES_TIMELINE_URL,
|
||||
publicFavorites: PLEROMA_USER_FAVORITES_TIMELINE_URL,
|
||||
bookmarks: MASTODON_BOOKMARK_TIMELINE_URL,
|
||||
bubble: AKKOMA_BUBBLE_TIMELINE_URL,
|
||||
tag: MASTODON_TAG_TIMELINE_URL,
|
||||
quotes: PLEROMA_STATUS_QUOTES_URL,
|
||||
|
||||
notifications: MASTODON_USER_NOTIFICATIONS_URL,
|
||||
}
|
||||
const urlFunc = timelineUrls[timeline]
|
||||
|
||||
const twoArgs = new Set([
|
||||
'user',
|
||||
'media',
|
||||
'list',
|
||||
'publicFavorites',
|
||||
'tag',
|
||||
'quotes',
|
||||
])
|
||||
|
||||
const params = {
|
||||
minId,
|
||||
sinceId,
|
||||
maxId,
|
||||
limit: 20,
|
||||
}
|
||||
|
||||
const id = (() => {
|
||||
switch (timeline) {
|
||||
case 'user':
|
||||
case 'media':
|
||||
return userId
|
||||
case 'list':
|
||||
return listId
|
||||
case 'quotes':
|
||||
return statusId
|
||||
case 'tag':
|
||||
return tag
|
||||
}
|
||||
})()
|
||||
|
||||
const isNotifications = timeline === 'notifications'
|
||||
|
||||
if (timeline === 'media') {
|
||||
params.onlyMedia = true
|
||||
}
|
||||
if (timeline === 'public') {
|
||||
params.local = true
|
||||
}
|
||||
if (timeline !== 'favorites' && timeline !== 'bookmarks') {
|
||||
params.withMuted = withMuted
|
||||
}
|
||||
if (replyVisibility !== 'all') {
|
||||
params.replyVisibility = replyVisibility
|
||||
}
|
||||
if (timeline === 'bookmarks' && bookmarkFolderId) {
|
||||
params.folderId = bookmarkFolderId
|
||||
}
|
||||
|
||||
if (isNotifications && includeTypes.length > 0) {
|
||||
params.includeTypes = includeTypes
|
||||
}
|
||||
|
||||
const url = twoArgs.has(timeline) ? urlFunc(id, params) : urlFunc(params)
|
||||
return promisedRequest({ url, credentials }).then((result) => {
|
||||
const pagination = parseLinkHeaderPagination(
|
||||
result.response.headers.get('Link'),
|
||||
{
|
||||
flakeId: timeline !== 'bookmarks' && timeline !== 'notifications',
|
||||
},
|
||||
)
|
||||
|
||||
return {
|
||||
...result,
|
||||
data: result.data.map(isNotifications ? parseNotification : parseStatus),
|
||||
pagination,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ import { useInterfaceStore } from 'src/stores/interface.js'
|
|||
import { useOAuthStore } from 'src/stores/oauth.js'
|
||||
import { useShoutStore } from 'src/stores/shout.js'
|
||||
|
||||
import { fetchTimeline } from 'src/api/public.js'
|
||||
import { fetchTimeline } from 'src/api/timelines.js'
|
||||
import {
|
||||
getMastodonSocketURI,
|
||||
ProcessedWS,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.j
|
|||
import { useInterfaceStore } from 'src/stores/interface.js'
|
||||
import { useMergedConfigStore } from 'src/stores/merged_config.js'
|
||||
|
||||
import { fetchTimeline } from 'src/api/public.js'
|
||||
import { fetchTimeline } from 'src/api/timelines.js'
|
||||
|
||||
const update = ({ store, notifications, older }) => {
|
||||
store.dispatch('addNewNotifications', { notifications, older })
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.j
|
|||
import { useInterfaceStore } from 'src/stores/interface.js'
|
||||
import { useMergedConfigStore } from 'src/stores/merged_config.js'
|
||||
|
||||
import { fetchTimeline } from 'src/api/public.js'
|
||||
import { fetchTimeline } from 'src/api/timelines.js'
|
||||
|
||||
const update = ({
|
||||
store,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue