mirror of
https://akkoma.dev/AkkomaGang/akkoma-fe.git
synced 2024-11-08 17:39:09 +00:00
Make timelineless status adding possible.
This commit is contained in:
parent
81c6f6e21f
commit
a5f523922c
2 changed files with 33 additions and 11 deletions
|
@ -1,4 +1,4 @@
|
|||
import { remove, map, slice, sortBy, toInteger, each, find, flatten, maxBy, last, merge, max } from 'lodash'
|
||||
import { remove, map, slice, sortBy, toInteger, each, find, flatten, maxBy, last, merge, max, isArray } from 'lodash'
|
||||
import moment from 'moment'
|
||||
import apiService from '../services/api/api.service.js'
|
||||
// import parse from '../services/status_parser/status_parser.js'
|
||||
|
@ -100,11 +100,17 @@ const mergeOrAdd = (arr, item) => {
|
|||
}
|
||||
|
||||
const addNewStatuses = (state, { statuses, showImmediately = false, timeline, user = {} }) => {
|
||||
// Sanity check
|
||||
if (!isArray(statuses)) {
|
||||
return false
|
||||
}
|
||||
|
||||
const allStatuses = state.allStatuses
|
||||
const timelineObject = state.timelines[timeline]
|
||||
|
||||
// Set the maxId to the new id if it's larger.
|
||||
const updateMaxId = ({id}) => {
|
||||
if (!timeline) { return false }
|
||||
timelineObject.maxId = max([id, timelineObject.maxId])
|
||||
}
|
||||
|
||||
|
@ -117,15 +123,15 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
|||
}
|
||||
|
||||
// Some statuses should only be added to the global status repository.
|
||||
if (addToTimeline) {
|
||||
if (timeline && addToTimeline) {
|
||||
mergeOrAdd(timelineObject.statuses, status)
|
||||
}
|
||||
|
||||
if (showImmediately) {
|
||||
if (timeline && showImmediately) {
|
||||
// Add it directly to the visibleStatuses, don't change
|
||||
// newStatusCount
|
||||
mergeOrAdd(timelineObject.visibleStatuses, status)
|
||||
} else if (addToTimeline && result.new) {
|
||||
} else if (timeline && addToTimeline && result.new) {
|
||||
// Just change newStatuscount
|
||||
timelineObject.newStatusCount += 1
|
||||
}
|
||||
|
@ -159,7 +165,7 @@ 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 (find(timelineObject.visibleStatuses, {id: retweetedStatus.id})) {
|
||||
if (timeline && find(timelineObject.visibleStatuses, {id: retweetedStatus.id})) {
|
||||
// Already have it visible, don't add to timeline, don't show.
|
||||
retweet = addStatus(status, false, false)
|
||||
} else {
|
||||
|
@ -177,8 +183,10 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
|||
updateMaxId(deletion)
|
||||
|
||||
remove(allStatuses, { uri })
|
||||
if (timeline) {
|
||||
remove(timelineObject.statuses, { uri })
|
||||
remove(timelineObject.visibleStatuses, { uri })
|
||||
}
|
||||
},
|
||||
'default': (unknown) => {
|
||||
console.log(unknown)
|
||||
|
@ -192,9 +200,11 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
|||
})
|
||||
|
||||
// Keep the visible statuses sorted
|
||||
if (timeline) {
|
||||
timelineObject.visibleStatuses = sortBy(timelineObject.visibleStatuses, ({id}) => -id)
|
||||
timelineObject.statuses = sortBy(timelineObject.statuses, ({id}) => -id)
|
||||
timelineObject.minVisibleId = (last(timelineObject.statuses) || {}).id
|
||||
}
|
||||
}
|
||||
|
||||
export const mutations = {
|
||||
|
@ -228,7 +238,7 @@ export const mutations = {
|
|||
const statuses = {
|
||||
state: defaultState,
|
||||
actions: {
|
||||
addNewStatuses ({ rootState, commit }, { statuses, showImmediately = false, timeline }) {
|
||||
addNewStatuses ({ rootState, commit }, { statuses, showImmediately = false, timeline = false }) {
|
||||
commit('addNewStatuses', { statuses, showImmediately, timeline, user: rootState.users.currentUser })
|
||||
},
|
||||
favorite ({ rootState, commit }, status) {
|
||||
|
|
|
@ -67,6 +67,18 @@ describe('The Statuses module', () => {
|
|||
expect(state.timelines.public.newStatusCount).to.equal(1)
|
||||
})
|
||||
|
||||
it('add the statuses to allStatuses if no timeline is given', () => {
|
||||
const state = cloneDeep(defaultState)
|
||||
const status = makeMockStatus({id: 1})
|
||||
|
||||
mutations.addNewStatuses(state, { statuses: [status] })
|
||||
|
||||
expect(state.allStatuses).to.eql([status])
|
||||
expect(state.timelines.public.statuses).to.eql([])
|
||||
expect(state.timelines.public.visibleStatuses).to.eql([])
|
||||
expect(state.timelines.public.newStatusCount).to.equal(0)
|
||||
})
|
||||
|
||||
it('adds the status to allStatuses and to the given timeline, directly visible', () => {
|
||||
const state = cloneDeep(defaultState)
|
||||
const status = makeMockStatus({id: 1})
|
||||
|
|
Loading…
Reference in a new issue