aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/config.js1
-rw-r--r--src/modules/instance.js3
-rw-r--r--src/modules/oauth_tokens.js26
-rw-r--r--src/modules/statuses.js21
-rw-r--r--src/modules/users.js96
5 files changed, 114 insertions, 33 deletions
diff --git a/src/modules/config.js b/src/modules/config.js
index 71f71376..1c30c203 100644
--- a/src/modules/config.js
+++ b/src/modules/config.js
@@ -8,6 +8,7 @@ const defaultState = {
collapseMessageWithSubject: undefined, // instance default
hideAttachments: false,
hideAttachmentsInConv: false,
+ maxThumbnails: 16,
hideNsfw: true,
preloadImage: true,
loopVideo: true,
diff --git a/src/modules/instance.js b/src/modules/instance.js
index 59c6b91c..24c52f9c 100644
--- a/src/modules/instance.js
+++ b/src/modules/instance.js
@@ -21,7 +21,7 @@ const defaultState = {
collapseMessageWithSubject: false,
hidePostStats: false,
hideUserStats: false,
- hideFilteredStatuses: true,
+ hideFilteredStatuses: false,
disableChat: false,
scopeCopy: true,
subjectLineBehavior: 'email',
@@ -37,6 +37,7 @@ const defaultState = {
emoji: [],
customEmoji: [],
restrictedNicknames: [],
+ postFormats: [],
// Feature-set, apparently, not everything here is reported...
mediaProxyAvailable: false,
diff --git a/src/modules/oauth_tokens.js b/src/modules/oauth_tokens.js
new file mode 100644
index 00000000..00ac1431
--- /dev/null
+++ b/src/modules/oauth_tokens.js
@@ -0,0 +1,26 @@
+const oauthTokens = {
+ state: {
+ tokens: []
+ },
+ actions: {
+ fetchTokens ({rootState, commit}) {
+ rootState.api.backendInteractor.fetchOAuthTokens().then((tokens) => {
+ commit('swapTokens', tokens)
+ })
+ },
+ revokeToken ({rootState, commit, state}, id) {
+ rootState.api.backendInteractor.revokeOAuthToken(id).then((response) => {
+ if (response.status === 201) {
+ commit('swapTokens', state.tokens.filter(token => token.id !== id))
+ }
+ })
+ }
+ },
+ mutations: {
+ swapTokens (state, tokens) {
+ state.tokens = tokens
+ }
+ }
+}
+
+export default oauthTokens
diff --git a/src/modules/statuses.js b/src/modules/statuses.js
index 56619455..96a3549d 100644
--- a/src/modules/statuses.js
+++ b/src/modules/statuses.js
@@ -10,6 +10,7 @@ const emptyTl = (userId = 0) => ({
visibleStatusesObject: {},
newStatusCount: 0,
maxId: 0,
+ minId: 0,
minVisibleId: 0,
loading: false,
followers: [],
@@ -117,16 +118,21 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
const timelineObject = state.timelines[timeline]
const maxNew = statuses.length > 0 ? maxBy(statuses, 'id').id : 0
- const older = timeline && maxNew < timelineObject.maxId
+ const minNew = statuses.length > 0 ? minBy(statuses, 'id').id : 0
+ const newer = timeline && maxNew > timelineObject.maxId && statuses.length > 0
+ const older = timeline && (minNew < timelineObject.minId || timelineObject.minId === 0) && statuses.length > 0
- if (timeline && !noIdUpdate && statuses.length > 0 && !older) {
+ if (!noIdUpdate && newer) {
timelineObject.maxId = maxNew
}
+ if (!noIdUpdate && older) {
+ timelineObject.minId = minNew
+ }
// This makes sure that user timeline won't get data meant for other
// user. I.e. opening different user profiles makes request which could
// return data late after user already viewing different user profile
- if (timeline === 'user' && timelineObject.userId !== userId) {
+ if ((timeline === 'user' || timeline === 'media') && timelineObject.userId !== userId) {
return
}
@@ -255,12 +261,9 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
processor(status)
})
- // Keep the visible statuses sorted
+ // Keep the visible statuses sorted
if (timeline) {
sortTimeline(timelineObject)
- if ((older || timelineObject.minVisibleId <= 0) && statuses.length > 0) {
- timelineObject.minVisibleId = minBy(statuses, 'id').id
- }
}
}
@@ -296,13 +299,15 @@ const addNewNotifications = (state, { dispatch, notifications, older, visibleNot
notifObj.image = action.attachments[0].url
}
- if (notification.fresh && !state.notifications.desktopNotificationSilence && visibleNotificationTypes.includes(notification.ntype)) {
+ if (!notification.seen && !state.notifications.desktopNotificationSilence && visibleNotificationTypes.includes(notification.type)) {
let notification = new window.Notification(title, notifObj)
// Chrome is known for not closing notifications automatically
// according to MDN, anyway.
setTimeout(notification.close.bind(notification), 5000)
}
}
+ } else if (notification.seen) {
+ state.notifications.idStore[notification.id].seen = true
}
})
}
diff --git a/src/modules/users.js b/src/modules/users.js
index 4d56ec6f..093af497 100644
--- a/src/modules/users.js
+++ b/src/modules/users.js
@@ -72,19 +72,31 @@ export const mutations = {
},
// Because frontend doesn't have a reason to keep these stuff in memory
// outside of viewing someones user profile.
- clearFriendsAndFollowers (state, userKey) {
- const user = state.usersObject[userKey]
+ clearFriends (state, userId) {
+ const user = state.usersObject[userId]
if (!user) {
return
}
user.friends = []
- user.followers = []
user.friendsPage = 0
+ },
+ clearFollowers (state, userId) {
+ const user = state.usersObject[userId]
+ if (!user) {
+ return
+ }
+ user.followers = []
user.followersPage = 0
},
addNewUsers (state, users) {
each(users, (user) => mergeOrAdd(state.users, state.usersObject, user))
},
+ saveBlocks (state, blockIds) {
+ state.currentUser.blockIds = blockIds
+ },
+ saveMutes (state, muteIds) {
+ state.currentUser.muteIds = muteIds
+ },
setUserForStatus (state, status) {
status.user = state.usersObject[status.user.id]
},
@@ -134,7 +146,39 @@ const users = {
getters,
actions: {
fetchUser (store, id) {
- store.rootState.api.backendInteractor.fetchUser({ id })
+ return store.rootState.api.backendInteractor.fetchUser({ id })
+ .then((user) => store.commit('addNewUsers', [user]))
+ },
+ fetchBlocks (store) {
+ return store.rootState.api.backendInteractor.fetchBlocks()
+ .then((blocks) => {
+ store.commit('saveBlocks', map(blocks, 'id'))
+ store.commit('addNewUsers', blocks)
+ return blocks
+ })
+ },
+ blockUser (store, id) {
+ return store.rootState.api.backendInteractor.blockUser(id)
+ .then((user) => store.commit('addNewUsers', [user]))
+ },
+ unblockUser (store, id) {
+ return store.rootState.api.backendInteractor.unblockUser(id)
+ .then((user) => store.commit('addNewUsers', [user]))
+ },
+ fetchMutes (store) {
+ return store.rootState.api.backendInteractor.fetchMutes()
+ .then((mutedUsers) => {
+ each(mutedUsers, (user) => { user.muted = true })
+ store.commit('addNewUsers', mutedUsers)
+ store.commit('saveMutes', map(mutedUsers, 'id'))
+ })
+ },
+ muteUser (store, id) {
+ return store.state.api.backendInteractor.setUserMute({ id, muted: true })
+ .then((user) => store.commit('addNewUsers', [user]))
+ },
+ unmuteUser (store, id) {
+ return store.state.api.backendInteractor.setUserMute({ id, muted: false })
.then((user) => store.commit('addNewUsers', [user]))
},
addFriends ({ rootState, commit }, fetchBy) {
@@ -151,20 +195,19 @@ const users = {
})
},
addFollowers ({ rootState, commit }, fetchBy) {
- return new Promise((resolve, reject) => {
- const user = rootState.users.usersObject[fetchBy]
- const page = user.followersPage || 1
- rootState.api.backendInteractor.fetchFollowers({ id: user.id, page })
- .then((followers) => {
- commit('addFollowers', { id: user.id, followers, page })
- resolve(followers)
- }).catch(() => {
- reject()
- })
- })
+ const user = rootState.users.usersObject[fetchBy]
+ const page = user.followersPage || 1
+ return rootState.api.backendInteractor.fetchFollowers({ id: user.id, page })
+ .then((followers) => {
+ commit('addFollowers', { id: user.id, followers, page })
+ return followers
+ })
+ },
+ clearFriends ({ commit }, userId) {
+ commit('clearFriends', userId)
},
- clearFriendsAndFollowers ({ commit }, userKey) {
- commit('clearFriendsAndFollowers', userKey)
+ clearFollowers ({ commit }, userId) {
+ commit('clearFollowers', userId)
},
registerPushNotifications (store) {
const token = store.state.currentUser.credentials
@@ -231,8 +274,14 @@ const users = {
store.commit('setToken', result.access_token)
store.dispatch('loginUser', result.access_token)
} else {
- let data = await response.json()
- let errors = humanizeErrors(JSON.parse(data.error))
+ const data = await response.json()
+ let errors = JSON.parse(data.error)
+ // replace ap_id with username
+ if (errors.ap_id) {
+ errors.username = errors.ap_id
+ delete errors.ap_id
+ }
+ errors = humanizeErrors(errors)
store.commit('signUpFailure', errors)
throw Error(errors)
}
@@ -257,6 +306,8 @@ const users = {
const user = data
// user.credentials = userCredentials
user.credentials = accessToken
+ user.blockIds = []
+ user.muteIds = []
commit('setCurrentUser', user)
commit('addNewUsers', [user])
@@ -273,11 +324,8 @@ const users = {
// Start getting fresh posts.
store.dispatch('startFetching', { timeline: 'friends' })
- // Get user mutes and follower info
- store.rootState.api.backendInteractor.fetchMutes().then((mutedUsers) => {
- each(mutedUsers, (user) => { user.muted = true })
- store.commit('addNewUsers', mutedUsers)
- })
+ // Get user mutes
+ store.dispatch('fetchMutes')
// Fetch our friends
store.rootState.api.backendInteractor.fetchFriends({ id: user.id })