aboutsummaryrefslogtreecommitdiff
path: root/src/modules/users.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/users.js')
-rw-r--r--src/modules/users.js86
1 files changed, 61 insertions, 25 deletions
diff --git a/src/modules/users.js b/src/modules/users.js
index 053e44b6..50b4cb84 100644
--- a/src/modules/users.js
+++ b/src/modules/users.js
@@ -61,13 +61,16 @@ const editUserNote = (store, { id, comment }) => {
.then((relationship) => store.commit('updateUserRelationship', [relationship]))
}
-const muteUser = (store, id) => {
+const muteUser = (store, args) => {
+ const id = typeof args === 'object' ? args.id : args
+ const expiresIn = typeof args === 'object' ? args.expiresIn : 0
+
const predictedRelationship = store.state.relationships[id] || { id }
predictedRelationship.muting = true
store.commit('updateUserRelationship', [predictedRelationship])
store.commit('addMuteId', id)
- return store.rootState.api.backendInteractor.muteUser({ id })
+ return store.rootState.api.backendInteractor.muteUser({ id, expiresIn })
.then((relationship) => {
store.commit('updateUserRelationship', [relationship])
store.commit('addMuteId', id)
@@ -192,9 +195,15 @@ export const mutations = {
state.currentUser.blockIds.push(blockId)
}
},
+ setBlockIdsMaxId (state, blockIdsMaxId) {
+ state.currentUser.blockIdsMaxId = blockIdsMaxId
+ },
saveMuteIds (state, muteIds) {
state.currentUser.muteIds = muteIds
},
+ setMuteIdsMaxId (state, muteIdsMaxId) {
+ state.currentUser.muteIdsMaxId = muteIdsMaxId
+ },
addMuteId (state, muteId) {
if (state.currentUser.muteIds.indexOf(muteId) === -1) {
state.currentUser.muteIds.push(muteId)
@@ -317,10 +326,20 @@ const users = {
.then((inLists) => store.commit('updateUserInLists', { id, inLists }))
}
},
- fetchBlocks (store) {
- return store.rootState.api.backendInteractor.fetchBlocks()
+ fetchBlocks (store, args) {
+ const { reset } = args || {}
+
+ const maxId = store.state.currentUser.blockIdsMaxId
+ return store.rootState.api.backendInteractor.fetchBlocks({ maxId })
.then((blocks) => {
- store.commit('saveBlockIds', map(blocks, 'id'))
+ if (reset) {
+ store.commit('saveBlockIds', map(blocks, 'id'))
+ } else {
+ map(blocks, 'id').map(id => store.commit('addBlockId', id))
+ }
+ if (blocks.length) {
+ store.commit('setBlockIdsMaxId', last(blocks).id)
+ }
store.commit('addNewUsers', blocks)
return blocks
})
@@ -343,10 +362,20 @@ const users = {
editUserNote (store, args) {
return editUserNote(store, args)
},
- fetchMutes (store) {
- return store.rootState.api.backendInteractor.fetchMutes()
+ fetchMutes (store, args) {
+ const { reset } = args || {}
+
+ const maxId = store.state.currentUser.muteIdsMaxId
+ return store.rootState.api.backendInteractor.fetchMutes({ maxId })
.then((mutes) => {
- store.commit('saveMuteIds', map(mutes, 'id'))
+ if (reset) {
+ store.commit('saveMuteIds', map(mutes, 'id'))
+ } else {
+ map(mutes, 'id').map(id => store.commit('addMuteId', id))
+ }
+ if (mutes.length) {
+ store.commit('setMuteIdsMaxId', last(mutes).id)
+ }
store.commit('addNewUsers', mutes)
return mutes
})
@@ -548,6 +577,7 @@ const users = {
loginUser (store, accessToken) {
return new Promise((resolve, reject) => {
const commit = store.commit
+ const dispatch = store.dispatch
commit('beginLogin')
store.rootState.api.backendInteractor.verifyCredentials(accessToken)
.then((data) => {
@@ -562,57 +592,57 @@ const users = {
commit('setServerSideStorage', user)
commit('addNewUsers', [user])
- store.dispatch('fetchEmoji')
+ dispatch('fetchEmoji')
getNotificationPermission()
.then(permission => commit('setNotificationPermission', permission))
// Set our new backend interactor
commit('setBackendInteractor', backendInteractorService(accessToken))
- store.dispatch('pushServerSideStorage')
+ dispatch('pushServerSideStorage')
if (user.token) {
- store.dispatch('setWsToken', user.token)
+ dispatch('setWsToken', user.token)
// Initialize the shout socket.
- store.dispatch('initializeSocket')
+ dispatch('initializeSocket')
}
const startPolling = () => {
// Start getting fresh posts.
- store.dispatch('startFetchingTimeline', { timeline: 'friends' })
+ dispatch('startFetchingTimeline', { timeline: 'friends' })
// Start fetching notifications
- store.dispatch('startFetchingNotifications')
+ dispatch('startFetchingNotifications')
// Start fetching chats
- store.dispatch('startFetchingChats')
+ dispatch('startFetchingChats')
}
- store.dispatch('startFetchingLists')
+ dispatch('startFetchingLists')
if (user.locked) {
- store.dispatch('startFetchingFollowRequests')
+ dispatch('startFetchingFollowRequests')
}
if (store.getters.mergedConfig.useStreamingApi) {
- store.dispatch('fetchTimeline', { timeline: 'friends', since: null })
- store.dispatch('fetchNotifications', { since: null })
- store.dispatch('enableMastoSockets', true).catch((error) => {
+ dispatch('fetchTimeline', { timeline: 'friends', since: null })
+ dispatch('fetchNotifications', { since: null })
+ dispatch('enableMastoSockets', true).catch((error) => {
console.error('Failed initializing MastoAPI Streaming socket', error)
}).then(() => {
- store.dispatch('fetchChats', { latest: true })
- setTimeout(() => store.dispatch('setNotificationsSilence', false), 10000)
+ dispatch('fetchChats', { latest: true })
+ setTimeout(() => dispatch('setNotificationsSilence', false), 10000)
})
} else {
startPolling()
}
// Get user mutes
- store.dispatch('fetchMutes')
+ dispatch('fetchMutes')
- store.dispatch('setLayoutWidth', windowWidth())
- store.dispatch('setLayoutHeight', windowHeight())
+ dispatch('setLayoutWidth', windowWidth())
+ dispatch('setLayoutHeight', windowHeight())
// Fetch our friends
store.rootState.api.backendInteractor.fetchFriends({ id: user.id })
@@ -621,6 +651,12 @@ const users = {
const response = data.error
// Authentication failed
commit('endLogin')
+
+ // remove authentication token on client/authentication errors
+ if ([400, 401, 403, 422].includes(response.status)) {
+ commit('clearToken')
+ }
+
if (response.status === 401) {
reject(new Error('Wrong username or password'))
} else {