forked from AkkomaGang/akkoma-fe
prepareStatus: nsfw tag parsing.
This commit is contained in:
parent
5888697c0d
commit
59647798b9
2 changed files with 28 additions and 2 deletions
|
@ -114,6 +114,15 @@ export const findMaxId = (...args) => {
|
||||||
return (maxBy(flatten(args), 'id') || {}).id
|
return (maxBy(flatten(args), 'id') || {}).id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const prepareStatus = (status) => {
|
||||||
|
if (status.nsfw === undefined) {
|
||||||
|
const nsfwRegex = /#nsfw/i
|
||||||
|
status.nsfw = !!status.text.match(nsfwRegex)
|
||||||
|
}
|
||||||
|
|
||||||
|
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]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { cloneDeep } from 'lodash'
|
import { cloneDeep } from 'lodash'
|
||||||
import { defaultState, mutations, findMaxId } from '../../../../src/modules/statuses.js'
|
import { defaultState, mutations, findMaxId, prepareStatus } from '../../../../src/modules/statuses.js'
|
||||||
|
|
||||||
const makeMockStatus = ({id, text}) => {
|
const makeMockStatus = ({id, text}) => {
|
||||||
return {
|
return {
|
||||||
|
@ -11,7 +11,24 @@ const makeMockStatus = ({id, text}) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('findMaxId', () => {
|
describe('Statuses.prepareStatus', () => {
|
||||||
|
it('sets nsfw for statuses with the #nsfw tag', () => {
|
||||||
|
const safe = makeMockStatus({id: 1, text: 'Hello oniichan'})
|
||||||
|
const nsfw = makeMockStatus({id: 1, text: 'Hello oniichan #nsfw'})
|
||||||
|
|
||||||
|
expect(prepareStatus(safe).nsfw).to.eq(false)
|
||||||
|
expect(prepareStatus(nsfw).nsfw).to.eq(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('leaves existing nsfw settings alone', () => {
|
||||||
|
const nsfw = makeMockStatus({id: 1, text: 'Hello oniichan #nsfw'})
|
||||||
|
nsfw.nsfw = false
|
||||||
|
|
||||||
|
expect(prepareStatus(nsfw).nsfw).to.eq(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('Statuses.findMaxId', () => {
|
||||||
it('returns the largest id in any of the given arrays', () => {
|
it('returns the largest id in any of the given arrays', () => {
|
||||||
const statusesOne = [{ id: 100 }, { id: 2 }]
|
const statusesOne = [{ id: 100 }, { id: 2 }]
|
||||||
const statusesTwo = [{ id: 3 }]
|
const statusesTwo = [{ id: 3 }]
|
||||||
|
|
Loading…
Reference in a new issue