biome format --write
This commit is contained in:
parent
8372348148
commit
9262e803ec
415 changed files with 54076 additions and 17419 deletions
|
|
@ -10,7 +10,7 @@ import {
|
|||
first,
|
||||
last,
|
||||
isArray,
|
||||
omitBy
|
||||
omitBy,
|
||||
} from 'lodash'
|
||||
import apiService from '../services/api/api.service.js'
|
||||
import { useInterfaceStore } from 'src/stores/interface'
|
||||
|
|
@ -29,7 +29,7 @@ const emptyTl = (userId = 0) => ({
|
|||
followers: [],
|
||||
friends: [],
|
||||
userId,
|
||||
flushMarker: 0
|
||||
flushMarker: 0,
|
||||
})
|
||||
|
||||
export const defaultState = () => ({
|
||||
|
|
@ -52,8 +52,8 @@ export const defaultState = () => ({
|
|||
dms: emptyTl(),
|
||||
bookmarks: emptyTl(),
|
||||
list: emptyTl(),
|
||||
bubble: emptyTl()
|
||||
}
|
||||
bubble: emptyTl(),
|
||||
},
|
||||
})
|
||||
|
||||
export const prepareStatus = (status) => {
|
||||
|
|
@ -73,7 +73,10 @@ const mergeOrAdd = (arr, obj, item) => {
|
|||
// We already have this, so only merge the new info.
|
||||
// We ignore null values to avoid overwriting existing properties with missing data
|
||||
// we also skip 'user' because that is handled by users module
|
||||
merge(oldItem, omitBy(item, (v, k) => v === null || k === 'user'))
|
||||
merge(
|
||||
oldItem,
|
||||
omitBy(item, (v, k) => v === null || k === 'user'),
|
||||
)
|
||||
// Reactivity fix.
|
||||
oldItem.attachments.splice(oldItem.attachments.length)
|
||||
return { item: oldItem, new: false }
|
||||
|
|
@ -116,26 +119,32 @@ const getLatestScrobble = (state, user) => {
|
|||
return
|
||||
}
|
||||
|
||||
if (state.scrobblesNextFetch[user.id] && state.scrobblesNextFetch[user.id] > Date.now()) {
|
||||
if (
|
||||
state.scrobblesNextFetch[user.id] &&
|
||||
state.scrobblesNextFetch[user.id] > Date.now()
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
state.scrobblesNextFetch[user.id] = Date.now() + 24 * 60 * 60 * 1000
|
||||
if (!scrobblesSupport) return
|
||||
apiService.fetchScrobbles({ accountId: user.id }).then((scrobbles) => {
|
||||
if (scrobbles?.error) {
|
||||
state.pleromaScrobblesAvailable = false
|
||||
return
|
||||
}
|
||||
apiService
|
||||
.fetchScrobbles({ accountId: user.id })
|
||||
.then((scrobbles) => {
|
||||
if (scrobbles?.error) {
|
||||
state.pleromaScrobblesAvailable = false
|
||||
return
|
||||
}
|
||||
|
||||
if (scrobbles.length > 0) {
|
||||
user.latestScrobble = scrobbles[0]
|
||||
if (scrobbles.length > 0) {
|
||||
user.latestScrobble = scrobbles[0]
|
||||
|
||||
state.scrobblesNextFetch[user.id] = Date.now() + 60 * 1000
|
||||
}
|
||||
}).catch(e => {
|
||||
console.warn('cannot fetch scrobbles', e)
|
||||
})
|
||||
state.scrobblesNextFetch[user.id] = Date.now() + 60 * 1000
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
console.warn('cannot fetch scrobbles', e)
|
||||
})
|
||||
}
|
||||
|
||||
// Add status to the global storages (arrays and objects maintaining statuses) except timelines
|
||||
|
|
@ -156,7 +165,18 @@ const addStatusToGlobalStorage = (state, data) => {
|
|||
return result
|
||||
}
|
||||
|
||||
const addNewStatuses = (state, { statuses, showImmediately = false, timeline, user = {}, noIdUpdate = false, userId, pagination = {} }) => {
|
||||
const addNewStatuses = (
|
||||
state,
|
||||
{
|
||||
statuses,
|
||||
showImmediately = false,
|
||||
timeline,
|
||||
user = {},
|
||||
noIdUpdate = false,
|
||||
userId,
|
||||
pagination = {},
|
||||
},
|
||||
) => {
|
||||
// Sanity check
|
||||
if (!isArray(statuses)) {
|
||||
return false
|
||||
|
|
@ -169,11 +189,19 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
|||
// pagination.maxId is the oldest of the returned statuses when fetching older,
|
||||
// and pagination.minId is the newest when fetching newer. The names come directly
|
||||
// from the arguments they're supposed to be passed as for the next fetch.
|
||||
const minNew = pagination.maxId || (statuses.length > 0 ? minBy(statuses, 'id').id : 0)
|
||||
const maxNew = pagination.minId || (statuses.length > 0 ? maxBy(statuses, 'id').id : 0)
|
||||
const minNew =
|
||||
pagination.maxId || (statuses.length > 0 ? minBy(statuses, 'id').id : 0)
|
||||
const maxNew =
|
||||
pagination.minId || (statuses.length > 0 ? maxBy(statuses, 'id').id : 0)
|
||||
|
||||
const newer = timeline && (maxNew > timelineObject.maxId || timelineObject.maxId === 0) && statuses.length > 0
|
||||
const older = timeline && (minNew < timelineObject.minId || timelineObject.minId === 0) && statuses.length > 0
|
||||
const newer =
|
||||
timeline &&
|
||||
(maxNew > timelineObject.maxId || timelineObject.maxId === 0) &&
|
||||
statuses.length > 0
|
||||
const older =
|
||||
timeline &&
|
||||
(minNew < timelineObject.minId || timelineObject.minId === 0) &&
|
||||
statuses.length > 0
|
||||
|
||||
if (!noIdUpdate && newer) {
|
||||
timelineObject.maxId = maxNew
|
||||
|
|
@ -185,7 +213,10 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
|||
// 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' || timeline === 'media') && timelineObject.userId !== userId) {
|
||||
if (
|
||||
(timeline === 'user' || timeline === 'media') &&
|
||||
timelineObject.userId !== userId
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -195,7 +226,10 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
|||
|
||||
if (result.new) {
|
||||
// We are mentioned in a post
|
||||
if (status.type === 'status' && find(status.attentions, { id: user.id })) {
|
||||
if (
|
||||
status.type === 'status' &&
|
||||
find(status.attentions, { id: user.id })
|
||||
) {
|
||||
const mentions = state.timelines.mentions
|
||||
|
||||
// Add the mention to the mentions timeline
|
||||
|
|
@ -220,20 +254,32 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
|||
let resultForCurrentTimeline
|
||||
// Some statuses should only be added to the global status repository.
|
||||
if (timeline && addToTimeline) {
|
||||
resultForCurrentTimeline = mergeOrAdd(timelineObject.statuses, timelineObject.statusesObject, status)
|
||||
resultForCurrentTimeline = mergeOrAdd(
|
||||
timelineObject.statuses,
|
||||
timelineObject.statusesObject,
|
||||
status,
|
||||
)
|
||||
}
|
||||
|
||||
if (timeline && showImmediately) {
|
||||
// Add it directly to the visibleStatuses, don't change
|
||||
// newStatusCount
|
||||
mergeOrAdd(timelineObject.visibleStatuses, timelineObject.visibleStatusesObject, status)
|
||||
mergeOrAdd(
|
||||
timelineObject.visibleStatuses,
|
||||
timelineObject.visibleStatusesObject,
|
||||
status,
|
||||
)
|
||||
} else if (timeline && addToTimeline && resultForCurrentTimeline.new) {
|
||||
// Just change newStatuscount
|
||||
timelineObject.newStatusCount += 1
|
||||
}
|
||||
|
||||
if (status.quote) {
|
||||
addStatus(status.quote, /* showImmediately = */ false, /* addToTimeline = */ false)
|
||||
addStatus(
|
||||
status.quote,
|
||||
/* showImmediately = */ false,
|
||||
/* addToTimeline = */ false,
|
||||
)
|
||||
}
|
||||
|
||||
return status
|
||||
|
|
@ -266,13 +312,19 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
|||
let retweet
|
||||
// If the retweeted status is already there, don't add the retweet
|
||||
// to the timeline.
|
||||
if (timeline && find(timelineObject.statuses, (s) => {
|
||||
if (s.retweeted_status) {
|
||||
return s.id === retweetedStatus.id || s.retweeted_status.id === retweetedStatus.id
|
||||
} else {
|
||||
return s.id === retweetedStatus.id
|
||||
}
|
||||
})) {
|
||||
if (
|
||||
timeline &&
|
||||
find(timelineObject.statuses, (s) => {
|
||||
if (s.retweeted_status) {
|
||||
return (
|
||||
s.id === retweetedStatus.id ||
|
||||
s.retweeted_status.id === retweetedStatus.id
|
||||
)
|
||||
} else {
|
||||
return s.id === retweetedStatus.id
|
||||
}
|
||||
})
|
||||
) {
|
||||
// Already have it visible (either as the original or another RT), don't add to timeline, don't show.
|
||||
retweet = addStatus(status, false, false)
|
||||
} else {
|
||||
|
|
@ -295,7 +347,7 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
|||
default: (unknown) => {
|
||||
console.warn('unknown status type')
|
||||
console.warn(unknown)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
each(statuses, (status) => {
|
||||
|
|
@ -315,35 +367,41 @@ const removeStatus = (state, { timeline, userId }) => {
|
|||
if (userId) {
|
||||
remove(timelineObject.statuses, { user: { id: userId } })
|
||||
remove(timelineObject.visibleStatuses, { user: { id: userId } })
|
||||
timelineObject.minVisibleId = timelineObject.visibleStatuses.length > 0 ? last(timelineObject.visibleStatuses).id : 0
|
||||
timelineObject.maxId = timelineObject.statuses.length > 0 ? first(timelineObject.statuses).id : 0
|
||||
timelineObject.minVisibleId =
|
||||
timelineObject.visibleStatuses.length > 0
|
||||
? last(timelineObject.visibleStatuses).id
|
||||
: 0
|
||||
timelineObject.maxId =
|
||||
timelineObject.statuses.length > 0 ? first(timelineObject.statuses).id : 0
|
||||
}
|
||||
}
|
||||
|
||||
export const mutations = {
|
||||
addNewStatuses,
|
||||
removeStatus,
|
||||
showNewStatuses (state, { timeline }) {
|
||||
const oldTimeline = (state.timelines[timeline])
|
||||
showNewStatuses(state, { timeline }) {
|
||||
const oldTimeline = state.timelines[timeline]
|
||||
|
||||
oldTimeline.newStatusCount = 0
|
||||
oldTimeline.visibleStatuses = slice(oldTimeline.statuses, 0, 50)
|
||||
oldTimeline.minVisibleId = last(oldTimeline.visibleStatuses).id
|
||||
oldTimeline.minId = oldTimeline.minVisibleId
|
||||
oldTimeline.visibleStatusesObject = {}
|
||||
each(oldTimeline.visibleStatuses, (status) => { oldTimeline.visibleStatusesObject[status.id] = status })
|
||||
each(oldTimeline.visibleStatuses, (status) => {
|
||||
oldTimeline.visibleStatusesObject[status.id] = status
|
||||
})
|
||||
},
|
||||
resetStatuses (state) {
|
||||
resetStatuses(state) {
|
||||
const emptyState = defaultState()
|
||||
Object.entries(emptyState).forEach(([key, value]) => {
|
||||
state[key] = value
|
||||
})
|
||||
},
|
||||
clearTimeline (state, { timeline, excludeUserId = false }) {
|
||||
clearTimeline(state, { timeline, excludeUserId = false }) {
|
||||
const userId = excludeUserId ? state.timelines[timeline].userId : undefined
|
||||
state.timelines[timeline] = emptyTl(userId)
|
||||
},
|
||||
setFavorited (state, { status, value }) {
|
||||
setFavorited(state, { status, value }) {
|
||||
const newStatus = state.allStatusesObject[status.id]
|
||||
|
||||
if (newStatus.favorited !== value) {
|
||||
|
|
@ -356,7 +414,7 @@ export const mutations = {
|
|||
|
||||
newStatus.favorited = value
|
||||
},
|
||||
setFavoritedConfirm (state, { status, user }) {
|
||||
setFavoritedConfirm(state, { status, user }) {
|
||||
const newStatus = state.allStatusesObject[status.id]
|
||||
newStatus.favorited = status.favorited
|
||||
newStatus.fave_num = status.fave_num
|
||||
|
|
@ -367,15 +425,19 @@ export const mutations = {
|
|||
newStatus.favoritedBy.push(user)
|
||||
}
|
||||
},
|
||||
setMutedStatus (state, status) {
|
||||
setMutedStatus(state, status) {
|
||||
const newStatus = state.allStatusesObject[status.id]
|
||||
newStatus.thread_muted = status.thread_muted
|
||||
|
||||
if (newStatus.thread_muted !== undefined) {
|
||||
state.conversationsObject[newStatus.statusnet_conversation_id].forEach(status => { status.thread_muted = newStatus.thread_muted })
|
||||
state.conversationsObject[newStatus.statusnet_conversation_id].forEach(
|
||||
(status) => {
|
||||
status.thread_muted = newStatus.thread_muted
|
||||
},
|
||||
)
|
||||
}
|
||||
},
|
||||
setRetweeted (state, { status, value }) {
|
||||
setRetweeted(state, { status, value }) {
|
||||
const newStatus = state.allStatusesObject[status.id]
|
||||
|
||||
if (newStatus.repeated !== value) {
|
||||
|
|
@ -388,7 +450,7 @@ export const mutations = {
|
|||
|
||||
newStatus.repeated = value
|
||||
},
|
||||
setRetweetedConfirm (state, { status, user }) {
|
||||
setRetweetedConfirm(state, { status, user }) {
|
||||
const newStatus = state.allStatusesObject[status.id]
|
||||
newStatus.repeated = status.repeated
|
||||
newStatus.repeat_num = status.repeat_num
|
||||
|
|
@ -399,73 +461,79 @@ export const mutations = {
|
|||
newStatus.rebloggedBy.push(user)
|
||||
}
|
||||
},
|
||||
setBookmarked (state, { status, value }) {
|
||||
setBookmarked(state, { status, value }) {
|
||||
const newStatus = state.allStatusesObject[status.id]
|
||||
newStatus.bookmarked = value
|
||||
newStatus.bookmark_folder_id = status.bookmark_folder_id
|
||||
},
|
||||
setBookmarkedConfirm (state, { status }) {
|
||||
setBookmarkedConfirm(state, { status }) {
|
||||
const newStatus = state.allStatusesObject[status.id]
|
||||
newStatus.bookmarked = status.bookmarked
|
||||
if (status.pleroma) newStatus.bookmark_folder_id = status.pleroma.bookmark_folder
|
||||
if (status.pleroma)
|
||||
newStatus.bookmark_folder_id = status.pleroma.bookmark_folder
|
||||
},
|
||||
setDeleted (state, { status }) {
|
||||
setDeleted(state, { status }) {
|
||||
const newStatus = state.allStatusesObject[status.id]
|
||||
if (newStatus) newStatus.deleted = true
|
||||
},
|
||||
setManyDeleted (state, condition) {
|
||||
Object.values(state.allStatusesObject).forEach(status => {
|
||||
setManyDeleted(state, condition) {
|
||||
Object.values(state.allStatusesObject).forEach((status) => {
|
||||
if (condition(status)) {
|
||||
status.deleted = true
|
||||
}
|
||||
})
|
||||
},
|
||||
setLoading (state, { timeline, value }) {
|
||||
setLoading(state, { timeline, value }) {
|
||||
state.timelines[timeline].loading = value
|
||||
},
|
||||
setNsfw (state, { id, nsfw }) {
|
||||
setNsfw(state, { id, nsfw }) {
|
||||
const newStatus = state.allStatusesObject[id]
|
||||
newStatus.nsfw = nsfw
|
||||
},
|
||||
queueFlush (state, { timeline, id }) {
|
||||
queueFlush(state, { timeline, id }) {
|
||||
state.timelines[timeline].flushMarker = id
|
||||
},
|
||||
queueFlushAll (state) {
|
||||
queueFlushAll(state) {
|
||||
Object.keys(state.timelines).forEach((timeline) => {
|
||||
state.timelines[timeline].flushMarker = state.timelines[timeline].maxId
|
||||
})
|
||||
},
|
||||
addRepeats (state, { id, rebloggedByUsers, currentUser }) {
|
||||
addRepeats(state, { id, rebloggedByUsers, currentUser }) {
|
||||
const newStatus = state.allStatusesObject[id]
|
||||
newStatus.rebloggedBy = rebloggedByUsers.filter(_ => _)
|
||||
newStatus.rebloggedBy = rebloggedByUsers.filter((_) => _)
|
||||
// repeats stats can be incorrect based on polling condition, let's update them using the most recent data
|
||||
newStatus.repeat_num = newStatus.rebloggedBy.length
|
||||
newStatus.repeated = !!newStatus.rebloggedBy.find(({ id }) => currentUser.id === id)
|
||||
newStatus.repeated = !!newStatus.rebloggedBy.find(
|
||||
({ id }) => currentUser.id === id,
|
||||
)
|
||||
},
|
||||
addFavs (state, { id, favoritedByUsers, currentUser }) {
|
||||
addFavs(state, { id, favoritedByUsers, currentUser }) {
|
||||
const newStatus = state.allStatusesObject[id]
|
||||
newStatus.favoritedBy = favoritedByUsers.filter(_ => _)
|
||||
newStatus.favoritedBy = favoritedByUsers.filter((_) => _)
|
||||
// favorites stats can be incorrect based on polling condition, let's update them using the most recent data
|
||||
newStatus.fave_num = newStatus.favoritedBy.length
|
||||
newStatus.favorited = !!newStatus.favoritedBy.find(({ id }) => currentUser.id === id)
|
||||
newStatus.favorited = !!newStatus.favoritedBy.find(
|
||||
({ id }) => currentUser.id === id,
|
||||
)
|
||||
},
|
||||
addEmojiReactionsBy (state, { id, emojiReactions }) {
|
||||
addEmojiReactionsBy(state, { id, emojiReactions }) {
|
||||
const status = state.allStatusesObject[id]
|
||||
status.emoji_reactions = emojiReactions
|
||||
},
|
||||
addOwnReaction (state, { id, emoji, currentUser }) {
|
||||
addOwnReaction(state, { id, emoji, currentUser }) {
|
||||
const status = state.allStatusesObject[id]
|
||||
const reactionIndex = findIndex(status.emoji_reactions, { name: emoji })
|
||||
const reaction = status.emoji_reactions[reactionIndex] || { name: emoji, count: 0, accounts: [] }
|
||||
const reaction = status.emoji_reactions[reactionIndex] || {
|
||||
name: emoji,
|
||||
count: 0,
|
||||
accounts: [],
|
||||
}
|
||||
|
||||
const newReaction = {
|
||||
...reaction,
|
||||
count: reaction.count + 1,
|
||||
me: true,
|
||||
accounts: [
|
||||
...reaction.accounts,
|
||||
currentUser
|
||||
]
|
||||
accounts: [...reaction.accounts, currentUser],
|
||||
}
|
||||
|
||||
// Update count of existing reaction if it exists, otherwise append at the end
|
||||
|
|
@ -475,7 +543,7 @@ export const mutations = {
|
|||
status.emoji_reactions = [...status.emoji_reactions, newReaction]
|
||||
}
|
||||
},
|
||||
removeOwnReaction (state, { id, emoji, currentUser }) {
|
||||
removeOwnReaction(state, { id, emoji, currentUser }) {
|
||||
const status = state.allStatusesObject[id]
|
||||
const reactionIndex = findIndex(status.emoji_reactions, { name: emoji })
|
||||
if (reactionIndex < 0) return
|
||||
|
|
@ -487,42 +555,70 @@ export const mutations = {
|
|||
...reaction,
|
||||
count: reaction.count - 1,
|
||||
me: false,
|
||||
accounts: accounts.filter(acc => acc.id !== currentUser.id)
|
||||
accounts: accounts.filter((acc) => acc.id !== currentUser.id),
|
||||
}
|
||||
|
||||
if (newReaction.count > 0) {
|
||||
status.emoji_reactions[reactionIndex] = newReaction
|
||||
} else {
|
||||
status.emoji_reactions = status.emoji_reactions.filter(r => r.name !== emoji)
|
||||
status.emoji_reactions = status.emoji_reactions.filter(
|
||||
(r) => r.name !== emoji,
|
||||
)
|
||||
}
|
||||
},
|
||||
updateStatusWithPoll (state, { id, poll }) {
|
||||
updateStatusWithPoll(state, { id, poll }) {
|
||||
const status = state.allStatusesObject[id]
|
||||
status.poll = poll
|
||||
},
|
||||
setVirtualHeight (state, { statusId, height }) {
|
||||
setVirtualHeight(state, { statusId, height }) {
|
||||
state.allStatusesObject[statusId].virtualHeight = height
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
const statuses = {
|
||||
state: defaultState(),
|
||||
actions: {
|
||||
addNewStatuses ({ rootState, commit }, { statuses, showImmediately = false, timeline = false, noIdUpdate = false, userId, pagination }) {
|
||||
commit('addNewStatuses', { statuses, showImmediately, timeline, noIdUpdate, user: rootState.users.currentUser, userId, pagination })
|
||||
addNewStatuses(
|
||||
{ rootState, commit },
|
||||
{
|
||||
statuses,
|
||||
showImmediately = false,
|
||||
timeline = false,
|
||||
noIdUpdate = false,
|
||||
userId,
|
||||
pagination,
|
||||
},
|
||||
) {
|
||||
commit('addNewStatuses', {
|
||||
statuses,
|
||||
showImmediately,
|
||||
timeline,
|
||||
noIdUpdate,
|
||||
user: rootState.users.currentUser,
|
||||
userId,
|
||||
pagination,
|
||||
})
|
||||
},
|
||||
fetchStatus ({ rootState, dispatch }, id) {
|
||||
return rootState.api.backendInteractor.fetchStatus({ id })
|
||||
fetchStatus({ rootState, dispatch }, id) {
|
||||
return rootState.api.backendInteractor
|
||||
.fetchStatus({ id })
|
||||
.then((status) => dispatch('addNewStatuses', { statuses: [status] }))
|
||||
},
|
||||
fetchStatusSource ({ rootState }, status) {
|
||||
return apiService.fetchStatusSource({ id: status.id, credentials: rootState.users.currentUser.credentials })
|
||||
fetchStatusSource({ rootState }, status) {
|
||||
return apiService.fetchStatusSource({
|
||||
id: status.id,
|
||||
credentials: rootState.users.currentUser.credentials,
|
||||
})
|
||||
},
|
||||
fetchStatusHistory (_, status) {
|
||||
fetchStatusHistory(_, status) {
|
||||
return apiService.fetchStatusHistory({ status })
|
||||
},
|
||||
deleteStatus ({ rootState, commit }, status) {
|
||||
apiService.deleteStatus({ id: status.id, credentials: rootState.users.currentUser.credentials })
|
||||
deleteStatus({ rootState, commit }, status) {
|
||||
apiService
|
||||
.deleteStatus({
|
||||
id: status.id,
|
||||
credentials: rootState.users.currentUser.credentials,
|
||||
})
|
||||
.then(() => {
|
||||
commit('setDeleted', { status })
|
||||
})
|
||||
|
|
@ -531,141 +627,208 @@ const statuses = {
|
|||
level: 'error',
|
||||
messageKey: 'status.delete_error',
|
||||
messageArgs: [e.message],
|
||||
timeout: 5000
|
||||
timeout: 5000,
|
||||
})
|
||||
})
|
||||
},
|
||||
deleteStatusById ({ rootState, commit }, id) {
|
||||
deleteStatusById({ rootState, commit }, id) {
|
||||
const status = rootState.statuses.allStatusesObject[id]
|
||||
commit('setDeleted', { status })
|
||||
},
|
||||
markStatusesAsDeleted ({ commit }, condition) {
|
||||
markStatusesAsDeleted({ commit }, condition) {
|
||||
commit('setManyDeleted', condition)
|
||||
},
|
||||
favorite ({ rootState, commit }, status) {
|
||||
favorite({ rootState, commit }, status) {
|
||||
// Optimistic favoriting...
|
||||
commit('setFavorited', { status, value: true })
|
||||
rootState.api.backendInteractor.favorite({ id: status.id })
|
||||
.then(status => commit('setFavoritedConfirm', { status, user: rootState.users.currentUser }))
|
||||
rootState.api.backendInteractor
|
||||
.favorite({ id: status.id })
|
||||
.then((status) =>
|
||||
commit('setFavoritedConfirm', {
|
||||
status,
|
||||
user: rootState.users.currentUser,
|
||||
}),
|
||||
)
|
||||
},
|
||||
unfavorite ({ rootState, commit }, status) {
|
||||
unfavorite({ rootState, commit }, status) {
|
||||
// Optimistic unfavoriting...
|
||||
commit('setFavorited', { status, value: false })
|
||||
rootState.api.backendInteractor.unfavorite({ id: status.id })
|
||||
.then(status => commit('setFavoritedConfirm', { status, user: rootState.users.currentUser }))
|
||||
rootState.api.backendInteractor
|
||||
.unfavorite({ id: status.id })
|
||||
.then((status) =>
|
||||
commit('setFavoritedConfirm', {
|
||||
status,
|
||||
user: rootState.users.currentUser,
|
||||
}),
|
||||
)
|
||||
},
|
||||
fetchPinnedStatuses ({ rootState, dispatch }, userId) {
|
||||
rootState.api.backendInteractor.fetchPinnedStatuses({ id: userId })
|
||||
.then(statuses => dispatch('addNewStatuses', { statuses, timeline: 'user', userId, showImmediately: true, noIdUpdate: true }))
|
||||
fetchPinnedStatuses({ rootState, dispatch }, 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({ id: statusId })
|
||||
pinStatus({ rootState, dispatch }, statusId) {
|
||||
return rootState.api.backendInteractor
|
||||
.pinOwnStatus({ id: statusId })
|
||||
.then((status) => dispatch('addNewStatuses', { statuses: [status] }))
|
||||
},
|
||||
unpinStatus ({ rootState, dispatch }, statusId) {
|
||||
rootState.api.backendInteractor.unpinOwnStatus({ id: statusId })
|
||||
unpinStatus({ rootState, dispatch }, statusId) {
|
||||
rootState.api.backendInteractor
|
||||
.unpinOwnStatus({ id: statusId })
|
||||
.then((status) => dispatch('addNewStatuses', { statuses: [status] }))
|
||||
},
|
||||
muteConversation ({ rootState, commit }, { id: statusId }) {
|
||||
return rootState.api.backendInteractor.muteConversation({ id: statusId })
|
||||
muteConversation({ rootState, commit }, { id: statusId }) {
|
||||
return rootState.api.backendInteractor
|
||||
.muteConversation({ id: statusId })
|
||||
.then((status) => commit('setMutedStatus', status))
|
||||
},
|
||||
unmuteConversation ({ rootState, commit }, { id: statusId }) {
|
||||
return rootState.api.backendInteractor.unmuteConversation({ id: statusId })
|
||||
unmuteConversation({ rootState, commit }, { id: statusId }) {
|
||||
return rootState.api.backendInteractor
|
||||
.unmuteConversation({ id: statusId })
|
||||
.then((status) => commit('setMutedStatus', status))
|
||||
},
|
||||
retweet ({ rootState, commit }, status) {
|
||||
retweet({ rootState, commit }, status) {
|
||||
// Optimistic retweeting...
|
||||
commit('setRetweeted', { status, value: true })
|
||||
rootState.api.backendInteractor.retweet({ id: status.id })
|
||||
.then(status => commit('setRetweetedConfirm', { status: status.retweeted_status, user: rootState.users.currentUser }))
|
||||
rootState.api.backendInteractor
|
||||
.retweet({ id: status.id })
|
||||
.then((status) =>
|
||||
commit('setRetweetedConfirm', {
|
||||
status: status.retweeted_status,
|
||||
user: rootState.users.currentUser,
|
||||
}),
|
||||
)
|
||||
},
|
||||
unretweet ({ rootState, commit }, status) {
|
||||
unretweet({ rootState, commit }, status) {
|
||||
// Optimistic unretweeting...
|
||||
commit('setRetweeted', { status, value: false })
|
||||
rootState.api.backendInteractor.unretweet({ id: status.id })
|
||||
.then(status => commit('setRetweetedConfirm', { status, user: rootState.users.currentUser }))
|
||||
rootState.api.backendInteractor
|
||||
.unretweet({ id: status.id })
|
||||
.then((status) =>
|
||||
commit('setRetweetedConfirm', {
|
||||
status,
|
||||
user: rootState.users.currentUser,
|
||||
}),
|
||||
)
|
||||
},
|
||||
bookmark ({ rootState, commit }, status) {
|
||||
bookmark({ rootState, commit }, status) {
|
||||
commit('setBookmarked', { status, value: true })
|
||||
rootState.api.backendInteractor.bookmarkStatus({ id: status.id, folder_id: status.bookmark_folder_id })
|
||||
.then(status => {
|
||||
rootState.api.backendInteractor
|
||||
.bookmarkStatus({ id: status.id, folder_id: status.bookmark_folder_id })
|
||||
.then((status) => {
|
||||
commit('setBookmarkedConfirm', { status })
|
||||
})
|
||||
},
|
||||
unbookmark ({ rootState, commit }, status) {
|
||||
unbookmark({ rootState, commit }, status) {
|
||||
commit('setBookmarked', { status, value: false })
|
||||
rootState.api.backendInteractor.unbookmarkStatus({ id: status.id })
|
||||
.then(status => {
|
||||
rootState.api.backendInteractor
|
||||
.unbookmarkStatus({ id: status.id })
|
||||
.then((status) => {
|
||||
commit('setBookmarkedConfirm', { status })
|
||||
})
|
||||
},
|
||||
queueFlush ({ commit }, { timeline, id }) {
|
||||
queueFlush({ commit }, { timeline, id }) {
|
||||
commit('queueFlush', { timeline, id })
|
||||
},
|
||||
queueFlushAll ({ commit }) {
|
||||
queueFlushAll({ commit }) {
|
||||
commit('queueFlushAll')
|
||||
},
|
||||
fetchFavsAndRepeats ({ rootState, commit }, id) {
|
||||
fetchFavsAndRepeats({ rootState, commit }, id) {
|
||||
Promise.all([
|
||||
rootState.api.backendInteractor.fetchFavoritedByUsers({ id }),
|
||||
rootState.api.backendInteractor.fetchRebloggedByUsers({ 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 })
|
||||
commit('addFavs', {
|
||||
id,
|
||||
favoritedByUsers,
|
||||
currentUser: rootState.users.currentUser,
|
||||
})
|
||||
commit('addRepeats', {
|
||||
id,
|
||||
rebloggedByUsers,
|
||||
currentUser: rootState.users.currentUser,
|
||||
})
|
||||
})
|
||||
},
|
||||
reactWithEmoji ({ rootState, dispatch, commit }, { id, emoji }) {
|
||||
reactWithEmoji({ rootState, dispatch, commit }, { id, emoji }) {
|
||||
const currentUser = rootState.users.currentUser
|
||||
if (!currentUser) return
|
||||
|
||||
commit('addOwnReaction', { id, emoji, currentUser })
|
||||
rootState.api.backendInteractor.reactWithEmoji({ id, emoji }).then(
|
||||
() => {
|
||||
dispatch('fetchEmojiReactionsBy', id)
|
||||
}
|
||||
)
|
||||
rootState.api.backendInteractor.reactWithEmoji({ id, emoji }).then(() => {
|
||||
dispatch('fetchEmojiReactionsBy', id)
|
||||
})
|
||||
},
|
||||
unreactWithEmoji ({ rootState, dispatch, commit }, { id, emoji }) {
|
||||
unreactWithEmoji({ rootState, dispatch, commit }, { id, emoji }) {
|
||||
const currentUser = rootState.users.currentUser
|
||||
if (!currentUser) return
|
||||
|
||||
commit('removeOwnReaction', { id, emoji, currentUser })
|
||||
rootState.api.backendInteractor.unreactWithEmoji({ id, emoji }).then(
|
||||
() => {
|
||||
rootState.api.backendInteractor
|
||||
.unreactWithEmoji({ id, emoji })
|
||||
.then(() => {
|
||||
dispatch('fetchEmojiReactionsBy', id)
|
||||
}
|
||||
)
|
||||
})
|
||||
},
|
||||
fetchEmojiReactionsBy ({ rootState, commit }, id) {
|
||||
return rootState.api.backendInteractor.fetchEmojiReactions({ id }).then(
|
||||
emojiReactions => {
|
||||
commit('addEmojiReactionsBy', { id, emojiReactions, currentUser: rootState.users.currentUser })
|
||||
}
|
||||
)
|
||||
fetchEmojiReactionsBy({ rootState, commit }, id) {
|
||||
return rootState.api.backendInteractor
|
||||
.fetchEmojiReactions({ id })
|
||||
.then((emojiReactions) => {
|
||||
commit('addEmojiReactionsBy', {
|
||||
id,
|
||||
emojiReactions,
|
||||
currentUser: rootState.users.currentUser,
|
||||
})
|
||||
})
|
||||
},
|
||||
fetchFavs ({ rootState, commit }, id) {
|
||||
rootState.api.backendInteractor.fetchFavoritedByUsers({ id })
|
||||
.then(favoritedByUsers => commit('addFavs', { id, favoritedByUsers, currentUser: rootState.users.currentUser }))
|
||||
fetchFavs({ rootState, commit }, 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 })
|
||||
.then(rebloggedByUsers => commit('addRepeats', { id, rebloggedByUsers, currentUser: rootState.users.currentUser }))
|
||||
fetchRepeats({ rootState, commit }, id) {
|
||||
rootState.api.backendInteractor
|
||||
.fetchRebloggedByUsers({ id })
|
||||
.then((rebloggedByUsers) =>
|
||||
commit('addRepeats', {
|
||||
id,
|
||||
rebloggedByUsers,
|
||||
currentUser: rootState.users.currentUser,
|
||||
}),
|
||||
)
|
||||
},
|
||||
search (store, { q, resolve, limit, offset, following, type }) {
|
||||
return store.rootState.api.backendInteractor.search2({ q, resolve, limit, offset, following, type })
|
||||
search(store, { q, resolve, limit, offset, following, type }) {
|
||||
return store.rootState.api.backendInteractor
|
||||
.search2({ q, resolve, limit, offset, following, type })
|
||||
.then((data) => {
|
||||
store.commit('addNewUsers', data.accounts)
|
||||
store.commit('addNewUsers', data.statuses.map(s => s.user).filter(u => u))
|
||||
store.commit(
|
||||
'addNewUsers',
|
||||
data.statuses.map((s) => s.user).filter((u) => u),
|
||||
)
|
||||
store.commit('addNewStatuses', { statuses: data.statuses })
|
||||
return data
|
||||
})
|
||||
},
|
||||
setVirtualHeight ({ commit }, { statusId, height }) {
|
||||
setVirtualHeight({ commit }, { statusId, height }) {
|
||||
commit('setVirtualHeight', { statusId, height })
|
||||
}
|
||||
},
|
||||
},
|
||||
mutations
|
||||
mutations,
|
||||
}
|
||||
|
||||
export default statuses
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue