forked from AkkomaGang/akkoma-fe
Add friend list fetching.
This commit is contained in:
parent
aa4a9fb24f
commit
dcb9a5fa17
3 changed files with 24 additions and 5 deletions
|
@ -48,18 +48,25 @@ const users = {
|
||||||
loginUser (store, userCredentials) {
|
loginUser (store, userCredentials) {
|
||||||
const commit = store.commit
|
const commit = store.commit
|
||||||
commit('beginLogin')
|
commit('beginLogin')
|
||||||
return store.rootState.api.backendInteractor.verifyCredentials(userCredentials)
|
store.rootState.api.backendInteractor.verifyCredentials(userCredentials)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
response.json()
|
response.json()
|
||||||
.then((user) => {
|
.then((user) => {
|
||||||
user.credentials = userCredentials
|
user.credentials = userCredentials
|
||||||
commit('setCurrentUser', user)
|
commit('setCurrentUser', user)
|
||||||
})
|
commit('addNewUsers', [user])
|
||||||
|
|
||||||
// Start getting fresh tweets.
|
// Start getting fresh tweets.
|
||||||
.then(() => timelineFetcher.startFetching({store, credentials: userCredentials}))
|
timelineFetcher.startFetching({store, credentials: userCredentials})
|
||||||
|
|
||||||
// Set our new backend interactor
|
// 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')
|
commit('endLogin')
|
||||||
})
|
})
|
||||||
|
|
|
@ -11,6 +11,7 @@ const STATUS_URL = '/api/statuses/show'
|
||||||
const MEDIA_UPLOAD_URL = '/api/statusnet/media/upload'
|
const MEDIA_UPLOAD_URL = '/api/statusnet/media/upload'
|
||||||
const CONVERSATION_URL = '/api/statusnet/conversation'
|
const CONVERSATION_URL = '/api/statusnet/conversation'
|
||||||
const MENTIONS_URL = '/api/statuses/mentions.json'
|
const MENTIONS_URL = '/api/statuses/mentions.json'
|
||||||
|
const FRIENDS_URL = '/api/statuses/friends.json'
|
||||||
|
|
||||||
const oldfetch = window.fetch
|
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}) => {
|
const fetchMentions = ({username, sinceId = 0, credentials}) => {
|
||||||
let url = `${MENTIONS_URL}?since_id=${sinceId}&screen_name=${username}`
|
let url = `${MENTIONS_URL}?since_id=${sinceId}&screen_name=${username}`
|
||||||
return fetch(url, { headers: authHeaders(credentials) })
|
return fetch(url, { headers: authHeaders(credentials) })
|
||||||
|
@ -128,6 +134,7 @@ const apiService = {
|
||||||
fetchConversation,
|
fetchConversation,
|
||||||
fetchStatus,
|
fetchStatus,
|
||||||
fetchMentions,
|
fetchMentions,
|
||||||
|
fetchFriends,
|
||||||
favorite,
|
favorite,
|
||||||
unfavorite,
|
unfavorite,
|
||||||
retweet,
|
retweet,
|
||||||
|
|
|
@ -13,10 +13,15 @@ const backendInteractorService = (credentials) => {
|
||||||
return apiService.fetchMentions({sinceId, username, credentials})
|
return apiService.fetchMentions({sinceId, username, credentials})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fetchFriends = () => {
|
||||||
|
return apiService.fetchFriends({credentials})
|
||||||
|
}
|
||||||
|
|
||||||
const backendInteractorServiceInstance = {
|
const backendInteractorServiceInstance = {
|
||||||
fetchStatus,
|
fetchStatus,
|
||||||
fetchConversation,
|
fetchConversation,
|
||||||
fetchMentions,
|
fetchMentions,
|
||||||
|
fetchFriends,
|
||||||
verifyCredentials: apiService.verifyCredentials
|
verifyCredentials: apiService.verifyCredentials
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue