Add friend list fetching.

This commit is contained in:
Roger Braun 2016-11-30 21:27:25 +01:00
parent aa4a9fb24f
commit dcb9a5fa17
3 changed files with 24 additions and 5 deletions

View file

@ -48,18 +48,25 @@ const users = {
loginUser (store, userCredentials) {
const commit = store.commit
commit('beginLogin')
return store.rootState.api.backendInteractor.verifyCredentials(userCredentials)
store.rootState.api.backendInteractor.verifyCredentials(userCredentials)
.then((response) => {
if (response.ok) {
response.json()
.then((user) => {
user.credentials = userCredentials
commit('setCurrentUser', user)
})
commit('addNewUsers', [user])
// Start getting fresh tweets.
.then(() => timelineFetcher.startFetching({store, credentials: userCredentials}))
timelineFetcher.startFetching({store, credentials: userCredentials})
// Set our new backend interactor
.then(() => commit('setBackendInteractor', backendInteractorService(userCredentials)))
commit('setBackendInteractor', backendInteractorService(userCredentials))
// Fetch our friends
store.rootState.api.backendInteractor.fetchFriends()
.then((friends) => commit('addNewUsers', friends))
})
}
commit('endLogin')
})

View file

@ -11,6 +11,7 @@ const STATUS_URL = '/api/statuses/show'
const MEDIA_UPLOAD_URL = '/api/statusnet/media/upload'
const CONVERSATION_URL = '/api/statusnet/conversation'
const MENTIONS_URL = '/api/statuses/mentions.json'
const FRIENDS_URL = '/api/statuses/friends.json'
const oldfetch = window.fetch
@ -28,6 +29,11 @@ const authHeaders = (user) => {
}
}
const fetchFriends = ({credentials}) => {
return fetch(FRIENDS_URL, { headers: authHeaders(credentials) })
.then((data) => data.json())
}
const fetchMentions = ({username, sinceId = 0, credentials}) => {
let url = `${MENTIONS_URL}?since_id=${sinceId}&screen_name=${username}`
return fetch(url, { headers: authHeaders(credentials) })
@ -128,6 +134,7 @@ const apiService = {
fetchConversation,
fetchStatus,
fetchMentions,
fetchFriends,
favorite,
unfavorite,
retweet,

View file

@ -13,10 +13,15 @@ const backendInteractorService = (credentials) => {
return apiService.fetchMentions({sinceId, username, credentials})
}
const fetchFriends = () => {
return apiService.fetchFriends({credentials})
}
const backendInteractorServiceInstance = {
fetchStatus,
fetchConversation,
fetchMentions,
fetchFriends,
verifyCredentials: apiService.verifyCredentials
}