forked from AkkomaGang/akkoma-fe
Some reducer changes for statuses.
This commit is contained in:
parent
d4284686fa
commit
d10a58f26a
1 changed files with 36 additions and 21 deletions
|
@ -1,7 +1,7 @@
|
||||||
import { reduce, map, slice, last, intersectionBy, sortBy, unionBy, toInteger, groupBy, differenceBy, each, find, flatten, maxBy } from 'lodash'
|
import { reduce, map, slice, last, intersectionBy, sortBy, unionBy, toInteger, groupBy, differenceBy, each, find, flatten, maxBy } from 'lodash'
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import apiService from '../services/api/api.service.js'
|
import apiService from '../services/api/api.service.js'
|
||||||
import parse from '../services/status_parser/status_parser.js'
|
// import parse from '../services/status_parser/status_parser.js'
|
||||||
|
|
||||||
export const defaultState = {
|
export const defaultState = {
|
||||||
allStatuses: [],
|
allStatuses: [],
|
||||||
|
@ -41,6 +41,19 @@ const statusType = (status) => {
|
||||||
return !status.is_post_verb && status.uri.match(/fave/) ? 'fave' : 'status'
|
return !status.is_post_verb && status.uri.match(/fave/) ? 'fave' : 'status'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const prepareStatus = (status) => {
|
||||||
|
// Parse nsfw tags
|
||||||
|
if (status.nsfw === undefined) {
|
||||||
|
const nsfwRegex = /#nsfw/i
|
||||||
|
status.nsfw = !!status.text.match(nsfwRegex)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set created_at_parsed to initial value
|
||||||
|
status.created_at_parsed = status.created_at
|
||||||
|
|
||||||
|
return status
|
||||||
|
}
|
||||||
|
|
||||||
const addStatusesToTimeline = (addedStatuses, showImmediately, { statuses, visibleStatuses, newStatusCount, faves, loading, maxId }) => {
|
const addStatusesToTimeline = (addedStatuses, showImmediately, { statuses, visibleStatuses, newStatusCount, faves, loading, maxId }) => {
|
||||||
const statusesAndFaves = groupBy(addedStatuses, statusType)
|
const statusesAndFaves = groupBy(addedStatuses, statusType)
|
||||||
const addedFaves = statusesAndFaves['fave'] || []
|
const addedFaves = statusesAndFaves['fave'] || []
|
||||||
|
@ -60,13 +73,7 @@ const addStatusesToTimeline = (addedStatuses, showImmediately, { statuses, visib
|
||||||
addedStatuses = map(addedStatuses, (status) => {
|
addedStatuses = map(addedStatuses, (status) => {
|
||||||
const statusoid = status.retweeted_status || status
|
const statusoid = status.retweeted_status || status
|
||||||
|
|
||||||
statusoid.created_at_parsed = statusoid.created_at
|
prepareStatus(statusoid)
|
||||||
statusoid.statusnet_html = parse(statusoid.statusnet_html)
|
|
||||||
|
|
||||||
if (statusoid.nsfw === undefined) {
|
|
||||||
const nsfwRegex = /#nsfw/i
|
|
||||||
statusoid.nsfw = statusoid.text.match(nsfwRegex)
|
|
||||||
}
|
|
||||||
|
|
||||||
return status
|
return status
|
||||||
})
|
})
|
||||||
|
@ -109,24 +116,28 @@ const updateTimestampsInStatuses = (statuses) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// const groupStatusesByType = (statuses) => {
|
||||||
|
// return groupBy(statuses, (status) => {
|
||||||
|
// if (status.is_post_verb) {
|
||||||
|
// return 'status'
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (status.retweeted_status) {
|
||||||
|
// return 'retweet'
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (typeof status.uri === 'string' && status.uri.match(/fave/)) {
|
||||||
|
// return 'favorite'
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return 'unknown'
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
|
||||||
export const findMaxId = (...args) => {
|
export const findMaxId = (...args) => {
|
||||||
return (maxBy(flatten(args), 'id') || {}).id
|
return (maxBy(flatten(args), 'id') || {}).id
|
||||||
}
|
}
|
||||||
|
|
||||||
export const prepareStatus = (status) => {
|
|
||||||
// Parse nsfw tags
|
|
||||||
if (status.nsfw === undefined) {
|
|
||||||
const nsfwRegex = /#nsfw/i
|
|
||||||
status.nsfw = !!status.text.match(nsfwRegex)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set created_at_parsed to initial value
|
|
||||||
status.created_at_parsed = status.created_at
|
|
||||||
|
|
||||||
return status
|
|
||||||
}
|
|
||||||
|
|
||||||
export const mutations = {
|
export const mutations = {
|
||||||
addNewStatuses (state, { statuses, showImmediately = false, timeline }) {
|
addNewStatuses (state, { statuses, showImmediately = false, timeline }) {
|
||||||
const timelineObject = state.timelines[timeline]
|
const timelineObject = state.timelines[timeline]
|
||||||
|
@ -134,6 +145,10 @@ export const mutations = {
|
||||||
// Set new maxId
|
// Set new maxId
|
||||||
const maxId = findMaxId(statuses, timelineObject.statuses)
|
const maxId = findMaxId(statuses, timelineObject.statuses)
|
||||||
timelineObject.maxId = maxId
|
timelineObject.maxId = maxId
|
||||||
|
|
||||||
|
// Split statuses by type
|
||||||
|
// const statusesByType = groupStatusesByType(statuses)
|
||||||
|
|
||||||
state.timelines[timeline] = addStatusesToTimeline(statuses, showImmediately, state.timelines[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')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue