mirror of
https://akkoma.dev/AkkomaGang/akkoma-fe.git
synced 2024-11-08 17:39:09 +00:00
Don't put statuses we received from retweets into timelines.
They should be in allStatuses to keep only one reference, but they should not get into the timeline, or it will mess up old status fetching, because they have a very low id.
This commit is contained in:
parent
79b2243f6c
commit
f8a3afc9d1
2 changed files with 17 additions and 16 deletions
|
@ -1,4 +1,4 @@
|
|||
import { flatten, map, slice, last, intersectionBy, sortBy, unionBy, toInteger, groupBy, differenceBy, each, find } from 'lodash'
|
||||
import { reduce, map, slice, last, intersectionBy, sortBy, unionBy, toInteger, groupBy, differenceBy, each, find } from 'lodash'
|
||||
import moment from 'moment'
|
||||
import apiService from '../services/api/api.service.js'
|
||||
|
||||
|
@ -55,14 +55,6 @@ const addStatusesToTimeline = (addedStatuses, showImmediately, { statuses, visib
|
|||
|
||||
addedStatuses = statusesAndFaves['status'] || []
|
||||
|
||||
const splitRetweets = (status) => {
|
||||
if (status.retweeted_status) {
|
||||
return [status, status.retweeted_status]
|
||||
} else {
|
||||
return status
|
||||
}
|
||||
}
|
||||
|
||||
// Add some html and nsfw to the statuses.
|
||||
addedStatuses = map(addedStatuses, (status) => {
|
||||
const statusoid = status.retweeted_status || status
|
||||
|
@ -79,11 +71,9 @@ const addStatusesToTimeline = (addedStatuses, showImmediately, { statuses, visib
|
|||
statusoid.nsfw = statusoid.text.match(nsfwRegex)
|
||||
}
|
||||
|
||||
return splitRetweets(status)
|
||||
return status
|
||||
})
|
||||
|
||||
addedStatuses = flatten(addedStatuses)
|
||||
|
||||
const newStatuses = sortBy(
|
||||
unionBy(addedStatuses, statuses, 'id'),
|
||||
({id}) => -id
|
||||
|
@ -125,9 +115,19 @@ const updateTimestampsInStatuses = (statuses) => {
|
|||
export const mutations = {
|
||||
addNewStatuses (state, { statuses, showImmediately = false, timeline }) {
|
||||
state.timelines[timeline] = addStatusesToTimeline(statuses, showImmediately, state.timelines[timeline])
|
||||
state.allStatuses = unionBy(state.timelines[timeline].statuses, state.allStatuses.id)
|
||||
state.allStatuses = unionBy(state.timelines[timeline].statuses, state.allStatuses, 'id')
|
||||
|
||||
// Set up retweets with most current status
|
||||
const getRetweets = (result, status) => {
|
||||
if (status.retweeted_status) {
|
||||
result.push(status.retweeted_status)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
const retweets = reduce(statuses, getRetweets, [])
|
||||
|
||||
state.allStatuses = unionBy(retweets, state.allStatuses, 'id')
|
||||
|
||||
each(state.allStatuses, (status) => {
|
||||
if (status.retweeted_status) {
|
||||
|
|
|
@ -42,9 +42,10 @@ describe('The Statuses module', () => {
|
|||
|
||||
retweet.retweeted_status = status
|
||||
|
||||
// It adds both statuses
|
||||
mutations.addNewStatuses(state, { statuses: [retweet], timeline: 'public' })
|
||||
expect(state.allStatuses).to.eql([retweet, status])
|
||||
// It adds both statuses, but only the retweet to visible.
|
||||
mutations.addNewStatuses(state, { statuses: [retweet], timeline: 'public', showImmediately: true })
|
||||
expect(state.timelines.public.visibleStatuses).to.have.length(1)
|
||||
expect(state.allStatuses).to.eql([status, retweet])
|
||||
|
||||
// It refers to the modified status.
|
||||
mutations.addNewStatuses(state, { statuses: [modStatus], timeline: 'public' })
|
||||
|
|
Loading…
Reference in a new issue