Merge branch 'develop' into brendenbice1222/pleroma-fe-issues/pleroma-fe-202-show-boosted-users
This commit is contained in:
commit
d417945427
41 changed files with 767 additions and 275 deletions
|
@ -1,5 +1,5 @@
|
|||
import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js'
|
||||
import { compact, map, each, merge, find, last } from 'lodash'
|
||||
import { compact, map, each, merge, last, concat, uniq } from 'lodash'
|
||||
import { set } from 'vue'
|
||||
import { registerPushNotifications, unregisterPushNotifications } from '../services/push/push.js'
|
||||
import oauthApi from '../services/new_api/oauth'
|
||||
|
@ -32,6 +32,35 @@ const getNotificationPermission = () => {
|
|||
return Promise.resolve(Notification.permission)
|
||||
}
|
||||
|
||||
const blockUser = (store, id) => {
|
||||
return store.rootState.api.backendInteractor.blockUser(id)
|
||||
.then((relationship) => {
|
||||
store.commit('updateUserRelationship', [relationship])
|
||||
store.commit('addBlockId', id)
|
||||
store.commit('removeStatus', { timeline: 'friends', userId: id })
|
||||
store.commit('removeStatus', { timeline: 'public', userId: id })
|
||||
store.commit('removeStatus', { timeline: 'publicAndExternal', userId: id })
|
||||
})
|
||||
}
|
||||
|
||||
const unblockUser = (store, id) => {
|
||||
return store.rootState.api.backendInteractor.unblockUser(id)
|
||||
.then((relationship) => store.commit('updateUserRelationship', [relationship]))
|
||||
}
|
||||
|
||||
const muteUser = (store, id) => {
|
||||
return store.rootState.api.backendInteractor.muteUser(id)
|
||||
.then((relationship) => {
|
||||
store.commit('updateUserRelationship', [relationship])
|
||||
store.commit('addMuteId', id)
|
||||
})
|
||||
}
|
||||
|
||||
const unmuteUser = (store, id) => {
|
||||
return store.rootState.api.backendInteractor.unmuteUser(id)
|
||||
.then((relationship) => store.commit('updateUserRelationship', [relationship]))
|
||||
}
|
||||
|
||||
export const mutations = {
|
||||
setMuted (state, { user: { id }, muted }) {
|
||||
const user = state.usersObject[id]
|
||||
|
@ -73,42 +102,27 @@ export const mutations = {
|
|||
endLogin (state) {
|
||||
state.loggingIn = false
|
||||
},
|
||||
// TODO Clean after ourselves?
|
||||
addFriends (state, { id, friends }) {
|
||||
saveFriendIds (state, { id, friendIds }) {
|
||||
const user = state.usersObject[id]
|
||||
each(friends, friend => {
|
||||
if (!find(user.friends, { id: friend.id })) {
|
||||
user.friends.push(friend)
|
||||
}
|
||||
})
|
||||
user.lastFriendId = last(friends).id
|
||||
user.friendIds = uniq(concat(user.friendIds, friendIds))
|
||||
},
|
||||
addFollowers (state, { id, followers }) {
|
||||
saveFollowerIds (state, { id, followerIds }) {
|
||||
const user = state.usersObject[id]
|
||||
each(followers, follower => {
|
||||
if (!find(user.followers, { id: follower.id })) {
|
||||
user.followers.push(follower)
|
||||
}
|
||||
})
|
||||
user.lastFollowerId = last(followers).id
|
||||
user.followerIds = uniq(concat(user.followerIds, followerIds))
|
||||
},
|
||||
// Because frontend doesn't have a reason to keep these stuff in memory
|
||||
// outside of viewing someones user profile.
|
||||
clearFriends (state, userId) {
|
||||
const user = state.usersObject[userId]
|
||||
if (!user) {
|
||||
return
|
||||
if (user) {
|
||||
set(user, 'friendIds', [])
|
||||
}
|
||||
user.friends = []
|
||||
user.lastFriendId = null
|
||||
},
|
||||
clearFollowers (state, userId) {
|
||||
const user = state.usersObject[userId]
|
||||
if (!user) {
|
||||
return
|
||||
if (user) {
|
||||
set(user, 'followerIds', [])
|
||||
}
|
||||
user.followers = []
|
||||
user.lastFollowerId = null
|
||||
},
|
||||
addNewUsers (state, users) {
|
||||
each(users, (user) => mergeOrAdd(state.users, state.usersObject, user))
|
||||
|
@ -132,6 +146,11 @@ export const mutations = {
|
|||
saveBlockIds (state, blockIds) {
|
||||
state.currentUser.blockIds = blockIds
|
||||
},
|
||||
addBlockId (state, blockId) {
|
||||
if (state.currentUser.blockIds.indexOf(blockId) === -1) {
|
||||
state.currentUser.blockIds.push(blockId)
|
||||
}
|
||||
},
|
||||
updateMutes (state, mutedUsers) {
|
||||
// Reset muted of all fetched users
|
||||
each(state.users, (user) => { user.muted = false })
|
||||
|
@ -140,6 +159,11 @@ export const mutations = {
|
|||
saveMuteIds (state, muteIds) {
|
||||
state.currentUser.muteIds = muteIds
|
||||
},
|
||||
addMuteId (state, muteId) {
|
||||
if (state.currentUser.muteIds.indexOf(muteId) === -1) {
|
||||
state.currentUser.muteIds.push(muteId)
|
||||
}
|
||||
},
|
||||
setUserForStatus (state, status) {
|
||||
status.user = state.usersObject[status.user.id]
|
||||
},
|
||||
|
@ -200,8 +224,10 @@ const users = {
|
|||
})
|
||||
},
|
||||
fetchUserRelationship (store, id) {
|
||||
return store.rootState.api.backendInteractor.fetchUserRelationship({ id })
|
||||
.then((relationships) => store.commit('updateUserRelationship', relationships))
|
||||
if (store.state.currentUser) {
|
||||
store.rootState.api.backendInteractor.fetchUserRelationship({ id })
|
||||
.then((relationships) => store.commit('updateUserRelationship', relationships))
|
||||
}
|
||||
},
|
||||
fetchBlocks (store) {
|
||||
return store.rootState.api.backendInteractor.fetchBlocks()
|
||||
|
@ -211,18 +237,17 @@ const users = {
|
|||
return blocks
|
||||
})
|
||||
},
|
||||
blockUser (store, userId) {
|
||||
return store.rootState.api.backendInteractor.blockUser(userId)
|
||||
.then((relationship) => {
|
||||
store.commit('updateUserRelationship', [relationship])
|
||||
store.commit('removeStatus', { timeline: 'friends', userId })
|
||||
store.commit('removeStatus', { timeline: 'public', userId })
|
||||
store.commit('removeStatus', { timeline: 'publicAndExternal', userId })
|
||||
})
|
||||
blockUser (store, id) {
|
||||
return blockUser(store, id)
|
||||
},
|
||||
unblockUser (store, id) {
|
||||
return store.rootState.api.backendInteractor.unblockUser(id)
|
||||
.then((relationship) => store.commit('updateUserRelationship', [relationship]))
|
||||
return unblockUser(store, id)
|
||||
},
|
||||
blockUsers (store, ids = []) {
|
||||
return Promise.all(ids.map(id => blockUser(store, id)))
|
||||
},
|
||||
unblockUsers (store, ids = []) {
|
||||
return Promise.all(ids.map(id => unblockUser(store, id)))
|
||||
},
|
||||
fetchMutes (store) {
|
||||
return store.rootState.api.backendInteractor.fetchMutes()
|
||||
|
@ -233,32 +258,34 @@ const users = {
|
|||
})
|
||||
},
|
||||
muteUser (store, id) {
|
||||
return store.rootState.api.backendInteractor.muteUser(id)
|
||||
.then((relationship) => store.commit('updateUserRelationship', [relationship]))
|
||||
return muteUser(store, id)
|
||||
},
|
||||
unmuteUser (store, id) {
|
||||
return store.rootState.api.backendInteractor.unmuteUser(id)
|
||||
.then((relationship) => store.commit('updateUserRelationship', [relationship]))
|
||||
return unmuteUser(store, id)
|
||||
},
|
||||
addFriends ({ rootState, commit }, fetchBy) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const user = rootState.users.usersObject[fetchBy]
|
||||
const maxId = user.lastFriendId
|
||||
rootState.api.backendInteractor.fetchFriends({ id: user.id, maxId })
|
||||
.then((friends) => {
|
||||
commit('addFriends', { id: user.id, friends })
|
||||
resolve(friends)
|
||||
}).catch(() => {
|
||||
reject()
|
||||
})
|
||||
})
|
||||
muteUsers (store, ids = []) {
|
||||
return Promise.all(ids.map(id => muteUser(store, id)))
|
||||
},
|
||||
addFollowers ({ rootState, commit }, fetchBy) {
|
||||
const user = rootState.users.usersObject[fetchBy]
|
||||
const maxId = user.lastFollowerId
|
||||
return rootState.api.backendInteractor.fetchFollowers({ id: user.id, maxId })
|
||||
unmuteUsers (store, ids = []) {
|
||||
return Promise.all(ids.map(id => unmuteUser(store, id)))
|
||||
},
|
||||
fetchFriends ({ rootState, commit }, id) {
|
||||
const user = rootState.users.usersObject[id]
|
||||
const maxId = last(user.friendIds)
|
||||
return rootState.api.backendInteractor.fetchFriends({ id, maxId })
|
||||
.then((friends) => {
|
||||
commit('addNewUsers', friends)
|
||||
commit('saveFriendIds', { id, friendIds: map(friends, 'id') })
|
||||
return friends
|
||||
})
|
||||
},
|
||||
fetchFollowers ({ rootState, commit }, id) {
|
||||
const user = rootState.users.usersObject[id]
|
||||
const maxId = last(user.followerIds)
|
||||
return rootState.api.backendInteractor.fetchFollowers({ id, maxId })
|
||||
.then((followers) => {
|
||||
commit('addFollowers', { id: user.id, followers })
|
||||
commit('addNewUsers', followers)
|
||||
commit('saveFollowerIds', { id, followerIds: map(followers, 'id') })
|
||||
return followers
|
||||
})
|
||||
},
|
||||
|
@ -281,6 +308,9 @@ const users = {
|
|||
|
||||
unregisterPushNotifications(token)
|
||||
},
|
||||
addNewUsers ({ commit }, users) {
|
||||
commit('addNewUsers', users)
|
||||
},
|
||||
addNewStatuses (store, { statuses }) {
|
||||
const users = map(statuses, 'user')
|
||||
const retweetedUsers = compact(map(statuses, 'retweeted_status.user'))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue