Merge branch '527' into 'develop'

Fix "Liking/reprööting posts while post is highlighted in conversation fails to update the liked/reprööted status"

Closes #527

See merge request pleroma/pleroma-fe!787
This commit is contained in:
HJ 2019-05-09 17:17:26 +00:00
commit cd67b1f496
4 changed files with 57 additions and 72 deletions

View file

@ -139,7 +139,7 @@
</div> </div>
<transition name="fade"> <transition name="fade">
<div class="favs-repeated-users" v-if="combinedFavsAndRepeatsUsers.length > 0 && isFocused"> <div class="favs-repeated-users" v-if="isFocused && combinedFavsAndRepeatsUsers.length > 0">
<div class="stats"> <div class="stats">
<div class="stat-count" v-if="statusFromGlobalRepository.rebloggedBy && statusFromGlobalRepository.rebloggedBy.length > 0"> <div class="stat-count" v-if="statusFromGlobalRepository.rebloggedBy && statusFromGlobalRepository.rebloggedBy.length > 0">
<a class="stat-title">{{ $t('status.repeats') }}</a> <a class="stat-title">{{ $t('status.repeats') }}</a>

View file

@ -1,4 +1,4 @@
import { remove, slice, each, find, maxBy, minBy, merge, first, last, isArray, omitBy } from 'lodash' import { remove, slice, each, findIndex, find, maxBy, minBy, merge, first, last, isArray, omitBy } from 'lodash'
import { set } from 'vue' import { set } from 'vue'
import apiService from '../services/api/api.service.js' import apiService from '../services/api/api.service.js'
// import parse from '../services/status_parser/status_parser.js' // import parse from '../services/status_parser/status_parser.js'
@ -402,12 +402,27 @@ export const mutations = {
}, },
setFavorited (state, { status, value }) { setFavorited (state, { status, value }) {
const newStatus = state.allStatusesObject[status.id] const newStatus = state.allStatusesObject[status.id]
if (newStatus.favorited !== value) {
if (value) {
newStatus.fave_num++
} else {
newStatus.fave_num--
}
}
newStatus.favorited = value newStatus.favorited = value
}, },
setFavoritedConfirm (state, { status }) { setFavoritedConfirm (state, { status, user }) {
const newStatus = state.allStatusesObject[status.id] const newStatus = state.allStatusesObject[status.id]
newStatus.favorited = status.favorited newStatus.favorited = status.favorited
newStatus.fave_num = status.fave_num newStatus.fave_num = status.fave_num
const index = findIndex(newStatus.favoritedBy, { id: user.id })
if (index !== -1 && !newStatus.favorited) {
newStatus.favoritedBy.splice(index, 1)
} else if (index === -1 && newStatus.favorited) {
newStatus.favoritedBy.push(user)
}
}, },
setRetweeted (state, { status, value }) { setRetweeted (state, { status, value }) {
const newStatus = state.allStatusesObject[status.id] const newStatus = state.allStatusesObject[status.id]
@ -422,6 +437,17 @@ export const mutations = {
newStatus.repeated = value newStatus.repeated = value
}, },
setRetweetedConfirm (state, { status, user }) {
const newStatus = state.allStatusesObject[status.id]
newStatus.repeated = status.repeated
newStatus.repeat_num = status.repeat_num
const index = findIndex(newStatus.rebloggedBy, { id: user.id })
if (index !== -1 && !newStatus.repeated) {
newStatus.rebloggedBy.splice(index, 1)
} else if (index === -1 && newStatus.repeated) {
newStatus.rebloggedBy.push(user)
}
},
setDeleted (state, { status }) { setDeleted (state, { status }) {
const newStatus = state.allStatusesObject[status.id] const newStatus = state.allStatusesObject[status.id]
newStatus.deleted = true newStatus.deleted = true
@ -461,11 +487,9 @@ export const mutations = {
state.timelines[timeline].flushMarker = id state.timelines[timeline].flushMarker = id
}, },
addFavsAndRepeats (state, { id, favoritedByUsers, rebloggedByUsers }) { addFavsAndRepeats (state, { id, favoritedByUsers, rebloggedByUsers }) {
state.allStatusesObject[id] = { const newStatus = state.allStatusesObject[id]
...state.allStatusesObject[id], newStatus.favoritedBy = favoritedByUsers.filter(_ => _)
favoritedBy: favoritedByUsers, newStatus.rebloggedBy = rebloggedByUsers.filter(_ => _)
rebloggedBy: rebloggedByUsers
}
} }
} }
@ -500,27 +524,26 @@ const statuses = {
favorite ({ rootState, commit }, status) { favorite ({ rootState, commit }, status) {
// Optimistic favoriting... // Optimistic favoriting...
commit('setFavorited', { status, value: true }) commit('setFavorited', { status, value: true })
apiService.favorite({ id: status.id, credentials: rootState.users.currentUser.credentials }) rootState.api.backendInteractor.favorite(status.id)
.then(status => { .then(status => commit('setFavoritedConfirm', { status, user: rootState.users.currentUser }))
commit('setFavoritedConfirm', { status })
})
}, },
unfavorite ({ rootState, commit }, status) { unfavorite ({ rootState, commit }, status) {
// Optimistic favoriting... // Optimistic unfavoriting...
commit('setFavorited', { status, value: false }) commit('setFavorited', { status, value: false })
apiService.unfavorite({ id: status.id, credentials: rootState.users.currentUser.credentials }) rootState.api.backendInteractor.unfavorite(status.id)
.then(status => { .then(status => commit('setFavoritedConfirm', { status, user: rootState.users.currentUser }))
commit('setFavoritedConfirm', { status })
})
}, },
retweet ({ rootState, commit }, status) { retweet ({ rootState, commit }, status) {
// Optimistic retweeting... // Optimistic retweeting...
commit('setRetweeted', { status, value: true }) commit('setRetweeted', { status, value: true })
apiService.retweet({ id: status.id, credentials: rootState.users.currentUser.credentials }) rootState.api.backendInteractor.retweet(status.id)
.then(status => commit('setRetweetedConfirm', { status: status.retweeted_status, user: rootState.users.currentUser }))
}, },
unretweet ({ rootState, commit }, status) { unretweet ({ rootState, commit }, status) {
// Optimistic unretweeting...
commit('setRetweeted', { status, value: false }) commit('setRetweeted', { status, value: false })
apiService.unretweet({ id: status.id, credentials: rootState.users.currentUser.credentials }) rootState.api.backendInteractor.unretweet(status.id)
.then(status => commit('setRetweetedConfirm', { status, user: rootState.users.currentUser }))
}, },
queueFlush ({ rootState, commit }, { timeline, id }) { queueFlush ({ rootState, commit }, { timeline, id }) {
commit('queueFlush', { timeline, id }) commit('queueFlush', { timeline, id })
@ -537,14 +560,7 @@ const statuses = {
rootState.api.backendInteractor.fetchFavoritedByUsers(id), rootState.api.backendInteractor.fetchFavoritedByUsers(id),
rootState.api.backendInteractor.fetchRebloggedByUsers(id) rootState.api.backendInteractor.fetchRebloggedByUsers(id)
]).then(([favoritedByUsers, rebloggedByUsers]) => ]).then(([favoritedByUsers, rebloggedByUsers]) =>
commit( commit('addFavsAndRepeats', { id, favoritedByUsers, rebloggedByUsers })
'addFavsAndRepeats',
{
id,
favoritedByUsers: favoritedByUsers.filter(_ => _),
rebloggedByUsers: rebloggedByUsers.filter(_ => _)
}
)
) )
} }
}, },

