2018-06-13 15:38:36 +01:00
|
|
|
import { get, paramsString, DEFAULT_TIMEOUT } from '../_utils/ajax'
|
2018-02-24 22:49:28 +00:00
|
|
|
import { auth, basename } from './utils'
|
2018-01-19 04:25:34 +00:00
|
|
|
|
2018-02-09 06:29:29 +00:00
|
|
|
function getTimelineUrlPath (timeline) {
|
2018-01-22 04:02:32 +00:00
|
|
|
switch (timeline) {
|
|
|
|
case 'local':
|
|
|
|
case 'federated':
|
2018-01-23 05:16:27 +00:00
|
|
|
return 'timelines/public'
|
2018-01-22 04:02:32 +00:00
|
|
|
case 'home':
|
2018-01-23 05:16:27 +00:00
|
|
|
return 'timelines/home'
|
2018-02-04 02:06:02 +00:00
|
|
|
case 'notifications':
|
|
|
|
return 'notifications'
|
2018-02-08 06:49:50 +00:00
|
|
|
case 'favorites':
|
|
|
|
return 'favourites'
|
2018-01-23 05:16:27 +00:00
|
|
|
}
|
|
|
|
if (timeline.startsWith('tag/')) {
|
|
|
|
return 'timelines/tag'
|
|
|
|
} else if (timeline.startsWith('account/')) {
|
|
|
|
return 'accounts'
|
2018-02-08 17:15:25 +00:00
|
|
|
} else if (timeline.startsWith('list/')) {
|
|
|
|
return 'timelines/list'
|
2018-01-22 04:02:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-30 06:49:14 +01:00
|
|
|
export function getTimeline (instanceName, accessToken, timeline, maxId, since, limit) {
|
2018-01-23 05:16:27 +00:00
|
|
|
let timelineUrlName = getTimelineUrlPath(timeline)
|
|
|
|
let url = `${basename(instanceName)}/api/v1/${timelineUrlName}`
|
2018-01-19 04:25:34 +00:00
|
|
|
|
2018-01-22 04:02:32 +00:00
|
|
|
if (timeline.startsWith('tag/')) {
|
|
|
|
url += '/' + timeline.split('/').slice(-1)[0]
|
2018-01-23 05:16:27 +00:00
|
|
|
} else if (timeline.startsWith('account/')) {
|
2018-02-08 17:15:25 +00:00
|
|
|
url += '/' + timeline.split('/').slice(-1)[0] + '/statuses'
|
|
|
|
} else if (timeline.startsWith('list/')) {
|
|
|
|
url += '/' + timeline.split('/').slice(-1)[0]
|
2018-01-22 04:02:32 +00:00
|
|
|
}
|
|
|
|
|
2018-01-19 04:25:34 +00:00
|
|
|
let params = {}
|
|
|
|
if (since) {
|
|
|
|
params.since = since
|
|
|
|
}
|
|
|
|
|
|
|
|
if (maxId) {
|
|
|
|
params.max_id = maxId
|
|
|
|
}
|
|
|
|
|
2018-08-30 06:49:14 +01:00
|
|
|
if (limit) {
|
|
|
|
params.limit = limit
|
|
|
|
}
|
|
|
|
|
2018-01-19 07:37:43 +00:00
|
|
|
if (timeline === 'local') {
|
|
|
|
params.local = true
|
|
|
|
}
|
|
|
|
|
2018-01-19 04:25:34 +00:00
|
|
|
url += '?' + paramsString(params)
|
|
|
|
|
2018-08-30 05:42:57 +01:00
|
|
|
return get(url, auth(accessToken), { timeout: DEFAULT_TIMEOUT })
|
2018-02-09 06:29:29 +00:00
|
|
|
}
|