@ -1,14 +1,8 @@
/* eslint-env browser */
/* eslint-env browser */
const LOGIN _URL = '/api/account/verify_credentials.json'
const LOGIN _URL = '/api/account/verify_credentials.json'
const FRIENDS _TIMELINE _URL = '/api/statuses/friends_timeline.json'
const ALL _FOLLOWING _URL = '/api/qvitter/allfollowing'
const ALL _FOLLOWING _URL = '/api/qvitter/allfollowing'
const PUBLIC _TIMELINE _URL = '/api/statuses/public_timeline.json'
const PUBLIC _AND _EXTERNAL _TIMELINE _URL = '/api/statuses/public_and_external_timeline.json'
const TAG _TIMELINE _URL = '/api/statusnet/tags/timeline'
const TAG _TIMELINE _URL = '/api/statusnet/tags/timeline'
const MENTIONS _URL = '/api/statuses/mentions.json'
const MENTIONS _URL = '/api/statuses/mentions.json'
const DM _TIMELINE _URL = '/api/statuses/dm_timeline.json'
const FOLLOWERS _URL = '/api/statuses/followers.json'
const FRIENDS _URL = '/api/statuses/friends.json'
const REGISTRATION _URL = '/api/account/register.json'
const REGISTRATION _URL = '/api/account/register.json'
const AVATAR _UPDATE _URL = '/api/qvitter/update_avatar.json'
const AVATAR _UPDATE _URL = '/api/qvitter/update_avatar.json'
const BG _UPDATE _URL = '/api/qvitter/update_background_image.json'
const BG _UPDATE _URL = '/api/qvitter/update_background_image.json'
@ -33,6 +27,11 @@ const MASTODON_UNRETWEET_URL = id => `/api/v1/statuses/${id}/unreblog`
const MASTODON _DELETE _URL = id => ` /api/v1/statuses/ ${ id } `
const MASTODON _DELETE _URL = id => ` /api/v1/statuses/ ${ id } `
const MASTODON _FOLLOW _URL = id => ` /api/v1/accounts/ ${ id } /follow `
const MASTODON _FOLLOW _URL = id => ` /api/v1/accounts/ ${ id } /follow `
const MASTODON _UNFOLLOW _URL = id => ` /api/v1/accounts/ ${ id } /unfollow `
const MASTODON _UNFOLLOW _URL = id => ` /api/v1/accounts/ ${ id } /unfollow `
const MASTODON _FOLLOWING _URL = id => ` /api/v1/accounts/ ${ id } /following `
const MASTODON _FOLLOWERS _URL = id => ` /api/v1/accounts/ ${ id } /followers `
const MASTODON _DIRECT _MESSAGES _TIMELINE _URL = '/api/v1/timelines/direct'
const MASTODON _PUBLIC _TIMELINE = '/api/v1/timelines/public'
const MASTODON _USER _HOME _TIMELINE _URL = '/api/v1/timelines/home'
const MASTODON _STATUS _URL = id => ` /api/v1/statuses/ ${ id } `
const MASTODON _STATUS _URL = id => ` /api/v1/statuses/ ${ id } `
const MASTODON _STATUS _CONTEXT _URL = id => ` /api/v1/statuses/ ${ id } /context `
const MASTODON _STATUS _CONTEXT _URL = id => ` /api/v1/statuses/ ${ id } /context `
const MASTODON _USER _URL = '/api/v1/accounts'
const MASTODON _USER _URL = '/api/v1/accounts'
@ -276,28 +275,36 @@ const fetchUserRelationship = ({id, credentials}) => {
} )
} )
}
}
const fetchFriends = ( { id , page , credentials } ) => {
const fetchFriends = ( { id , maxId , sinceId , limit = 20 , credentials } ) => {
let url = ` ${ FRIENDS _URL } ?user_id= ${ id } `
let url = MASTODON _FOLLOWING _URL ( id )
if ( page ) {
const args = [
url = url + ` &page= ${ page } `
maxId && ` max_id= ${ maxId } ` ,
}
sinceId && ` since_id= ${ sinceId } ` ,
limit && ` limit= ${ limit } `
] . filter ( _ => _ ) . join ( '&' )
url = url + ( args ? '?' + args : '' )
return fetch ( url , { headers : authHeaders ( credentials ) } )
return fetch ( url , { headers : authHeaders ( credentials ) } )
. then ( ( data ) => data . json ( ) )
. then ( ( data ) => data . json ( ) )
. then ( ( data ) => data . map ( parseUser ) )
. then ( ( data ) => data . map ( parseUser ) )
}
}
const exportFriends = ( { id , credentials } ) => {
const exportFriends = ( { id , credentials } ) => {
let url = ` ${ FRIENDS _URL } ?user_id= ${ id } & all=true`
let url = MASTODON _FOLLOWING _URL ( id ) + ` ? all=true`
return fetch ( url , { headers : authHeaders ( credentials ) } )
return fetch ( url , { headers : authHeaders ( credentials ) } )
. then ( ( data ) => data . json ( ) )
. then ( ( data ) => data . json ( ) )
. then ( ( data ) => data . map ( parseUser ) )
. then ( ( data ) => data . map ( parseUser ) )
}
}
const fetchFollowers = ( { id , page , credentials } ) => {
const fetchFollowers = ( { id , maxId , sinceId , limit = 20 , credentials } ) => {
let url = ` ${ FOLLOWERS _URL } ?user_id= ${ id } `
let url = MASTODON _FOLLOWERS _URL ( id )
if ( page ) {
const args = [
url = url + ` &page= ${ page } `
maxId && ` max_id= ${ maxId } ` ,
}
sinceId && ` since_id= ${ sinceId } ` ,
limit && ` limit= ${ limit } `
] . filter ( _ => _ ) . join ( '&' )
url += args ? '?' + args : ''
return fetch ( url , { headers : authHeaders ( credentials ) } )
return fetch ( url , { headers : authHeaders ( credentials ) } )
. then ( ( data ) => data . json ( ) )
. then ( ( data ) => data . json ( ) )
. then ( ( data ) => data . map ( parseUser ) )
. then ( ( data ) => data . map ( parseUser ) )
@ -347,12 +354,12 @@ const fetchStatus = ({id, credentials}) => {
const fetchTimeline = ( { timeline , credentials , since = false , until = false , userId = false , tag = false , withMuted = false } ) => {
const fetchTimeline = ( { timeline , credentials , since = false , until = false , userId = false , tag = false , withMuted = false } ) => {
const timelineUrls = {
const timelineUrls = {
public : PUBLIC_TIMELINE _URL ,
public : MASTODON_ PUBLIC_TIMELINE ,
friends : FRIENDS _TIMELINE _URL ,
friends : MASTODON_USER _HOME _TIMELINE _URL ,
mentions : MENTIONS _URL ,
mentions : MENTIONS _URL ,
dms : DM_TIMELINE _URL ,
dms : MASTO DON_DIRECT _ MESSAGES _TIMELINE _URL ,
notifications : QVITTER _USER _NOTIFICATIONS _URL ,
notifications : QVITTER _USER _NOTIFICATIONS _URL ,
'publicAndExternal' : PUBLIC_AND _EXTERNAL _TIMELINE _URL ,
'publicAndExternal' : MASTODON_PUBLIC _TIMELINE ,
user : MASTODON _USER _TIMELINE _URL ,
user : MASTODON _USER _TIMELINE _URL ,
media : MASTODON _USER _TIMELINE _URL ,
media : MASTODON _USER _TIMELINE _URL ,
favorites : MASTODON _USER _FAVORITES _TIMELINE _URL ,
favorites : MASTODON _USER _FAVORITES _TIMELINE _URL ,
@ -379,6 +386,12 @@ const fetchTimeline = ({timeline, credentials, since = false, until = false, use
if ( timeline === 'media' ) {
if ( timeline === 'media' ) {
params . push ( [ 'only_media' , 1 ] )
params . push ( [ 'only_media' , 1 ] )
}
}
if ( timeline === 'public' ) {
params . push ( [ 'local' , true ] )
}
if ( timeline === 'public' || timeline === 'publicAndExternal' ) {
params . push ( [ 'only_media' , false ] )
}
params . push ( [ 'count' , 20 ] )
params . push ( [ 'count' , 20 ] )
params . push ( [ 'with_muted' , withMuted ] )
params . push ( [ 'with_muted' , withMuted ] )