View file

@ -506,62 +506,22 @@ const verifyCredentials = (user) => {
} }
const favorite = ({ id, credentials }) => { const favorite = ({ id, credentials }) => {
return fetch(MASTODON_FAVORITE_URL(id), { return promisedRequest({ url: MASTODON_FAVORITE_URL(id), method: 'POST', credentials })
headers: authHeaders(credentials),
method: 'POST'
})
.then(response => {
if (response.ok) {
return response.json()
} else {
throw new Error('Error favoriting post')
}
})
.then((data) => parseStatus(data)) .then((data) => parseStatus(data))
} }
const unfavorite = ({ id, credentials }) => { const unfavorite = ({ id, credentials }) => {
return fetch(MASTODON_UNFAVORITE_URL(id), { return promisedRequest({ url: MASTODON_UNFAVORITE_URL(id), method: 'POST', credentials })
headers: authHeaders(credentials),
method: 'POST'
})
.then(response => {
if (response.ok) {
return response.json()
} else {
throw new Error('Error removing favorite')
}
})
.then((data) => parseStatus(data)) .then((data) => parseStatus(data))
} }
const retweet = ({ id, credentials }) => { const retweet = ({ id, credentials }) => {
return fetch(MASTODON_RETWEET_URL(id), { return promisedRequest({ url: MASTODON_RETWEET_URL(id), method: 'POST', credentials })
headers: authHeaders(credentials),
method: 'POST'
})
.then(response => {
if (response.ok) {
return response.json()
} else {
throw new Error('Error repeating post')
}
})
.then((data) => parseStatus(data)) .then((data) => parseStatus(data))
} }
const unretweet = ({ id, credentials }) => { const unretweet = ({ id, credentials }) => {
return fetch(MASTODON_UNRETWEET_URL(id), { return promisedRequest({ url: MASTODON_UNRETWEET_URL(id), method: 'POST', credentials })
headers: authHeaders(credentials),
method: 'POST'
})
.then(response => {
if (response.ok) {
return response.json()
} else {
throw new Error('Error removing repeat')
}
})
.then((data) => parseStatus(data)) .then((data) => parseStatus(data))
} }

View file

@ -117,6 +117,11 @@ const backendInteractorService = (credentials) => {
const fetchRebloggedByUsers = (id) => apiService.fetchRebloggedByUsers({id}) const fetchRebloggedByUsers = (id) => apiService.fetchRebloggedByUsers({id})
const reportUser = (params) => apiService.reportUser({credentials, ...params}) const reportUser = (params) => apiService.reportUser({credentials, ...params})
const favorite = (id) => apiService.favorite({id, credentials})
const unfavorite = (id) => apiService.unfavorite({id, credentials})
const retweet = (id) => apiService.retweet({id, credentials})
const unretweet = (id) => apiService.unretweet({id, credentials})
const backendInteractorServiceInstance = { const backendInteractorServiceInstance = {
fetchStatus, fetchStatus,
fetchConversation, fetchConversation,
@ -161,7 +166,11 @@ const backendInteractorService = (credentials) => {
denyUser, denyUser,
fetchFavoritedByUsers, fetchFavoritedByUsers,
fetchRebloggedByUsers, fetchRebloggedByUsers,
reportUser reportUser,
favorite,
unfavorite,
retweet,
unretweet
} }
return backendInteractorServiceInstance return backendInteractorServiceInstance