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>
<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="stat-count" v-if="statusFromGlobalRepository.rebloggedBy && statusFromGlobalRepository.rebloggedBy.length > 0">
<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 apiService from '../services/api/api.service.js'
// import parse from '../services/status_parser/status_parser.js'
@ -402,12 +402,27 @@ export const mutations = {
},
setFavorited (state, { status, value }) {
const newStatus = state.allStatusesObject[status.id]
if (newStatus.favorited !== value) {
if (value) {
newStatus.fave_num++
} else {
newStatus.fave_num--
}
}
newStatus.favorited = value
},
setFavoritedConfirm (state, { status }) {
setFavoritedConfirm (state, { status, user }) {
const newStatus = state.allStatusesObject[status.id]
newStatus.favorited = status.favorited
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 }) {
const newStatus = state.allStatusesObject[status.id]
@ -422,6 +437,17 @@ export const mutations = {
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 }) {
const newStatus = state.allStatusesObject[status.id]
newStatus.deleted = true
@ -461,11 +487,9 @@ export const mutations = {
state.timelines[timeline].flushMarker = id
},
addFavsAndRepeats (state, { id, favoritedByUsers, rebloggedByUsers }) {
state.allStatusesObject[id] = {
...state.allStatusesObject[id],
favoritedBy: favoritedByUsers,
rebloggedBy: rebloggedByUsers
}
const newStatus = state.allStatusesObject[id]
newStatus.favoritedBy = favoritedByUsers.filter(_ => _)
newStatus.rebloggedBy = rebloggedByUsers.filter(_ => _)
}
}
@ -500,27 +524,26 @@ const statuses = {
favorite ({ rootState, commit }, status) {
// Optimistic favoriting...
commit('setFavorited', { status, value: true })
apiService.favorite({ id: status.id, credentials: rootState.users.currentUser.credentials })
.then(status => {
commit('setFavoritedConfirm', { status })
})
rootState.api.backendInteractor.favorite(status.id)
.then(status => commit('setFavoritedConfirm', { status, user: rootState.users.currentUser }))
},
unfavorite ({ rootState, commit }, status) {
// Optimistic favoriting...
// Optimistic unfavoriting...
commit('setFavorited', { status, value: false })
apiService.unfavorite({ id: status.id, credentials: rootState.users.currentUser.credentials })
.then(status => {
commit('setFavoritedConfirm', { status })
})
rootState.api.backendInteractor.unfavorite(status.id)
.then(status => commit('setFavoritedConfirm', { status, user: rootState.users.currentUser }))
},
retweet ({ rootState, commit }, status) {
// Optimistic retweeting...
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) {
// Optimistic unretweeting...
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 }) {
commit('queueFlush', { timeline, id })
@ -537,14 +560,7 @@ const statuses = {
rootState.api.backendInteractor.fetchFavoritedByUsers(id),
rootState.api.backendInteractor.fetchRebloggedByUsers(id)
]).then(([favoritedByUsers, rebloggedByUsers]) =>
commit(
'addFavsAndRepeats',
{
id,
favoritedByUsers: favoritedByUsers.filter(_ => _),
rebloggedByUsers: rebloggedByUsers.filter(_ => _)
}
)
commit('addFavsAndRepeats', { id, favoritedByUsers, rebloggedByUsers })
)
}
},

View file

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

View file

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