aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/api.js140
-rw-r--r--src/modules/auth_flow.js8
-rw-r--r--src/modules/config.js1
-rw-r--r--src/modules/instance.js1
-rw-r--r--src/modules/oauth_tokens.js2
-rw-r--r--src/modules/polls.js4
-rw-r--r--src/modules/statuses.js33
-rw-r--r--src/modules/users.js52
8 files changed, 181 insertions, 60 deletions
diff --git a/src/modules/api.js b/src/modules/api.js
index 1293e3c8..9c296275 100644
--- a/src/modules/api.js
+++ b/src/modules/api.js
@@ -6,6 +6,7 @@ const api = {
backendInteractor: backendInteractorService(),
fetchers: {},
socket: null,
+ mastoUserSocket: null,
followRequests: []
},
mutations: {
@@ -15,7 +16,8 @@ const api = {
addFetcher (state, { fetcherName, fetcher }) {
state.fetchers[fetcherName] = fetcher
},
- removeFetcher (state, { fetcherName }) {
+ removeFetcher (state, { fetcherName, fetcher }) {
+ window.clearInterval(fetcher)
delete state.fetchers[fetcherName]
},
setWsToken (state, token) {
@@ -29,32 +31,134 @@ const api = {
}
},
actions: {
- startFetchingTimeline (store, { timeline = 'friends', tag = false, userId = false }) {
- // Don't start fetching if we already are.
+ // Global MastoAPI socket control, in future should disable ALL sockets/(re)start relevant sockets
+ enableMastoSockets (store) {
+ const { state, dispatch } = store
+ if (state.mastoUserSocket) return
+ return dispatch('startMastoUserSocket')
+ },
+ disableMastoSockets (store) {
+ const { state, dispatch } = store
+ if (!state.mastoUserSocket) return
+ return dispatch('stopMastoUserSocket')
+ },
+
+ // MastoAPI 'User' sockets
+ startMastoUserSocket (store) {
+ return new Promise((resolve, reject) => {
+ try {
+ const { state, dispatch, rootState } = store
+ const timelineData = rootState.statuses.timelines.friends
+ state.mastoUserSocket = state.backendInteractor.startUserSocket({ store })
+ state.mastoUserSocket.addEventListener(
+ 'message',
+ ({ detail: message }) => {
+ if (!message) return // pings
+ if (message.event === 'notification') {
+ dispatch('addNewNotifications', {
+ notifications: [message.notification],
+ older: false
+ })
+ } else if (message.event === 'update') {
+ dispatch('addNewStatuses', {
+ statuses: [message.status],
+ userId: false,
+ showImmediately: timelineData.visibleStatuses.length === 0,
+ timeline: 'friends'
+ })
+ }
+ }
+ )
+ state.mastoUserSocket.addEventListener('error', ({ detail: error }) => {
+ console.error('Error in MastoAPI websocket:', error)
+ })
+ state.mastoUserSocket.addEventListener('close', ({ detail: closeEvent }) => {
+ const ignoreCodes = new Set([
+ 1000, // Normal (intended) closure
+ 1001 // Going away
+ ])
+ const { code } = closeEvent
+ if (ignoreCodes.has(code)) {
+ console.debug(`Not restarting socket becasue of closure code ${code} is in ignore list`)
+ } else {
+ console.warn(`MastoAPI websocket disconnected, restarting. CloseEvent code: ${code}`)
+ dispatch('startFetchingTimeline', { timeline: 'friends' })
+ dispatch('startFetchingNotifications')
+ dispatch('restartMastoUserSocket')
+ }
+ })
+ resolve()
+ } catch (e) {
+ reject(e)
+ }
+ })
+ },
+ restartMastoUserSocket ({ dispatch }) {
+ // This basically starts MastoAPI user socket and stops conventional
+ // fetchers when connection reestablished
+ return dispatch('startMastoUserSocket').then(() => {
+ dispatch('stopFetchingTimeline', { timeline: 'friends' })
+ dispatch('stopFetchingNotifications')
+ })
+ },
+ stopMastoUserSocket ({ state, dispatch }) {
+ dispatch('startFetchingTimeline', { timeline: 'friends' })
+ dispatch('startFetchingNotifications')
+ console.log(state.mastoUserSocket)
+ state.mastoUserSocket.close()
+ },
+
+ // Timelines
+ startFetchingTimeline (store, {
+ timeline = 'friends',
+ tag = false,
+ userId = false
+ }) {
if (store.state.fetchers[timeline]) return
- const fetcher = store.state.backendInteractor.startFetchingTimeline({ timeline, store, userId, tag })
+ const fetcher = store.state.backendInteractor.startFetchingTimeline({
+ timeline, store, userId, tag
+ })
store.commit('addFetcher', { fetcherName: timeline, fetcher })
},
- startFetchingNotifications (store) {
- // Don't start fetching if we already are.
- if (store.state.fetchers['notifications']) return
+ stopFetchingTimeline (store, timeline) {
+ const fetcher = store.state.fetchers[timeline]
+ if (!fetcher) return
+ store.commit('removeFetcher', { fetcherName: timeline, fetcher })
+ },
+ // Notifications
+ startFetchingNotifications (store) {
+ if (store.state.fetchers.notifications) return
const fetcher = store.state.backendInteractor.startFetchingNotifications({ store })
store.commit('addFetcher', { fetcherName: 'notifications', fetcher })
},
- startFetchingFollowRequest (store) {
- // Don't start fetching if we already are.
- if (store.state.fetchers['followRequest']) return
+ stopFetchingNotifications (store) {
+ const fetcher = store.state.fetchers.notifications
+ if (!fetcher) return
+ store.commit('removeFetcher', { fetcherName: 'notifications', fetcher })
+ },
+ fetchAndUpdateNotifications (store) {
+ store.state.backendInteractor.fetchAndUpdateNotifications({ store })
+ },
- const fetcher = store.state.backendInteractor.startFetchingFollowRequest({ store })
- store.commit('addFetcher', { fetcherName: 'followRequest', fetcher })
+ // Follow requests
+ startFetchingFollowRequests (store) {
+ if (store.state.fetchers['followRequests']) return
+ const fetcher = store.state.backendInteractor.startFetchingFollowRequests({ store })
+ store.commit('addFetcher', { fetcherName: 'followRequests', fetcher })
},
- stopFetching (store, fetcherName) {
- const fetcher = store.state.fetchers[fetcherName]
- window.clearInterval(fetcher)
- store.commit('removeFetcher', { fetcherName })
+ stopFetchingFollowRequests (store) {
+ const fetcher = store.state.fetchers.followRequests
+ if (!fetcher) return
+ store.commit('removeFetcher', { fetcherName: 'followRequests', fetcher })
+ },
+ removeFollowRequest (store, request) {
+ let requests = store.state.followRequests.filter((it) => it !== request)
+ store.commit('setFollowRequests', requests)
},
+
+ // Pleroma websocket
setWsToken (store, token) {
store.commit('setWsToken', token)
},
@@ -72,10 +176,6 @@ const api = {
disconnectFromSocket ({ commit, state }) {
state.socket && state.socket.disconnect()
commit('setSocket', null)
- },
- removeFollowRequest (store, request) {
- let requests = store.state.followRequests.filter((it) => it !== request)
- store.commit('setFollowRequests', requests)
}
}
}
diff --git a/src/modules/auth_flow.js b/src/modules/auth_flow.js
index d0a90feb..956d40e8 100644
--- a/src/modules/auth_flow.js
+++ b/src/modules/auth_flow.js
@@ -7,7 +7,6 @@ const RECOVERY_STRATEGY = 'recovery'
// initial state
const state = {
- app: null,
settings: {},
strategy: PASSWORD_STRATEGY,
initStrategy: PASSWORD_STRATEGY // default strategy from config
@@ -16,14 +15,10 @@ const state = {
const resetState = (state) => {
state.strategy = state.initStrategy
state.settings = {}
- state.app = null
}
// getters
const getters = {
- app: (state, getters) => {
- return state.app
- },
settings: (state, getters) => {
return state.settings
},
@@ -55,9 +50,8 @@ const mutations = {
requireToken (state) {
state.strategy = TOKEN_STRATEGY
},
- requireMFA (state, { app, settings }) {
+ requireMFA (state, { settings }) {
state.settings = settings
- state.app = app
state.strategy = TOTP_STRATEGY // default strategy of MFA
},
requireRecovery (state) {
diff --git a/src/modules/config.js b/src/modules/config.js
index cc47c848..de9f041b 100644
--- a/src/modules/config.js
+++ b/src/modules/config.js
@@ -36,6 +36,7 @@ export const defaultState = {
highlight: {},
interfaceLanguage: browserLocale,
hideScopeNotice: false,
+ useStreamingApi: false,
scopeCopy: undefined, // instance default
subjectLineBehavior: undefined, // instance default
alwaysShowSubjectInput: undefined, // instance default
diff --git a/src/modules/instance.js b/src/modules/instance.js
index 96f14ed5..625323b9 100644
--- a/src/modules/instance.js
+++ b/src/modules/instance.js
@@ -27,6 +27,7 @@ const defaultState = {
scopeCopy: true,
subjectLineBehavior: 'email',
postContentType: 'text/plain',
+ hideSitename: false,
nsfwCensorImage: undefined,
vapidPublicKey: undefined,
noAttachmentLinks: false,
diff --git a/src/modules/oauth_tokens.js b/src/modules/oauth_tokens.js
index 0159a3f1..907cae4a 100644
--- a/src/modules/oauth_tokens.js
+++ b/src/modules/oauth_tokens.js
@@ -9,7 +9,7 @@ const oauthTokens = {
})
},
revokeToken ({ rootState, commit, state }, id) {
- rootState.api.backendInteractor.revokeOAuthToken(id).then((response) => {
+ rootState.api.backendInteractor.revokeOAuthToken({ id }).then((response) => {
if (response.status === 201) {
commit('swapTokens', state.tokens.filter(token => token.id !== id))
}
diff --git a/src/modules/polls.js b/src/modules/polls.js
index e6158b63..92b89a06 100644
--- a/src/modules/polls.js
+++ b/src/modules/polls.js
@@ -40,7 +40,7 @@ const polls = {
commit('mergeOrAddPoll', poll)
},
updateTrackedPoll ({ rootState, dispatch, commit }, pollId) {
- rootState.api.backendInteractor.fetchPoll(pollId).then(poll => {
+ rootState.api.backendInteractor.fetchPoll({ pollId }).then(poll => {
setTimeout(() => {
if (rootState.polls.trackedPolls[pollId]) {
dispatch('updateTrackedPoll', pollId)
@@ -59,7 +59,7 @@ const polls = {
commit('untrackPoll', pollId)
},
votePoll ({ rootState, commit }, { id, pollId, choices }) {
- return rootState.api.backendInteractor.vote(pollId, choices).then(poll => {
+ return rootState.api.backendInteractor.vote({ pollId, choices }).then(poll => {
commit('mergeOrAddPoll', poll)
return poll
})
diff --git a/src/modules/statuses.js b/src/modules/statuses.js
index f3fc0f21..16dae8ce 100644
--- a/src/modules/statuses.js
+++ b/src/modules/statuses.js
@@ -38,6 +38,7 @@ export const defaultState = () => ({
notifications: emptyNotifications(),
favorites: new Set(),
error: false,
+ errorData: null,
timelines: {
mentions: emptyTl(),
public: emptyTl(),
@@ -483,6 +484,9 @@ export const mutations = {
setError (state, { value }) {
state.error = value
},
+ setErrorData (state, { value }) {
+ state.errorData = value
+ },
setNotificationsLoading (state, { value }) {
state.notifications.loading = value
},
@@ -532,6 +536,9 @@ const statuses = {
setError ({ rootState, commit }, { value }) {
commit('setError', { value })
},
+ setErrorData ({ rootState, commit }, { value }) {
+ commit('setErrorData', { value })
+ },
setNotificationsLoading ({ rootState, commit }, { value }) {
commit('setNotificationsLoading', { value })
},
@@ -555,45 +562,45 @@ const statuses = {
favorite ({ rootState, commit }, status) {
// Optimistic favoriting...
commit('setFavorited', { status, value: true })
- rootState.api.backendInteractor.favorite(status.id)
+ rootState.api.backendInteractor.favorite({ id: status.id })
.then(status => commit('setFavoritedConfirm', { status, user: rootState.users.currentUser }))
},
unfavorite ({ rootState, commit }, status) {
// Optimistic unfavoriting...
commit('setFavorited', { status, value: false })
- rootState.api.backendInteractor.unfavorite(status.id)
+ rootState.api.backendInteractor.unfavorite({ id: status.id })
.then(status => commit('setFavoritedConfirm', { status, user: rootState.users.currentUser }))
},
fetchPinnedStatuses ({ rootState, dispatch }, userId) {
- rootState.api.backendInteractor.fetchPinnedStatuses(userId)
+ rootState.api.backendInteractor.fetchPinnedStatuses({ id: userId })
.then(statuses => dispatch('addNewStatuses', { statuses, timeline: 'user', userId, showImmediately: true, noIdUpdate: true }))
},
pinStatus ({ rootState, dispatch }, statusId) {
- return rootState.api.backendInteractor.pinOwnStatus(statusId)
+ return rootState.api.backendInteractor.pinOwnStatus({ id: statusId })
.then((status) => dispatch('addNewStatuses', { statuses: [status] }))
},
unpinStatus ({ rootState, dispatch }, statusId) {
- rootState.api.backendInteractor.unpinOwnStatus(statusId)
+ rootState.api.backendInteractor.unpinOwnStatus({ id: statusId })
.then((status) => dispatch('addNewStatuses', { statuses: [status] }))
},
muteConversation ({ rootState, commit }, statusId) {
- return rootState.api.backendInteractor.muteConversation(statusId)
+ return rootState.api.backendInteractor.muteConversation({ id: statusId })
.then((status) => commit('setMutedStatus', status))
},
unmuteConversation ({ rootState, commit }, statusId) {
- return rootState.api.backendInteractor.unmuteConversation(statusId)
+ return rootState.api.backendInteractor.unmuteConversation({ id: statusId })
.then((status) => commit('setMutedStatus', status))
},
retweet ({ rootState, commit }, status) {
// Optimistic retweeting...
commit('setRetweeted', { status, value: true })
- rootState.api.backendInteractor.retweet(status.id)
+ rootState.api.backendInteractor.retweet({ id: 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 })
- rootState.api.backendInteractor.unretweet(status.id)
+ rootState.api.backendInteractor.unretweet({ id: status.id })
.then(status => commit('setRetweetedConfirm', { status, user: rootState.users.currentUser }))
},
queueFlush ({ rootState, commit }, { timeline, id }) {
@@ -608,19 +615,19 @@ const statuses = {
},
fetchFavsAndRepeats ({ rootState, commit }, id) {
Promise.all([
- rootState.api.backendInteractor.fetchFavoritedByUsers(id),
- rootState.api.backendInteractor.fetchRebloggedByUsers(id)
+ rootState.api.backendInteractor.fetchFavoritedByUsers({ id }),
+ rootState.api.backendInteractor.fetchRebloggedByUsers({ id })
]).then(([favoritedByUsers, rebloggedByUsers]) => {
commit('addFavs', { id, favoritedByUsers, currentUser: rootState.users.currentUser })
commit('addRepeats', { id, rebloggedByUsers, currentUser: rootState.users.currentUser })
})
},
fetchFavs ({ rootState, commit }, id) {
- rootState.api.backendInteractor.fetchFavoritedByUsers(id)
+ rootState.api.backendInteractor.fetchFavoritedByUsers({ id })
.then(favoritedByUsers => commit('addFavs', { id, favoritedByUsers, currentUser: rootState.users.currentUser }))
},
fetchRepeats ({ rootState, commit }, id) {
- rootState.api.backendInteractor.fetchRebloggedByUsers(id)
+ rootState.api.backendInteractor.fetchRebloggedByUsers({ id })
.then(rebloggedByUsers => commit('addRepeats', { id, rebloggedByUsers, currentUser: rootState.users.currentUser }))
},
search (store, { q, resolve, limit, offset, following }) {
diff --git a/src/modules/users.js b/src/modules/users.js
index f209b23b..84fa0255 100644
--- a/src/modules/users.js
+++ b/src/modules/users.js
@@ -32,7 +32,7 @@ const getNotificationPermission = () => {
}
const blockUser = (store, id) => {
- return store.rootState.api.backendInteractor.blockUser(id)
+ return store.rootState.api.backendInteractor.blockUser({ id })
.then((relationship) => {
store.commit('updateUserRelationship', [relationship])
store.commit('addBlockId', id)
@@ -43,12 +43,12 @@ const blockUser = (store, id) => {
}
const unblockUser = (store, id) => {
- return store.rootState.api.backendInteractor.unblockUser(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)
+ return store.rootState.api.backendInteractor.muteUser({ id })
.then((relationship) => {
store.commit('updateUserRelationship', [relationship])
store.commit('addMuteId', id)
@@ -56,7 +56,7 @@ const muteUser = (store, id) => {
}
const unmuteUser = (store, id) => {
- return store.rootState.api.backendInteractor.unmuteUser(id)
+ return store.rootState.api.backendInteractor.unmuteUser({ id })
.then((relationship) => store.commit('updateUserRelationship', [relationship]))
}
@@ -95,9 +95,9 @@ export const mutations = {
newRights[right] = value
set(user, 'rights', newRights)
},
- updateActivationStatus (state, { user: { id }, status }) {
+ updateActivationStatus (state, { user: { id }, deactivated }) {
const user = state.usersObject[id]
- set(user, 'deactivated', !status)
+ set(user, 'deactivated', deactivated)
},
setCurrentUser (state, user) {
state.lastLoginName = user.screen_name
@@ -324,13 +324,18 @@ const users = {
commit('clearFollowers', userId)
},
subscribeUser ({ rootState, commit }, id) {
- return rootState.api.backendInteractor.subscribeUser(id)
+ return rootState.api.backendInteractor.subscribeUser({ id })
.then((relationship) => commit('updateUserRelationship', [relationship]))
},
unsubscribeUser ({ rootState, commit }, id) {
- return rootState.api.backendInteractor.unsubscribeUser(id)
+ return rootState.api.backendInteractor.unsubscribeUser({ id })
.then((relationship) => commit('updateUserRelationship', [relationship]))
},
+ toggleActivationStatus ({ rootState, commit }, user) {
+ const api = user.deactivated ? rootState.api.backendInteractor.activateUser : rootState.api.backendInteractor.deactivateUser
+ api(user)
+ .then(({ deactivated }) => commit('updateActivationStatus', { user, deactivated }))
+ },
registerPushNotifications (store) {
const token = store.state.currentUser.credentials
const vapidPublicKey = store.rootState.instance.vapidPublicKey
@@ -384,7 +389,7 @@ const users = {
})
},
searchUsers (store, query) {
- return store.rootState.api.backendInteractor.searchUsers(query)
+ return store.rootState.api.backendInteractor.searchUsers({ query })
.then((users) => {
store.commit('addNewUsers', users)
return users
@@ -396,7 +401,7 @@ const users = {
let rootState = store.rootState
try {
- let data = await rootState.api.backendInteractor.register(userInfo)
+ let data = await rootState.api.backendInteractor.register({ ...userInfo })
store.commit('signUpSuccess')
store.commit('setToken', data.access_token)
store.dispatch('loginUser', data.access_token)
@@ -433,10 +438,10 @@ const users = {
store.commit('clearCurrentUser')
store.dispatch('disconnectFromSocket')
store.commit('clearToken')
- store.dispatch('stopFetching', 'friends')
+ store.dispatch('stopFetchingTimeline', 'friends')
store.commit('setBackendInteractor', backendInteractorService(store.getters.getToken()))
- store.dispatch('stopFetching', 'notifications')
- store.dispatch('stopFetching', 'followRequest')
+ store.dispatch('stopFetchingNotifications')
+ store.dispatch('stopFetchingFollowRequests')
store.commit('clearNotifications')
store.commit('resetStatuses')
})
@@ -471,11 +476,24 @@ const users = {
store.dispatch('initializeSocket')
}
- // Start getting fresh posts.
- store.dispatch('startFetchingTimeline', { timeline: 'friends' })
+ const startPolling = () => {
+ // Start getting fresh posts.
+ store.dispatch('startFetchingTimeline', { timeline: 'friends' })
+
+ // Start fetching notifications
+ store.dispatch('startFetchingNotifications')
+ }
- // Start fetching notifications
- store.dispatch('startFetchingNotifications')
+ if (store.getters.mergedConfig.useStreamingApi) {
+ store.dispatch('enableMastoSockets').catch((error) => {
+ console.error('Failed initializing MastoAPI Streaming socket', error)
+ startPolling()
+ }).then(() => {
+ setTimeout(() => store.dispatch('setNotificationsSilence', false), 10000)
+ })
+ } else {
+ startPolling()
+ }
// Get user mutes
store.dispatch('fetchMutes')