2018-06-13 16:38:36 +02:00
|
|
|
import { get, paramsString, DEFAULT_TIMEOUT } from '../_utils/ajax'
|
2018-02-24 23:49:28 +01:00
|
|
|
import { auth, basename } from './utils'
|
2018-01-19 05:25:34 +01:00
|
|
|
|
2018-02-09 07:29:29 +01:00
|
|
|
function getTimelineUrlPath (timeline) {
|
2018-01-22 05:02:32 +01:00
|
|
|
switch (timeline) {
|
|
|
|
case 'local':
|
|
|
|
case 'federated':
|
2018-01-23 06:16:27 +01:00
|
|
|
return 'timelines/public'
|
2018-01-22 05:02:32 +01:00
|
|
|
case 'home':
|
2018-01-23 06:16:27 +01:00
|
|
|
return 'timelines/home'
|
2018-02-04 03:06:02 +01:00
|
|
|
case 'notifications':
|
2019-05-05 02:58:44 +02:00
|
|
|
case 'notifications/mentions':
|
2018-02-04 03:06:02 +01:00
|
|
|
return 'notifications'
|
2018-02-08 07:49:50 +01:00
|
|
|
case 'favorites':
|
|
|
|
return 'favourites'
|
2019-04-13 20:04:39 +02:00
|
|
|
case 'direct':
|
2019-04-02 12:05:27 +02:00
|
|
|
return 'conversations'
|
2018-01-23 06:16:27 +01:00
|
|
|
}
|
|
|
|
if (timeline.startsWith('tag/')) {
|
|
|
|
return 'timelines/tag'
|
|
|
|
} else if (timeline.startsWith('account/')) {
|
|
|
|
return 'accounts'
|
2018-02-08 18:15:25 +01:00
|
|
|
} else if (timeline.startsWith('list/')) {
|
|
|
|
return 'timelines/list'
|
2018-01-22 05:02:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-13 20:04:39 +02:00
|
|
|
export async function getTimeline (instanceName, accessToken, timeline, maxId, since, limit) {
|
2018-01-23 06:16:27 +01:00
|
|
|
let timelineUrlName = getTimelineUrlPath(timeline)
|
|
|
|
let url = `${basename(instanceName)}/api/v1/${timelineUrlName}`
|
2018-01-19 05:25:34 +01:00
|
|
|
|
2018-01-22 05:02:32 +01:00
|
|
|
if (timeline.startsWith('tag/')) {
|
2019-03-31 06:48:49 +02:00
|
|
|
url += '/' + timeline.split('/')[1]
|
2018-01-23 06:16:27 +01:00
|
|
|
} else if (timeline.startsWith('account/')) {
|
2019-03-31 06:48:49 +02:00
|
|
|
url += '/' + timeline.split('/')[1] + '/statuses'
|
2018-02-08 18:15:25 +01:00
|
|
|
} else if (timeline.startsWith('list/')) {
|
2019-03-31 06:48:49 +02:00
|
|
|
url += '/' + timeline.split('/')[1]
|
2018-01-22 05:02:32 +01:00
|
|
|
}
|
|
|
|
|
2018-01-19 05:25:34 +01:00
|
|
|
let params = {}
|
|
|
|
if (since) {
|
|
|
|
params.since = since
|
|
|
|
}
|
|
|
|
|
|
|
|
if (maxId) {
|
|
|
|
params.max_id = maxId
|
|
|
|
}
|
|
|
|
|
2018-08-30 07:49:14 +02:00
|
|
|
if (limit) {
|
|
|
|
params.limit = limit
|
|
|
|
}
|
|
|
|
|
2018-01-19 08:37:43 +01:00
|
|
|
if (timeline === 'local') {
|
|
|
|
params.local = true
|
|
|
|
}
|
|
|
|
|
2019-03-31 06:48:49 +02:00
|
|
|
if (timeline.startsWith('account/')) {
|
|
|
|
if (timeline.endsWith('media')) {
|
|
|
|
params.only_media = true
|
|
|
|
} else {
|
|
|
|
params.exclude_replies = !timeline.endsWith('/with_replies')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-05 02:58:44 +02:00
|
|
|
if (timeline === 'notifications/mentions') {
|
|
|
|
params.exclude_types = ['follow', 'favourite', 'reblog', 'poll']
|
|
|
|
}
|
|
|
|
|
2018-01-19 05:25:34 +01:00
|
|
|
url += '?' + paramsString(params)
|
|
|
|
|
2019-04-13 20:04:39 +02:00
|
|
|
const items = await get(url, auth(accessToken), { timeout: DEFAULT_TIMEOUT })
|
2019-04-02 12:05:27 +02:00
|
|
|
|
2019-04-13 20:04:39 +02:00
|
|
|
if (timeline === 'direct') {
|
|
|
|
return items.map(item => item.last_status)
|
|
|
|
}
|
|
|
|
return items
|
2018-02-09 07:29:29 +01:00
|
|
|
}
|