Grab mutes from server on patched servers.

This commit is contained in:
Roger Braun 2017-02-20 18:01:45 +01:00
parent 3fd0d0d1cb
commit 9c1093b6ca
4 changed files with 45 additions and 3 deletions

View File

@ -82,6 +82,7 @@
toggleMute () {
const store = this.$store
store.commit('setMuted', {user: this.user, muted: !this.user.muted})
store.state.api.backendInteractor.setUserMute(this.user)
}
}
}

View File

@ -82,6 +82,12 @@ const users = {
// Start getting fresh tweets.
store.dispatch('startFetching', 'friends')
// Get user mutes and follower info
store.rootState.api.backendInteractor.fetchMutes().then((mutedUsers) => {
each(mutedUsers, (user) => { user.muted = true })
store.commit('addNewUsers', mutedUsers)
})
// Fetch our friends
store.rootState.api.backendInteractor.fetchFriends()
.then((friends) => commit('addNewUsers', friends))

View File

@ -16,6 +16,7 @@ const MENTIONS_URL = '/api/statuses/mentions.json'
const FRIENDS_URL = '/api/statuses/friends.json'
const FOLLOWING_URL = '/api/friendships/create.json'
const UNFOLLOWING_URL = '/api/friendships/destroy.json'
const QVITTER_USER_PREF_URL = '/api/qvitter/set_profile_pref.json'
// const USER_URL = '/api/users/show.json'
const oldfetch = window.fetch
@ -58,7 +59,7 @@ const fetchFriends = ({credentials}) => {
const fetchAllFollowing = ({username, credentials}) => {
const url = `${ALL_FOLLOWING_URL}/${username}.json`
return fetch(url, { headers: authHeaders(credentials) })
.then((data) => data.json().users)
.then((data) => data.json())
}
const fetchMentions = ({username, sinceId = 0, credentials}) => {
@ -79,6 +80,22 @@ const fetchStatus = ({id, credentials}) => {
.then((data) => data.json())
}
const setUserMute = ({id, credentials, muted = true}) => {
const form = new FormData()
const muteInteger = muted ? 1 : 0
form.append('namespace', 'qvitter')
form.append('data', muteInteger)
form.append('topic', `mute:${id}`)
return fetch(QVITTER_USER_PREF_URL, {
method: 'POST',
headers: authHeaders(credentials),
body: form
})
}
const fetchTimeline = ({timeline, credentials, since = false, until = false}) => {
const timelineUrls = {
public: PUBLIC_TIMELINE_URL,
@ -162,6 +179,14 @@ const uploadMedia = ({formData, credentials}) => {
.then((text) => (new DOMParser()).parseFromString(text, 'application/xml'))
}
const fetchMutes = ({credentials}) => {
const url = '/api/qvitter/mutes.json'
return fetch(url, {
headers: authHeaders(credentials)
}).then((data) => data.json())
}
const apiService = {
verifyCredentials,
fetchTimeline,
@ -177,7 +202,9 @@ const apiService = {
postStatus,
deleteStatus,
uploadMedia,
fetchAllFollowing
fetchAllFollowing,
setUserMute,
fetchMutes
}
export default apiService

View File

@ -34,6 +34,12 @@ const backendInteractorService = (credentials) => {
return timelineFetcherService.startFetching({timeline, store, credentials})
}
const setUserMute = ({id, muted = true}) => {
return apiService.setUserMute({id, muted, credentials})
}
const fetchMutes = () => apiService.fetchMutes({credentials})
const backendInteractorServiceInstance = {
fetchStatus,
fetchConversation,
@ -43,7 +49,9 @@ const backendInteractorService = (credentials) => {
unfollowUser,
fetchAllFollowing,
verifyCredentials: apiService.verifyCredentials,
startFetching
startFetching,
setUserMute,
fetchMutes
}
return backendInteractorServiceInstance