Skip to content
Snippets Groups Projects
Commit dcb9a5fa authored by lain's avatar lain
Browse files

Add friend list fetching.

parent aa4a9fb2
No related branches found
No related tags found
No related merge requests found
......@@ -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.
timelineFetcher.startFetching({store, credentials: userCredentials})
// Set our new backend interactor
commit('setBackendInteractor', backendInteractorService(userCredentials))
// Fetch our friends
store.rootState.api.backendInteractor.fetchFriends()
.then((friends) => commit('addNewUsers', friends))
})
// Start getting fresh tweets.
.then(() => timelineFetcher.startFetching({store, credentials: userCredentials}))
// Set our new backend interactor
.then(() => commit('setBackendInteractor', backendInteractorService(userCredentials)))
}
commit('endLogin')
})
......
......@@ -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,
......
......@@ -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
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment