aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoger Braun <roger@rogerbraun.net>2016-11-15 10:35:16 +0100
committerRoger Braun <roger@rogerbraun.net>2016-11-15 10:35:16 +0100
commitd10a58f26ab9b22fd9dba499a9f097ac177e1cae (patch)
tree491ca28086c5b0b8c2d61fe81b16d08c7ca7bb5b /src
parentd4284686fa791cc1a43ae058375e1d51d8f1bd5b (diff)
Some reducer changes for statuses.
Diffstat (limited to 'src')
-rw-r--r--src/modules/statuses.js55
1 files changed, 35 insertions, 20 deletions
diff --git a/src/modules/statuses.js b/src/modules/statuses.js
index 86995b03..d7607bf1 100644
--- a/src/modules/statuses.js
+++ b/src/modules/statuses.js
@@ -1,7 +1,7 @@
import { reduce, map, slice, last, intersectionBy, sortBy, unionBy, toInteger, groupBy, differenceBy, each, find, flatten, maxBy } from 'lodash'
import moment from 'moment'
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 = {
allStatuses: [],
@@ -41,6 +41,19 @@ const statusType = (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 statusesAndFaves = groupBy(addedStatuses, statusType)
const addedFaves = statusesAndFaves['fave'] || []
@@ -60,13 +73,7 @@ const addStatusesToTimeline = (addedStatuses, showImmediately, { statuses, visib
addedStatuses = map(addedStatuses, (status) => {
const statusoid = status.retweeted_status || status
- statusoid.created_at_parsed = statusoid.created_at
- statusoid.statusnet_html = parse(statusoid.statusnet_html)
-
- if (statusoid.nsfw === undefined) {
- const nsfwRegex = /#nsfw/i
- statusoid.nsfw = statusoid.text.match(nsfwRegex)
- }
+ prepareStatus(statusoid)
return status
})
@@ -109,22 +116,26 @@ const updateTimestampsInStatuses = (statuses) => {
})
}
+// const groupStatusesByType = (statuses) => {
+// return groupBy(statuses, (status) => {
+// if (status.is_post_verb) {
+// return 'status'
+// }
-export const findMaxId = (...args) => {
- return (maxBy(flatten(args), 'id') || {}).id
-}
+// if (status.retweeted_status) {
+// return 'retweet'
+// }
-export const prepareStatus = (status) => {
- // Parse nsfw tags
- if (status.nsfw === undefined) {
- const nsfwRegex = /#nsfw/i
- status.nsfw = !!status.text.match(nsfwRegex)
- }
+// if (typeof status.uri === 'string' && status.uri.match(/fave/)) {
+// return 'favorite'
+// }
- // Set created_at_parsed to initial value
- status.created_at_parsed = status.created_at
+// return 'unknown'
+// })
+// }
- return status
+export const findMaxId = (...args) => {
+ return (maxBy(flatten(args), 'id') || {}).id
}
export const mutations = {
@@ -134,6 +145,10 @@ export const mutations = {
// Set new maxId
const maxId = findMaxId(statuses, timelineObject.statuses)
timelineObject.maxId = maxId
+
+ // Split statuses by type
+ // const statusesByType = groupStatusesByType(statuses)
+
state.timelines[timeline] = addStatusesToTimeline(statuses, showImmediately, state.timelines[timeline])
state.allStatuses = unionBy(state.timelines[timeline].statuses, state.allStatuses, 'id')