2026-01-06 16:22:52 +02:00
|
|
|
import {
|
|
|
|
|
compact,
|
2026-01-06 16:23:17 +02:00
|
|
|
concat,
|
2026-01-06 16:22:52 +02:00
|
|
|
each,
|
2026-01-06 16:23:17 +02:00
|
|
|
isArray,
|
2026-01-06 16:22:52 +02:00
|
|
|
last,
|
2026-01-06 16:23:17 +02:00
|
|
|
map,
|
|
|
|
|
mergeWith,
|
2026-01-06 16:22:52 +02:00
|
|
|
uniq,
|
|
|
|
|
} from 'lodash'
|
2026-01-08 17:26:52 +02:00
|
|
|
|
2026-01-06 16:23:17 +02:00
|
|
|
import { declarations } from 'src/modules/config_declaration'
|
2026-01-29 00:49:26 +02:00
|
|
|
import { useInstanceStore } from 'src/stores/instance.js'
|
2026-01-06 16:23:17 +02:00
|
|
|
import { useInterfaceStore } from 'src/stores/interface.js'
|
|
|
|
|
import { useOAuthStore } from 'src/stores/oauth.js'
|
|
|
|
|
import { useServerSideStorageStore } from 'src/stores/serverSideStorage'
|
2025-03-09 15:06:19 -04:00
|
|
|
import apiService from '../services/api/api.service.js'
|
2026-01-06 16:23:17 +02:00
|
|
|
import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js'
|
2019-07-02 15:33:40 +07:00
|
|
|
import oauthApi from '../services/new_api/oauth.js'
|
2026-01-06 16:22:52 +02:00
|
|
|
import {
|
|
|
|
|
registerPushNotifications,
|
|
|
|
|
unregisterPushNotifications,
|
|
|
|
|
} from '../services/sw/sw.js'
|
2026-01-06 16:23:17 +02:00
|
|
|
import {
|
|
|
|
|
windowHeight,
|
|
|
|
|
windowWidth,
|
|
|
|
|
} from '../services/window_utils/window_utils'
|
2016-10-27 18:03:14 +02:00
|
|
|
|
2016-11-30 18:29:44 +01:00
|
|
|
// TODO: Unify with mergeOrAdd in statuses.js
|
2017-03-08 17:59:12 +01:00
|
|
|
export const mergeOrAdd = (arr, obj, item) => {
|
2026-01-06 16:22:52 +02:00
|
|
|
if (!item) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2017-03-08 17:59:12 +01:00
|
|
|
const oldItem = obj[item.id]
|
2016-11-30 18:29:44 +01:00
|
|
|
if (oldItem) {
|
|
|
|
|
// We already have this, so only merge the new info.
|
2019-11-17 22:34:00 +09:00
|
|
|
mergeWith(oldItem, item, mergeArrayLength)
|
2018-12-13 18:22:15 +07:00
|
|
|
return { item: oldItem, new: false }
|
2016-11-30 18:29:44 +01:00
|
|
|
} else {
|
|
|
|
|
// This is a new item, prepare it
|
|
|
|
|
arr.push(item)
|
2021-04-25 13:24:08 +03:00
|
|
|
obj[item.id] = item
|
2018-12-13 18:22:15 +07:00
|
|
|
return { item, new: true }
|
2016-11-30 18:29:44 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-17 22:34:00 +09:00
|
|
|
const mergeArrayLength = (oldValue, newValue) => {
|
|
|
|
|
if (isArray(oldValue) && isArray(newValue)) {
|
|
|
|
|
oldValue.length = newValue.length
|
|
|
|
|
return mergeWith(oldValue, newValue, mergeArrayLength)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-13 18:04:09 +07:00
|
|
|
const getNotificationPermission = () => {
|
|
|
|
|
const Notification = window.Notification
|
|
|
|
|
|
|
|
|
|
if (!Notification) return Promise.resolve(null)
|
2026-01-06 16:22:52 +02:00
|
|
|
if (Notification.permission === 'default')
|
|
|
|
|
return Notification.requestPermission()
|
2018-12-13 18:04:09 +07:00
|
|
|
return Promise.resolve(Notification.permission)
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-12 20:04:39 +03:00
|
|
|
const blockUser = (store, args) => {
|
|
|
|
|
const id = args.id
|
|
|
|
|
const expiresIn = typeof args === 'object' ? args.expiresIn : 0
|
|
|
|
|
|
|
|
|
|
const predictedRelationship = store.state.relationships[id] || { id }
|
|
|
|
|
store.commit('updateUserRelationship', [predictedRelationship])
|
|
|
|
|
store.commit('addBlockId', id)
|
|
|
|
|
|
2026-01-06 16:22:52 +02:00
|
|
|
return store.rootState.api.backendInteractor
|
|
|
|
|
.blockUser({ id, expiresIn })
|
2019-04-04 13:54:52 -04:00
|
|
|
.then((relationship) => {
|
|
|
|
|
store.commit('updateUserRelationship', [relationship])
|
2019-04-04 14:02:46 -04:00
|
|
|
store.commit('addBlockId', id)
|
2025-06-12 20:04:39 +03:00
|
|
|
|
2019-04-04 14:02:46 -04:00
|
|
|
store.commit('removeStatus', { timeline: 'friends', userId: id })
|
|
|
|
|
store.commit('removeStatus', { timeline: 'public', userId: id })
|
2026-01-06 16:22:52 +02:00
|
|
|
store.commit('removeStatus', {
|
|
|
|
|
timeline: 'publicAndExternal',
|
|
|
|
|
userId: id,
|
|
|
|
|
})
|
2019-04-04 13:54:52 -04:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-04 14:02:46 -04:00
|
|
|
const unblockUser = (store, id) => {
|
2026-01-06 16:22:52 +02:00
|
|
|
return store.rootState.api.backendInteractor
|
|
|
|
|
.unblockUser({ id })
|
|
|
|
|
.then((relationship) =>
|
|
|
|
|
store.commit('updateUserRelationship', [relationship]),
|
|
|
|
|
)
|
2019-04-04 14:02:46 -04:00
|
|
|
}
|
|
|
|
|
|
2022-09-15 22:02:58 -06:00
|
|
|
const removeUserFromFollowers = (store, id) => {
|
2026-01-06 16:22:52 +02:00
|
|
|
return store.rootState.api.backendInteractor
|
|
|
|
|
.removeUserFromFollowers({ id })
|
|
|
|
|
.then((relationship) =>
|
|
|
|
|
store.commit('updateUserRelationship', [relationship]),
|
|
|
|
|
)
|
2022-09-15 22:02:58 -06:00
|
|
|
}
|
|
|
|
|
|
2022-08-20 13:18:57 -04:00
|
|
|
const editUserNote = (store, { id, comment }) => {
|
2026-01-06 16:22:52 +02:00
|
|
|
return store.rootState.api.backendInteractor
|
|
|
|
|
.editUserNote({ id, comment })
|
|
|
|
|
.then((relationship) =>
|
|
|
|
|
store.commit('updateUserRelationship', [relationship]),
|
|
|
|
|
)
|
2022-08-20 13:18:57 -04:00
|
|
|
}
|
|
|
|
|
|
2022-04-30 11:08:19 -04:00
|
|
|
const muteUser = (store, args) => {
|
|
|
|
|
const id = typeof args === 'object' ? args.id : args
|
|
|
|
|
const expiresIn = typeof args === 'object' ? args.expiresIn : 0
|
|
|
|
|
|
2020-04-24 18:53:17 +03:00
|
|
|
const predictedRelationship = store.state.relationships[id] || { id }
|
|
|
|
|
store.commit('updateUserRelationship', [predictedRelationship])
|
|
|
|
|
store.commit('addMuteId', id)
|
|
|
|
|
|
2026-01-06 16:22:52 +02:00
|
|
|
return store.rootState.api.backendInteractor
|
|
|
|
|
.muteUser({ id, expiresIn })
|
2019-04-04 14:02:46 -04:00
|
|
|
.then((relationship) => {
|
|
|
|
|
store.commit('updateUserRelationship', [relationship])
|
|
|
|
|
store.commit('addMuteId', id)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const unmuteUser = (store, id) => {
|
2020-04-24 18:53:17 +03:00
|
|
|
const predictedRelationship = store.state.relationships[id] || { id }
|
|
|
|
|
predictedRelationship.muting = false
|
|
|
|
|
store.commit('updateUserRelationship', [predictedRelationship])
|
|
|
|
|
|
2026-01-06 16:22:52 +02:00
|
|
|
return store.rootState.api.backendInteractor
|
|
|
|
|
.unmuteUser({ id })
|
|
|
|
|
.then((relationship) =>
|
|
|
|
|
store.commit('updateUserRelationship', [relationship]),
|
|
|
|
|
)
|
2019-04-04 13:54:52 -04:00
|
|
|
}
|
|
|
|
|
|
2019-09-21 16:24:47 +03:00
|
|
|
const hideReblogs = (store, userId) => {
|
2026-01-06 16:22:52 +02:00
|
|
|
return store.rootState.api.backendInteractor
|
|
|
|
|
.followUser({ id: userId, reblogs: false })
|
2019-09-21 16:24:47 +03:00
|
|
|
.then((relationship) => {
|
|
|
|
|
store.commit('updateUserRelationship', [relationship])
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const showReblogs = (store, userId) => {
|
2026-01-06 16:22:52 +02:00
|
|
|
return store.rootState.api.backendInteractor
|
|
|
|
|
.followUser({ id: userId, reblogs: true })
|
|
|
|
|
.then((relationship) =>
|
|
|
|
|
store.commit('updateUserRelationship', [relationship]),
|
|
|
|
|
)
|
2019-09-21 16:24:47 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-15 20:22:54 +00:00
|
|
|
const muteDomain = (store, domain) => {
|
2026-01-06 16:22:52 +02:00
|
|
|
return store.rootState.api.backendInteractor
|
|
|
|
|
.muteDomain({ domain })
|
2020-01-15 20:22:54 +00:00
|
|
|
.then(() => store.commit('addDomainMute', domain))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const unmuteDomain = (store, domain) => {
|
2026-01-06 16:22:52 +02:00
|
|
|
return store.rootState.api.backendInteractor
|
|
|
|
|
.unmuteDomain({ domain })
|
2020-01-15 20:22:54 +00:00
|
|
|
.then(() => store.commit('removeDomainMute', domain))
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-30 18:29:44 +01:00
|
|
|
export const mutations = {
|
2026-01-06 16:22:52 +02:00
|
|
|
tagUser(state, { user: { id }, tag }) {
|
2019-02-18 17:49:32 +03:00
|
|
|
const user = state.usersObject[id]
|
|
|
|
|
const tags = user.tags || []
|
|
|
|
|
const newTags = tags.concat([tag])
|
2022-07-31 12:35:48 +03:00
|
|
|
user.tags = newTags
|
2019-02-18 17:49:32 +03:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
untagUser(state, { user: { id }, tag }) {
|
2019-02-18 17:49:32 +03:00
|
|
|
const user = state.usersObject[id]
|
|
|
|
|
const tags = user.tags || []
|
2026-01-06 16:22:52 +02:00
|
|
|
const newTags = tags.filter((t) => t !== tag)
|
2022-07-31 12:35:48 +03:00
|
|
|
user.tags = newTags
|
2019-02-18 17:49:32 +03:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
updateRight(state, { user: { id }, right, value }) {
|
2019-02-18 17:49:32 +03:00
|
|
|
const user = state.usersObject[id]
|
2022-07-31 12:35:48 +03:00
|
|
|
const newRights = user.rights
|
2019-02-18 17:49:32 +03:00
|
|
|
newRights[right] = value
|
2022-07-31 12:35:48 +03:00
|
|
|
user.rights = newRights
|
2019-02-18 17:49:32 +03:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
updateActivationStatus(state, { user: { id }, deactivated }) {
|
2019-02-18 17:49:32 +03:00
|
|
|
const user = state.usersObject[id]
|
2022-07-31 12:35:48 +03:00
|
|
|
user.deactivated = deactivated
|
2019-02-18 17:49:32 +03:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
setCurrentUser(state, user) {
|
2017-07-02 13:07:35 +02:00
|
|
|
state.lastLoginName = user.screen_name
|
2026-01-06 16:22:52 +02:00
|
|
|
state.currentUser = mergeWith(
|
|
|
|
|
state.currentUser || {},
|
|
|
|
|
user,
|
|
|
|
|
mergeArrayLength,
|
|
|
|
|
)
|
2016-10-27 18:03:14 +02:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
clearCurrentUser(state) {
|
2017-07-02 12:25:34 +02:00
|
|
|
state.currentUser = false
|
2017-07-02 13:07:35 +02:00
|
|
|
state.lastLoginName = false
|
2017-07-02 12:25:34 +02:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
beginLogin(state) {
|
2016-11-30 18:29:44 +01:00
|
|
|
state.loggingIn = true
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
endLogin(state) {
|
2016-11-30 18:29:44 +01:00
|
|
|
state.loggingIn = false
|
2016-10-27 18:03:14 +02:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
saveFriendIds(state, { id, friendIds }) {
|
2018-12-17 19:14:38 +03:00
|
|
|
const user = state.usersObject[id]
|
2020-11-17 15:25:38 +02:00
|
|
|
user.friendIds = uniq(concat(user.friendIds || [], friendIds))
|
2018-12-17 19:14:38 +03:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
saveFollowerIds(state, { id, followerIds }) {
|
2018-12-17 19:14:38 +03:00
|
|
|
const user = state.usersObject[id]
|
2020-11-17 15:25:38 +02:00
|
|
|
user.followerIds = uniq(concat(user.followerIds || [], followerIds))
|
2019-02-02 22:29:10 +02:00
|
|
|
},
|
|
|
|
|
// Because frontend doesn't have a reason to keep these stuff in memory
|
|
|
|
|
// outside of viewing someones user profile.
|
2026-01-06 16:22:52 +02:00
|
|
|
clearFriends(state, userId) {
|
2019-02-25 04:51:23 -05:00
|
|
|
const user = state.usersObject[userId]
|
2019-04-10 13:49:39 -04:00
|
|
|
if (user) {
|
2022-07-31 12:35:48 +03:00
|
|
|
user.friendIds = []
|
2019-02-02 22:29:10 +02:00
|
|
|
}
|
2019-02-25 04:51:23 -05:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
clearFollowers(state, userId) {
|
2019-02-25 04:51:23 -05:00
|
|
|
const user = state.usersObject[userId]
|
2019-04-10 13:49:39 -04:00
|
|
|
if (user) {
|
2022-07-31 12:35:48 +03:00
|
|
|
user.followerIds = []
|
2019-02-25 04:51:23 -05:00
|
|
|
}
|
2018-12-17 19:14:38 +03:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
addNewUsers(state, users) {
|
2020-04-21 23:27:51 +03:00
|
|
|
each(users, (user) => {
|
|
|
|
|
if (user.relationship) {
|
2021-04-25 13:24:08 +03:00
|
|
|
state.relationships[user.relationship.id] = user.relationship
|
2020-04-21 23:27:51 +03:00
|
|
|
}
|
2022-08-10 12:17:18 -04:00
|
|
|
const res = mergeOrAdd(state.users, state.usersObject, user)
|
|
|
|
|
const item = res.item
|
|
|
|
|
if (res.new && item.screen_name && !item.screen_name.includes('@')) {
|
|
|
|
|
state.usersByNameObject[item.screen_name.toLowerCase()] = item
|
|
|
|
|
}
|
2020-04-21 23:27:51 +03:00
|
|
|
})
|
2017-02-16 14:23:59 +01:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
updateUserRelationship(state, relationships) {
|
2019-03-08 00:35:30 +02:00
|
|
|
relationships.forEach((relationship) => {
|
2021-04-25 13:24:08 +03:00
|
|
|
state.relationships[relationship.id] = relationship
|
2019-03-08 00:35:30 +02:00
|
|
|
})
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
updateUserInLists(state, { id, inLists }) {
|
2022-08-15 23:19:33 +03:00
|
|
|
state.usersObject[id].inLists = inLists
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
saveBlockIds(state, blockIds) {
|
2019-02-13 22:24:09 -05:00
|
|
|
state.currentUser.blockIds = blockIds
|
2019-02-13 12:05:23 -05:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
addBlockId(state, blockId) {
|
2019-04-02 14:56:37 -04:00
|
|
|
if (state.currentUser.blockIds.indexOf(blockId) === -1) {
|
|
|
|
|
state.currentUser.blockIds.push(blockId)
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
setBlockIdsMaxId(state, blockIdsMaxId) {
|
2023-02-21 00:39:16 -05:00
|
|
|
state.currentUser.blockIdsMaxId = blockIdsMaxId
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
saveMuteIds(state, muteIds) {
|
2019-02-13 22:24:09 -05:00
|
|
|
state.currentUser.muteIds = muteIds
|
2019-02-13 22:04:28 -05:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
setMuteIdsMaxId(state, muteIdsMaxId) {
|
2023-02-21 00:39:16 -05:00
|
|
|
state.currentUser.muteIdsMaxId = muteIdsMaxId
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
addMuteId(state, muteId) {
|
2019-04-02 16:23:12 -04:00
|
|
|
if (state.currentUser.muteIds.indexOf(muteId) === -1) {
|
|
|
|
|
state.currentUser.muteIds.push(muteId)
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
saveDomainMutes(state, domainMutes) {
|
2020-01-15 20:22:54 +00:00
|
|
|
state.currentUser.domainMutes = domainMutes
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
addDomainMute(state, domain) {
|
2020-01-15 20:22:54 +00:00
|
|
|
if (state.currentUser.domainMutes.indexOf(domain) === -1) {
|
|
|
|
|
state.currentUser.domainMutes.push(domain)
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
removeDomainMute(state, domain) {
|
2020-01-15 20:22:54 +00:00
|
|
|
const index = state.currentUser.domainMutes.indexOf(domain)
|
|
|
|
|
if (index !== -1) {
|
|
|
|
|
state.currentUser.domainMutes.splice(index, 1)
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
setPinnedToUser(state, status) {
|
2019-04-30 08:20:19 -04:00
|
|
|
const user = state.usersObject[status.user.id]
|
2020-11-17 15:25:38 +02:00
|
|
|
user.pinnedStatusIds = user.pinnedStatusIds || []
|
2019-07-19 22:49:29 -04:00
|
|
|
const index = user.pinnedStatusIds.indexOf(status.id)
|
2020-11-17 15:25:38 +02:00
|
|
|
|
2019-04-30 08:20:19 -04:00
|
|
|
if (status.pinned && index === -1) {
|
2019-07-19 22:49:29 -04:00
|
|
|
user.pinnedStatusIds.push(status.id)
|
2019-04-30 08:20:19 -04:00
|
|
|
} else if (!status.pinned && index !== -1) {
|
2019-07-19 22:49:29 -04:00
|
|
|
user.pinnedStatusIds.splice(index, 1)
|
2019-04-30 08:20:19 -04:00
|
|
|
}
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
setUserForStatus(state, status) {
|
2017-03-08 18:04:21 +01:00
|
|
|
status.user = state.usersObject[status.user.id]
|
2018-06-18 11:36:58 +03:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
setUserForNotification(state, notification) {
|
2019-03-31 21:59:18 -04:00
|
|
|
if (notification.type !== 'follow') {
|
|
|
|
|
notification.action.user = state.usersObject[notification.action.user.id]
|
|
|
|
|
}
|
2019-03-31 14:50:34 -04:00
|
|
|
notification.from_profile = state.usersObject[notification.from_profile.id]
|
2018-12-26 09:19:25 +00:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
setColor(state, { user: { id }, highlighted }) {
|
2018-06-18 11:36:58 +03:00
|
|
|
const user = state.usersObject[id]
|
2022-07-31 12:35:48 +03:00
|
|
|
user.highlight = highlighted
|
2018-12-05 13:43:01 +04:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
signUpPending(state) {
|
2018-12-05 23:07:58 +04:00
|
|
|
state.signUpPending = true
|
|
|
|
|
state.signUpErrors = []
|
2023-07-25 10:46:27 -04:00
|
|
|
state.signUpNotice = {}
|
2018-12-05 13:43:01 +04:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
signUpSuccess(state) {
|
2018-12-05 23:07:58 +04:00
|
|
|
state.signUpPending = false
|
2018-12-05 13:43:01 +04:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
signUpFailure(state, errors) {
|
2018-12-05 23:07:58 +04:00
|
|
|
state.signUpPending = false
|
|
|
|
|
state.signUpErrors = errors
|
2023-07-25 10:46:27 -04:00
|
|
|
state.signUpNotice = {}
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
signUpNotice(state, notice) {
|
2023-07-25 10:46:27 -04:00
|
|
|
state.signUpPending = false
|
|
|
|
|
state.signUpErrors = []
|
|
|
|
|
state.signUpNotice = notice
|
2026-01-06 16:22:52 +02:00
|
|
|
},
|
2016-11-30 18:29:44 +01:00
|
|
|
}
|
|
|
|
|
|
2018-12-31 01:57:22 +00:00
|
|
|
export const getters = {
|
2026-01-06 16:22:52 +02:00
|
|
|
findUser: (state) => (query) => {
|
2022-08-10 12:17:18 -04:00
|
|
|
return state.usersObject[query]
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
findUserByName: (state) => (query) => {
|
2022-08-10 12:17:18 -04:00
|
|
|
return state.usersByNameObject[query.toLowerCase()]
|
2020-04-24 18:53:17 +03:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
findUserByUrl: (state) => (query) => {
|
|
|
|
|
return state.users.find(
|
|
|
|
|
(u) =>
|
|
|
|
|
u.statusnet_profile_url &&
|
|
|
|
|
u.statusnet_profile_url.toLowerCase() === query.toLowerCase(),
|
|
|
|
|
)
|
2021-06-07 16:16:10 +03:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
relationship: (state) => (id) => {
|
2020-04-27 10:06:17 +03:00
|
|
|
const rel = id && state.relationships[id]
|
|
|
|
|
return rel || { id, loading: true }
|
2026-01-06 16:22:52 +02:00
|
|
|
},
|
2018-12-31 01:57:22 +00:00
|
|
|
}
|
|
|
|
|
|
2016-11-30 18:29:44 +01:00
|
|
|
export const defaultState = {
|
2018-12-05 23:07:58 +04:00
|
|
|
loggingIn: false,
|
2017-07-02 13:07:35 +02:00
|
|
|
lastLoginName: false,
|
2016-11-30 18:29:44 +01:00
|
|
|
currentUser: false,
|
2017-03-08 17:59:12 +01:00
|
|
|
users: [],
|
2018-12-05 13:43:01 +04:00
|
|
|
usersObject: {},
|
2022-08-10 12:17:18 -04:00
|
|
|
usersByNameObject: {},
|
2018-12-05 23:07:58 +04:00
|
|
|
signUpPending: false,
|
2020-04-21 23:27:51 +03:00
|
|
|
signUpErrors: [],
|
2023-07-25 10:46:27 -04:00
|
|
|
signUpNotice: {},
|
2026-01-06 16:22:52 +02:00
|
|
|
relationships: {},
|
2016-11-30 18:29:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const users = {
|
|
|
|
|
state: defaultState,
|
|
|
|
|
mutations,
|
2018-12-31 01:57:22 +00:00
|
|
|
getters,
|
2016-10-27 18:03:14 +02:00
|
|
|
actions: {
|
2026-01-06 16:22:52 +02:00
|
|
|
fetchUserIfMissing(store, id) {
|
2020-07-07 14:39:43 +02:00
|
|
|
if (!store.getters.findUser(id)) {
|
|
|
|
|
store.dispatch('fetchUser', id)
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
fetchUser(store, id) {
|
|
|
|
|
return store.rootState.api.backendInteractor
|
|
|
|
|
.fetchUser({ id })
|
2019-03-12 22:10:22 +02:00
|
|
|
.then((user) => {
|
|
|
|
|
store.commit('addNewUsers', [user])
|
|
|
|
|
return user
|
|
|
|
|
})
|
2019-03-08 22:40:57 +02:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
fetchUserByName(store, name) {
|
|
|
|
|
return store.rootState.api.backendInteractor
|
|
|
|
|
.fetchUserByName({ name })
|
2022-08-09 22:11:55 -04:00
|
|
|
.then((user) => {
|
|
|
|
|
store.commit('addNewUsers', [user])
|
|
|
|
|
return user
|
|
|
|
|
})
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
fetchUserRelationship(store, id) {
|
2019-04-17 22:47:56 -04:00
|
|
|
if (store.state.currentUser) {
|
2026-01-06 16:22:52 +02:00
|
|
|
store.rootState.api.backendInteractor
|
|
|
|
|
.fetchUserRelationship({ id })
|
|
|
|
|
.then((relationships) =>
|
|
|
|
|
store.commit('updateUserRelationship', relationships),
|
|
|
|
|
)
|
2019-04-17 22:47:56 -04:00
|
|
|
}
|
2017-11-14 18:08:03 +02:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
fetchUserInLists(store, id) {
|
2022-08-15 23:19:33 +03:00
|
|
|
if (store.state.currentUser) {
|
2026-01-06 16:22:52 +02:00
|
|
|
store.rootState.api.backendInteractor
|
|
|
|
|
.fetchUserInLists({ id })
|
2022-08-15 23:19:33 +03:00
|
|
|
.then((inLists) => store.commit('updateUserInLists', { id, inLists }))
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
fetchBlocks(store, args) {
|
2023-02-21 00:39:16 -05:00
|
|
|
const { reset } = args || {}
|
|
|
|
|
|
|
|
|
|
const maxId = store.state.currentUser.blockIdsMaxId
|
2026-01-06 16:22:52 +02:00
|
|
|
return store.rootState.api.backendInteractor
|
|
|
|
|
.fetchBlocks({ maxId })
|
2019-02-13 12:05:23 -05:00
|
|
|
.then((blocks) => {
|
2023-02-21 00:39:16 -05:00
|
|
|
if (reset) {
|
|
|
|
|
store.commit('saveBlockIds', map(blocks, 'id'))
|
|
|
|
|
} else {
|
2026-01-06 16:22:52 +02:00
|
|
|
map(blocks, 'id').map((id) => store.commit('addBlockId', id))
|
2023-02-21 00:39:16 -05:00
|
|
|
}
|
|
|
|
|
if (blocks.length) {
|
|
|
|
|
store.commit('setBlockIdsMaxId', last(blocks).id)
|
|
|
|
|
}
|
2020-04-21 23:27:51 +03:00
|
|
|
store.commit('addNewUsers', blocks)
|
2019-02-13 12:05:23 -05:00
|
|
|
return blocks
|
|
|
|
|
})
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
blockUser(store, data) {
|
2025-06-12 20:04:39 +03:00
|
|
|
return blockUser(store, data)
|
2019-04-04 13:54:52 -04:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
unblockUser(store, data) {
|
2025-06-12 20:04:39 +03:00
|
|
|
return unblockUser(store, data)
|
2019-04-04 13:54:52 -04:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
removeUserFromFollowers(store, id) {
|
2022-09-15 22:02:58 -06:00
|
|
|
return removeUserFromFollowers(store, id)
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
blockUsers(store, data = []) {
|
|
|
|
|
return Promise.all(data.map((d) => blockUser(store, d)))
|
2019-02-13 15:31:20 -05:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
unblockUsers(store, data = []) {
|
|
|
|
|
return Promise.all(data.map((d) => unblockUser(store, d)))
|
2019-02-13 15:31:20 -05:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
editUserNote(store, args) {
|
2022-08-20 13:18:57 -04:00
|
|
|
return editUserNote(store, args)
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
fetchMutes(store, args) {
|
2023-02-21 00:39:16 -05:00
|
|
|
const { reset } = args || {}
|
|
|
|
|
|
|
|
|
|
const maxId = store.state.currentUser.muteIdsMaxId
|
2026-01-06 16:22:52 +02:00
|
|
|
return store.rootState.api.backendInteractor
|
|
|
|
|
.fetchMutes({ maxId })
|
2019-03-01 13:30:01 -05:00
|
|
|
.then((mutes) => {
|
2023-02-21 00:39:16 -05:00
|
|
|
if (reset) {
|
|
|
|
|
store.commit('saveMuteIds', map(mutes, 'id'))
|
|
|
|
|
} else {
|
2026-01-06 16:22:52 +02:00
|
|
|
map(mutes, 'id').map((id) => store.commit('addMuteId', id))
|
2023-02-21 00:39:16 -05:00
|
|
|
}
|
|
|
|
|
if (mutes.length) {
|
|
|
|
|
store.commit('setMuteIdsMaxId', last(mutes).id)
|
|
|
|
|
}
|
2020-04-21 23:27:51 +03:00
|
|
|
store.commit('addNewUsers', mutes)
|
2019-03-01 13:30:01 -05:00
|
|
|
return mutes
|
2019-02-13 22:04:28 -05:00
|
|
|
})
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
muteUser(store, data) {
|
2025-06-12 20:04:39 +03:00
|
|
|
return muteUser(store, data)
|
2019-02-13 22:04:28 -05:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
unmuteUser(store, id) {
|
2019-04-04 14:02:46 -04:00
|
|
|
return unmuteUser(store, id)
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
hideReblogs(store, id) {
|
2019-09-21 16:24:47 +03:00
|
|
|
return hideReblogs(store, id)
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
showReblogs(store, id) {
|
2019-09-21 16:24:47 +03:00
|
|
|
return showReblogs(store, id)
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
muteUsers(store, data = []) {
|
|
|
|
|
return Promise.all(data.map((d) => muteUser(store, d)))
|
2019-04-04 14:02:46 -04:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
unmuteUsers(store, ids = []) {
|
|
|
|
|
return Promise.all(ids.map((d) => unmuteUser(store, d)))
|
2019-02-13 22:04:28 -05:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
fetchDomainMutes(store) {
|
|
|
|
|
return store.rootState.api.backendInteractor
|
|
|
|
|
.fetchDomainMutes()
|
2020-01-15 20:22:54 +00:00
|
|
|
.then((domainMutes) => {
|
|
|
|
|
store.commit('saveDomainMutes', domainMutes)
|
|
|
|
|
return domainMutes
|
|
|
|
|
})
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
muteDomain(store, domain) {
|
2020-01-15 20:22:54 +00:00
|
|
|
return muteDomain(store, domain)
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
unmuteDomain(store, domain) {
|
2020-01-15 20:22:54 +00:00
|
|
|
return unmuteDomain(store, domain)
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
muteDomains(store, domains = []) {
|
|
|
|
|
return Promise.all(domains.map((domain) => muteDomain(store, domain)))
|
2020-01-15 20:22:54 +00:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
unmuteDomains(store, domain = []) {
|
|
|
|
|
return Promise.all(domain.map((domain) => unmuteDomain(store, domain)))
|
2020-01-15 20:22:54 +00:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
fetchFriends({ rootState, commit }, id) {
|
2019-04-10 13:49:39 -04:00
|
|
|
const user = rootState.users.usersObject[id]
|
|
|
|
|
const maxId = last(user.friendIds)
|
2026-01-06 16:22:52 +02:00
|
|
|
return rootState.api.backendInteractor
|
|
|
|
|
.fetchFriends({ id, maxId })
|
2019-04-10 13:49:39 -04:00
|
|
|
.then((friends) => {
|
|
|
|
|
commit('addNewUsers', friends)
|
|
|
|
|
commit('saveFriendIds', { id, friendIds: map(friends, 'id') })
|
|
|
|
|
return friends
|
|
|
|
|
})
|
2019-02-02 22:29:10 +02:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
fetchFollowers({ rootState, commit }, id) {
|
2019-04-10 13:49:39 -04:00
|
|
|
const user = rootState.users.usersObject[id]
|
|
|
|
|
const maxId = last(user.followerIds)
|
2026-01-06 16:22:52 +02:00
|
|
|
return rootState.api.backendInteractor
|
|
|
|
|
.fetchFollowers({ id, maxId })
|
2019-02-25 02:11:39 -05:00
|
|
|
.then((followers) => {
|
2019-04-10 13:49:39 -04:00
|
|
|
commit('addNewUsers', followers)
|
|
|
|
|
commit('saveFollowerIds', { id, followerIds: map(followers, 'id') })
|
2019-02-25 02:11:39 -05:00
|
|
|
return followers
|
|
|
|
|
})
|
2018-12-17 19:14:38 +03:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
clearFriends({ commit }, userId) {
|
2019-02-25 04:51:23 -05:00
|
|
|
commit('clearFriends', userId)
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
clearFollowers({ commit }, userId) {
|
2019-02-25 04:51:23 -05:00
|
|
|
commit('clearFollowers', userId)
|
2018-12-17 19:14:38 +03:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
subscribeUser({ rootState, commit }, id) {
|
|
|
|
|
return rootState.api.backendInteractor
|
|
|
|
|
.followUser({ id, notify: true })
|
|
|
|
|
.then((relationship) =>
|
|
|
|
|
commit('updateUserRelationship', [relationship]),
|
|
|
|
|
)
|
2019-04-25 04:30:08 -04:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
unsubscribeUser({ rootState, commit }, id) {
|
|
|
|
|
return rootState.api.backendInteractor
|
|
|
|
|
.followUser({ id, notify: false })
|
|
|
|
|
.then((relationship) =>
|
|
|
|
|
commit('updateUserRelationship', [relationship]),
|
|
|
|
|
)
|
2019-04-25 04:30:08 -04:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
toggleActivationStatus({ rootState, commit }, { user }) {
|
|
|
|
|
const api = user.deactivated
|
|
|
|
|
? rootState.api.backendInteractor.activateUser
|
|
|
|
|
: rootState.api.backendInteractor.deactivateUser
|
|
|
|
|
api({ user }).then((user) => {
|
|
|
|
|
const deactivated = !user.is_active
|
|
|
|
|
commit('updateActivationStatus', { user, deactivated })
|
|
|
|
|
})
|
2019-11-18 20:42:10 -05:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
registerPushNotifications(store) {
|
2018-12-10 22:36:25 +07:00
|
|
|
const token = store.state.currentUser.credentials
|
2026-01-29 00:49:26 +02:00
|
|
|
const vapidPublicKey = useInstanceStore().vapidPublicKey
|
2018-12-10 22:36:25 +07:00
|
|
|
const isEnabled = store.rootState.config.webPushNotifications
|
2026-01-06 16:22:52 +02:00
|
|
|
const notificationVisibility =
|
|
|
|
|
store.rootState.config.notificationVisibility
|
2018-12-10 22:36:25 +07:00
|
|
|
|
2026-01-06 16:22:52 +02:00
|
|
|
registerPushNotifications(
|
|
|
|
|
isEnabled,
|
|
|
|
|
vapidPublicKey,
|
|
|
|
|
token,
|
|
|
|
|
notificationVisibility,
|
|
|
|
|
)
|
2018-12-10 22:36:25 +07:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
unregisterPushNotifications(store) {
|
2018-12-25 03:46:19 +03:00
|
|
|
const token = store.state.currentUser.credentials
|
|
|
|
|
|
|
|
|
|
unregisterPushNotifications(token)
|
2018-12-20 09:17:59 +03:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
addNewUsers({ commit }, users) {
|
2019-04-02 13:49:48 -04:00
|
|
|
commit('addNewUsers', users)
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
addNewStatuses(store, { statuses }) {
|
2016-11-30 18:29:44 +01:00
|
|
|
const users = map(statuses, 'user')
|
2016-12-08 09:08:59 +01:00
|
|
|
const retweetedUsers = compact(map(statuses, 'retweeted_status.user'))
|
2016-11-30 18:29:44 +01:00
|
|
|
store.commit('addNewUsers', users)
|
2016-12-08 09:08:59 +01:00
|
|
|
store.commit('addNewUsers', retweetedUsers)
|
2017-02-14 00:01:50 +01:00
|
|
|
|
|
|
|
|
each(statuses, (status) => {
|
2019-04-30 08:20:19 -04:00
|
|
|
// Reconnect users to statuses
|
2017-02-16 14:23:59 +01:00
|
|
|
store.commit('setUserForStatus', status)
|
2019-04-30 08:20:19 -04:00
|
|
|
// Set pinned statuses to user
|
2019-08-30 15:55:28 -04:00
|
|
|
store.commit('setPinnedToUser', status)
|
2017-02-14 00:01:50 +01:00
|
|
|
})
|
|
|
|
|
each(compact(map(statuses, 'retweeted_status')), (status) => {
|
2019-04-30 08:20:19 -04:00
|
|
|
// Reconnect users to retweets
|
2017-02-16 14:23:59 +01:00
|
|
|
store.commit('setUserForStatus', status)
|
2019-04-30 08:20:19 -04:00
|
|
|
// Set pinned retweets to user
|
2019-08-30 15:55:28 -04:00
|
|
|
store.commit('setPinnedToUser', status)
|
2017-02-14 00:01:50 +01:00
|
|
|
})
|
2016-11-30 18:29:44 +01:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
addNewNotifications(store, { notifications }) {
|
2019-01-14 22:38:37 +03:00
|
|
|
const users = map(notifications, 'from_profile')
|
2026-01-06 16:22:52 +02:00
|
|
|
const targetUsers = map(notifications, 'target').filter((_) => _)
|
|
|
|
|
const notificationIds = notifications.map((_) => _.id)
|
2018-12-26 09:19:25 +00:00
|
|
|
store.commit('addNewUsers', users)
|
2019-12-11 18:48:18 +09:00
|
|
|
store.commit('addNewUsers', targetUsers)
|
2018-12-26 09:19:25 +00:00
|
|
|
|
2023-11-16 19:26:18 +02:00
|
|
|
const notificationsObject = store.rootState.notifications.idStore
|
2018-12-26 09:19:25 +00:00
|
|
|
const relevantNotifications = Object.entries(notificationsObject)
|
2025-02-04 15:23:21 +02:00
|
|
|
.filter(([k]) => notificationIds.includes(k))
|
|
|
|
|
.map(([, val]) => val)
|
2018-12-26 09:19:25 +00:00
|
|
|
|
|
|
|
|
// Reconnect users to notifications
|
|
|
|
|
each(relevantNotifications, (notification) => {
|
|
|
|
|
store.commit('setUserForNotification', notification)
|
|
|
|
|
})
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
searchUsers({ rootState, commit }, { query }) {
|
|
|
|
|
return rootState.api.backendInteractor
|
|
|
|
|
.searchUsers({ query })
|
2019-04-11 15:46:44 -04:00
|
|
|
.then((users) => {
|
2020-06-18 12:29:13 +03:00
|
|
|
commit('addNewUsers', users)
|
2019-04-11 15:46:44 -04:00
|
|
|
return users
|
|
|
|
|
})
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
async signUp(store, userInfo) {
|
2025-03-11 18:48:55 -04:00
|
|
|
const oauthStore = useOAuthStore()
|
2018-12-05 23:07:58 +04:00
|
|
|
store.commit('signUpPending')
|
2018-12-05 13:43:01 +04:00
|
|
|
|
2019-05-22 19:13:41 +03:00
|
|
|
try {
|
2025-03-11 18:48:55 -04:00
|
|
|
const token = await oauthStore.ensureAppToken()
|
2026-01-06 16:22:52 +02:00
|
|
|
const data = await apiService.register({
|
|
|
|
|
credentials: token,
|
|
|
|
|
params: { ...userInfo },
|
|
|
|
|
})
|
2023-07-25 10:46:27 -04:00
|
|
|
|
|
|
|
|
if (data.access_token) {
|
|
|
|
|
store.commit('signUpSuccess')
|
2025-03-11 18:48:55 -04:00
|
|
|
oauthStore.setToken(data.access_token)
|
2026-01-07 10:50:26 +04:00
|
|
|
await store.dispatch('loginUser', data.access_token)
|
2023-07-25 10:46:27 -04:00
|
|
|
return 'ok'
|
2026-01-06 16:22:52 +02:00
|
|
|
} else {
|
|
|
|
|
// Request succeeded, but user cannot login yet.
|
2023-07-25 10:46:27 -04:00
|
|
|
store.commit('signUpNotice', data)
|
|
|
|
|
return 'request_sent'
|
|
|
|
|
}
|
2019-05-22 19:13:41 +03:00
|
|
|
} catch (e) {
|
2022-07-31 12:35:48 +03:00
|
|
|
const errors = e.message
|
2018-12-05 23:07:58 +04:00
|
|
|
store.commit('signUpFailure', errors)
|
2019-08-06 18:03:31 +00:00
|
|
|
throw e
|
2018-12-05 13:43:01 +04:00
|
|
|
}
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
async getCaptcha(store) {
|
2019-07-07 00:54:17 +03:00
|
|
|
return store.rootState.api.backendInteractor.getCaptcha()
|
2018-12-16 20:53:41 +03:00
|
|
|
},
|
|
|
|
|
|
2026-01-06 16:22:52 +02:00
|
|
|
logout(store) {
|
2025-03-11 18:48:55 -04:00
|
|
|
const oauth = useOAuthStore()
|
|
|
|
|
const { instance } = store.rootState
|
2019-07-02 15:33:40 +07:00
|
|
|
|
2025-03-09 15:06:19 -04:00
|
|
|
// NOTE: No need to verify the app still exists, because if it doesn't,
|
|
|
|
|
// the token will be invalid too
|
2026-01-06 16:22:52 +02:00
|
|
|
return oauth
|
|
|
|
|
.ensureApp()
|
2019-07-02 15:33:40 +07:00
|
|
|
.then((app) => {
|
|
|
|
|
const params = {
|
|
|
|
|
app,
|
2025-03-11 18:48:55 -04:00
|
|
|
instance: instance.server,
|
2026-01-06 16:22:52 +02:00
|
|
|
token: oauth.userToken,
|
2019-07-02 15:33:40 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return oauthApi.revokeToken(params)
|
|
|
|
|
})
|
|
|
|
|
.then(() => {
|
|
|
|
|
store.commit('clearCurrentUser')
|
2019-08-17 08:18:42 +00:00
|
|
|
store.dispatch('disconnectFromSocket')
|
2025-03-11 18:48:55 -04:00
|
|
|
oauth.clearToken()
|
2019-12-08 16:05:41 +02:00
|
|
|
store.dispatch('stopFetchingTimeline', 'friends')
|
2026-01-06 16:22:52 +02:00
|
|
|
store.commit(
|
|
|
|
|
'setBackendInteractor',
|
|
|
|
|
backendInteractorService(oauth.getToken),
|
|
|
|
|
)
|
2019-12-08 16:05:41 +02:00
|
|
|
store.dispatch('stopFetchingNotifications')
|
2022-08-15 20:43:38 +03:00
|
|
|
store.dispatch('stopFetchingLists')
|
2024-09-23 23:10:32 +02:00
|
|
|
store.dispatch('stopFetchingBookmarkFolders')
|
2019-12-08 16:05:41 +02:00
|
|
|
store.dispatch('stopFetchingFollowRequests')
|
2019-07-02 15:33:40 +07:00
|
|
|
store.commit('clearNotifications')
|
|
|
|
|
store.commit('resetStatuses')
|
2020-05-07 16:10:53 +03:00
|
|
|
store.dispatch('resetChats')
|
2023-04-05 21:06:37 -06:00
|
|
|
useInterfaceStore().setLastTimeline('public-timeline')
|
|
|
|
|
useInterfaceStore().setLayoutWidth(windowWidth())
|
|
|
|
|
useInterfaceStore().setLayoutHeight(windowHeight())
|
2022-08-12 01:19:19 +03:00
|
|
|
store.commit('clearServerSideStorage')
|
2019-07-02 15:33:40 +07:00
|
|
|
})
|
2017-07-02 12:25:34 +02:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
loginUser(store, accessToken) {
|
2017-03-08 18:28:41 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const commit = store.commit
|
2023-03-13 00:09:47 +02:00
|
|
|
const dispatch = store.dispatch
|
2017-03-08 18:28:41 +01:00
|
|
|
commit('beginLogin')
|
2026-01-06 16:22:52 +02:00
|
|
|
store.rootState.api.backendInteractor
|
|
|
|
|
.verifyCredentials(accessToken)
|
2019-01-17 22:11:51 +03:00
|
|
|
.then((data) => {
|
|
|
|
|
if (!data.error) {
|
2019-01-17 23:01:38 +03:00
|
|
|
const user = data
|
2019-01-17 22:11:51 +03:00
|
|
|
// user.credentials = userCredentials
|
|
|
|
|
user.credentials = accessToken
|
2019-02-13 22:14:46 -05:00
|
|
|
user.blockIds = []
|
|
|
|
|
user.muteIds = []
|
2020-01-15 20:22:54 +00:00
|
|
|
user.domainMutes = []
|
2019-01-17 22:11:51 +03:00
|
|
|
commit('setCurrentUser', user)
|
2025-03-23 20:03:25 +02:00
|
|
|
|
|
|
|
|
useServerSideStorageStore().setServerSideStorage(user)
|
2019-01-17 22:11:51 +03:00
|
|
|
commit('addNewUsers', [user])
|
2016-11-30 21:27:25 +01:00
|
|
|
|
2023-03-13 00:09:47 +02:00
|
|
|
dispatch('fetchEmoji')
|
2019-10-01 20:14:14 +03:00
|
|
|
|
2026-01-06 16:22:52 +02:00
|
|
|
getNotificationPermission().then((permission) =>
|
|
|
|
|
useInterfaceStore().setNotificationPermission(permission),
|
|
|
|
|
)
|
2018-12-13 18:04:09 +07:00
|
|
|
|
2019-01-17 22:11:51 +03:00
|
|
|
// Set our new backend interactor
|
2026-01-06 16:22:52 +02:00
|
|
|
commit(
|
|
|
|
|
'setBackendInteractor',
|
|
|
|
|
backendInteractorService(accessToken),
|
|
|
|
|
)
|
2025-03-25 11:56:17 +02:00
|
|
|
|
|
|
|
|
// Do server-side storage migrations
|
|
|
|
|
|
2025-03-25 19:01:32 +02:00
|
|
|
// Debug snippet to clean up storage and reset migrations
|
|
|
|
|
/*
|
|
|
|
|
// Reset wordfilter
|
|
|
|
|
Object.keys(
|
|
|
|
|
useServerSideStorageStore().prefsStorage.simple.muteFilters
|
|
|
|
|
).forEach(key => {
|
|
|
|
|
useServerSideStorageStore().unsetPreference({ path: 'simple.muteFilters.' + key, value: null })
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Reset flag to 0 to re-run migrations
|
|
|
|
|
useServerSideStorageStore().setFlag({ flag: 'configMigration', value: 0 })
|
|
|
|
|
/**/
|
|
|
|
|
|
2026-01-06 16:22:52 +02:00
|
|
|
const { configMigration } =
|
|
|
|
|
useServerSideStorageStore().flagStorage
|
2025-03-26 15:50:38 +02:00
|
|
|
declarations
|
2026-01-06 16:22:52 +02:00
|
|
|
.filter((x) => {
|
|
|
|
|
return (
|
|
|
|
|
x.store === 'server-side' &&
|
2025-04-09 00:02:45 +03:00
|
|
|
x.migrationNum > 0 &&
|
|
|
|
|
x.migrationNum > configMigration
|
2026-01-06 16:22:52 +02:00
|
|
|
)
|
2025-03-26 15:50:38 +02:00
|
|
|
})
|
|
|
|
|
.toSorted((a, b) => a.configMigration - b.configMigration)
|
2026-01-06 16:22:52 +02:00
|
|
|
.forEach((value) => {
|
2025-03-26 15:50:38 +02:00
|
|
|
value.migration(useServerSideStorageStore(), store.rootState)
|
2026-01-06 16:22:52 +02:00
|
|
|
useServerSideStorageStore().setFlag({
|
|
|
|
|
flag: 'configMigration',
|
|
|
|
|
value: value.migrationNum,
|
|
|
|
|
})
|
2025-03-26 15:50:38 +02:00
|
|
|
useServerSideStorageStore().pushServerSideStorage()
|
2025-03-25 11:56:17 +02:00
|
|
|
})
|
2016-11-30 21:27:25 +01:00
|
|
|
|
2019-01-17 22:11:51 +03:00
|
|
|
if (user.token) {
|
2023-03-13 00:09:47 +02:00
|
|
|
dispatch('setWsToken', user.token)
|
2019-03-10 11:23:27 -07:00
|
|
|
|
2020-08-03 18:44:35 -05:00
|
|
|
// Initialize the shout socket.
|
2023-03-13 00:09:47 +02:00
|
|
|
dispatch('initializeSocket')
|
2019-01-17 22:11:51 +03:00
|
|
|
}
|
2017-12-04 19:08:33 +01:00
|
|
|
|
2019-12-10 21:30:27 +02:00
|
|
|
const startPolling = () => {
|
2019-11-24 18:50:28 +02:00
|
|
|
// Start getting fresh posts.
|
2023-03-13 00:09:47 +02:00
|
|
|
dispatch('startFetchingTimeline', { timeline: 'friends' })
|
2019-11-24 18:50:28 +02:00
|
|
|
|
|
|
|
|
// Start fetching notifications
|
2023-03-13 00:09:47 +02:00
|
|
|
dispatch('startFetchingNotifications')
|
2020-05-07 16:10:53 +03:00
|
|
|
|
2026-01-29 00:49:26 +02:00
|
|
|
if (useInstanceStore().pleromaChatMessagesAvailable) {
|
2025-06-16 14:57:34 +03:00
|
|
|
// Start fetching chats
|
|
|
|
|
dispatch('startFetchingChats')
|
|
|
|
|
}
|
2019-12-10 21:30:27 +02:00
|
|
|
}
|
2017-02-16 11:17:47 +01:00
|
|
|
|
2023-03-13 00:09:47 +02:00
|
|
|
dispatch('startFetchingLists')
|
2024-09-23 23:10:32 +02:00
|
|
|
dispatch('startFetchingBookmarkFolders')
|
2022-08-15 20:43:38 +03:00
|
|
|
|
|
|
|
|
if (user.locked) {
|
2023-03-13 00:09:47 +02:00
|
|
|
dispatch('startFetchingFollowRequests')
|
2022-08-15 20:43:38 +03:00
|
|
|
}
|
|
|
|
|
|
2019-12-10 21:30:27 +02:00
|
|
|
if (store.getters.mergedConfig.useStreamingApi) {
|
2023-03-13 00:09:47 +02:00
|
|
|
dispatch('fetchTimeline', { timeline: 'friends', since: null })
|
|
|
|
|
dispatch('fetchNotifications', { since: null })
|
2026-01-06 16:22:52 +02:00
|
|
|
dispatch('enableMastoSockets', true)
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.error(
|
|
|
|
|
'Failed initializing MastoAPI Streaming socket',
|
|
|
|
|
error,
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
.then(() => {
|
|
|
|
|
dispatch('fetchChats', { latest: true })
|
|
|
|
|
setTimeout(
|
|
|
|
|
() => dispatch('setNotificationsSilence', false),
|
|
|
|
|
10000,
|
|
|
|
|
)
|
|
|
|
|
})
|
2019-12-10 21:30:27 +02:00
|
|
|
} else {
|
|
|
|
|
startPolling()
|
|
|
|
|
}
|
2017-02-16 11:17:47 +01:00
|
|
|
|
2019-02-13 22:14:46 -05:00
|
|
|
// Get user mutes
|
2023-03-13 00:09:47 +02:00
|
|
|
dispatch('fetchMutes')
|
2017-02-20 18:01:45 +01:00
|
|
|
|
2023-04-05 21:06:37 -06:00
|
|
|
useInterfaceStore().setLayoutWidth(windowWidth())
|
|
|
|
|
useInterfaceStore().setLayoutHeight(windowHeight())
|
2022-05-16 23:40:51 +03:00
|
|
|
|
2019-01-17 22:11:51 +03:00
|
|
|
// Fetch our friends
|
2026-01-06 16:22:52 +02:00
|
|
|
store.rootState.api.backendInteractor
|
|
|
|
|
.fetchFriends({ id: user.id })
|
2019-01-17 22:11:51 +03:00
|
|
|
.then((friends) => commit('addNewUsers', friends))
|
2017-03-08 18:28:41 +01:00
|
|
|
} else {
|
2019-01-17 22:11:51 +03:00
|
|
|
const response = data.error
|
2017-03-08 18:28:41 +01:00
|
|
|
// Authentication failed
|
|
|
|
|
commit('endLogin')
|
2023-08-14 16:21:43 +03:00
|
|
|
|
|
|
|
|
// remove authentication token on client/authentication errors
|
|
|
|
|
if ([400, 401, 403, 422].includes(response.status)) {
|
2025-03-11 18:48:55 -04:00
|
|
|
useOAuthStore().clearToken()
|
2023-08-14 16:21:43 +03:00
|
|
|
}
|
|
|
|
|
|
2017-03-08 19:22:56 +01:00
|
|
|
if (response.status === 401) {
|
2019-07-07 00:54:17 +03:00
|
|
|
reject(new Error('Wrong username or password'))
|
2017-03-08 19:22:56 +01:00
|
|
|
} else {
|
2019-07-07 00:54:17 +03:00
|
|
|
reject(new Error('An error occurred, please try again'))
|
2017-03-08 19:22:56 +01:00
|
|
|
}
|
2017-03-08 18:28:41 +01:00
|
|
|
}
|
|
|
|
|
commit('endLogin')
|
|
|
|
|
resolve()
|
|
|
|
|
})
|
2019-07-05 10:02:14 +03:00
|
|
|
.catch((error) => {
|
2023-12-14 00:14:06 +02:00
|
|
|
console.error(error)
|
2019-07-05 10:02:14 +03:00
|
|
|
commit('endLogin')
|
2019-07-07 00:54:17 +03:00
|
|
|
reject(new Error('Failed to connect to server, try again'))
|
2019-07-05 10:02:14 +03:00
|
|
|
})
|
2017-03-08 18:28:41 +01:00
|
|
|
})
|
2026-01-06 16:22:52 +02:00
|
|
|
},
|
|
|
|
|
},
|
2016-10-27 18:03:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default users
|