1
0
Fork 0
forked from srxl/akkoma-fe

Remove posts by blocking or following

This commit is contained in:
jasper 2019-02-18 11:39:35 -08:00
parent 6c8ccf2733
commit 24d7f9917b
3 changed files with 80 additions and 21 deletions

View file

@ -1,4 +1,5 @@
import UserAvatar from '../user_avatar/user_avatar.vue' import UserAvatar from '../user_avatar/user_avatar.vue'
import apiService from '../../services/api/api.service.js'
import { hex2rgb } from '../../services/color_convert/color_convert.js' import { hex2rgb } from '../../services/color_convert/color_convert.js'
import { requestFollow, requestUnfollow } from '../../services/follow_manipulate/follow_manipulate' import { requestFollow, requestUnfollow } from '../../services/follow_manipulate/follow_manipulate'
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator' import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
@ -99,9 +100,24 @@ export default {
this.followRequestInProgress = false this.followRequestInProgress = false
this.followRequestSent = sent this.followRequestSent = sent
store.dispatch('stopFetching', 'friends') const rootState = store.rootState || store.state
store.commit('clearTimeline', { timeline: 'friends' }) const credentials = store.state.users.currentUser.credentials
store.dispatch('startFetching', { timeline: 'friends' }) const timelineData = rootState.statuses.timelines['friends']
apiService.fetchTimeline({
store,
credentials,
userId: this.user.id,
timeline: 'user',
between: true,
until: timelineData.maxId,
since: timelineData.minVisibleId
}).then((statuses) => {
store.dispatch('addNewStatuses', {
timeline: 'friends',
statuses,
showImmediately: true
})
}, () => store.dispatch('setError', { value: true }))
}) })
}, },
unfollowUser () { unfollowUser () {
@ -110,9 +126,7 @@ export default {
requestUnfollow(this.user, store).then(() => { requestUnfollow(this.user, store).then(() => {
this.followRequestInProgress = false this.followRequestInProgress = false
store.dispatch('stopFetching', 'friends') store.commit('removeStatus', { timeline: 'friends', userId: this.user.id })
store.commit('clearTimeline', { timeline: 'friends' })
store.dispatch('startFetching', { timeline: 'friends' })
}) })
}, },
blockUser () { blockUser () {
@ -121,12 +135,9 @@ export default {
.then((blockedUser) => { .then((blockedUser) => {
store.commit('addNewUsers', [blockedUser]) store.commit('addNewUsers', [blockedUser])
store.dispatch('stopFetching', 'friends') store.commit('removeStatus', { timeline: 'friends', userId: this.user.id })
store.commit('clearTimeline', { timeline: 'friends' }) store.commit('removeStatus', { timeline: 'public', userId: this.user.id })
store.dispatch('startFetching', { timeline: 'friends' }) store.commit('removeStatus', { timeline: 'publicAndExternal', userId: this.user.id })
store.commit('clearTimeline', { timeline: 'public' })
store.commit('clearTimeline', { timeline: 'publicAndExternal' })
}) })
}, },
unblockUser () { unblockUser () {
@ -135,12 +146,36 @@ export default {
.then((unblockedUser) => { .then((unblockedUser) => {
store.commit('addNewUsers', [unblockedUser]) store.commit('addNewUsers', [unblockedUser])
store.dispatch('stopFetching', 'friends') const rootState = store.rootState || store.state
store.commit('clearTimeline', { timeline: 'friends' }) const credentials = store.state.users.currentUser.credentials
store.dispatch('startFetching', { timeline: 'friends' }) const timelineData = rootState.statuses.timelines['friends']
apiService.fetchTimeline({
store.commit('clearTimeline', { timeline: 'public' }) store,
store.commit('clearTimeline', { timeline: 'publicAndExternal' }) credentials,
userId: this.user.id,
timeline: 'user',
between: true,
until: timelineData.maxId,
since: timelineData.minVisibleId
}).then((statuses) => {
store.dispatch('addNewStatuses', {
timeline: 'public',
statuses,
showImmediately: true
})
store.dispatch('addNewStatuses', {
timeline: 'publicAndExternal',
statuses,
showImmediately: true
})
if (this.user.follows_you) {
store.dispatch('addNewStatuses', {
timeline: 'friends',
statuses,
showImmediately: true
})
}
}, () => store.dispatch('setError', { value: true }))
}) })
}, },
toggleMute () { toggleMute () {

View file

@ -307,9 +307,32 @@ const addNewNotifications = (state, { dispatch, notifications, older, visibleNot
}) })
} }
const removeStatus = (state, { timeline, userId }) => {
const timelineObject = state.timelines[timeline]
if (userId) {
remove(timelineObject.statuses, { user: { id: userId } })
remove(timelineObject.visibleStatuses, { user: { id: userId } })
const statusesObject = timelineObject.statusesObject
const visibleStatusesObject = timelineObject.visibleStatusesObject
each(statusesObject, (status, key) => {
if (status.user.id === userId) {
delete statusesObject[key]
}
})
each(visibleStatusesObject, (status, key) => {
if (status.user.id === userId) {
delete visibleStatusesObject[key]
}
})
timelineObject.minVisibleId = (last(timeline.visibleStatuses) || {}).id
timelineObject.maxId = statuses.length > 0 ? maxBy(statuses, 'id').id : 0
}
}
export const mutations = { export const mutations = {
addNewStatuses, addNewStatuses,
addNewNotifications, addNewNotifications,
removeStatus,
showNewStatuses (state, { timeline }) { showNewStatuses (state, { timeline }) {
const oldTimeline = (state.timelines[timeline]) const oldTimeline = (state.timelines[timeline])

View file

@ -329,7 +329,7 @@ const setUserMute = ({id, credentials, muted = true}) => {
}) })
} }
const fetchTimeline = ({timeline, credentials, since = false, until = false, userId = false, tag = false}) => { const fetchTimeline = ({timeline, credentials, since = false, until = false, between = false, count = 20, userId = false, tag = false}) => {
const timelineUrls = { const timelineUrls = {
public: PUBLIC_TIMELINE_URL, public: PUBLIC_TIMELINE_URL,
friends: FRIENDS_TIMELINE_URL, friends: FRIENDS_TIMELINE_URL,
@ -362,8 +362,9 @@ const fetchTimeline = ({timeline, credentials, since = false, until = false, use
if (timeline === 'media') { if (timeline === 'media') {
params.push(['only_media', 1]) params.push(['only_media', 1])
} }
if (!between) {
params.push(['count', 20]) params.push(['count', count])
}
const queryString = map(params, (param) => `${param[0]}=${param[1]}`).join('&') const queryString = map(params, (param) => `${param[0]}=${param[1]}`).join('&')
url += `?${queryString}` url += `?${queryString}`