diff --git a/src/modules/users.js b/src/modules/users.js index 46a2e087d8..fd2d6e81cf 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -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') }) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 0dea2d4697..47895d3b37 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -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, diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index eff085ae3c..36a1ff3bfd 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -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 }