aboutsummaryrefslogtreecommitdiff
path: root/src/modules/statuses.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/statuses.js')
-rw-r--r--src/modules/statuses.js82
1 files changed, 24 insertions, 58 deletions
diff --git a/src/modules/statuses.js b/src/modules/statuses.js
index f92239a9..97b6d2ee 100644
--- a/src/modules/statuses.js
+++ b/src/modules/statuses.js
@@ -1,8 +1,8 @@
-import { includes, remove, slice, sortBy, toInteger, each, find, flatten, maxBy, minBy, merge, last, isArray } from 'lodash'
+import { remove, slice, sortBy, toInteger, each, find, flatten, maxBy, minBy, merge, last, isArray } from 'lodash'
import apiService from '../services/api/api.service.js'
// import parse from '../services/status_parser/status_parser.js'
-const emptyTl = (userId = 0) => ({
+export const emptyTl = (tl, userId) => (Object.assign(tl, {
statuses: [],
statusesObject: {},
faves: [],
@@ -14,9 +14,10 @@ const emptyTl = (userId = 0) => ({
loading: false,
followers: [],
friends: [],
+ userId: 0,
flushMarker: 0,
userId
-})
+}))
export const defaultState = {
allStatuses: [],
@@ -33,30 +34,17 @@ export const defaultState = {
favorites: new Set(),
error: false,
timelines: {
- mentions: emptyTl(),
- public: emptyTl(),
- user: emptyTl(),
- publicAndExternal: emptyTl(),
- friends: emptyTl(),
- tag: emptyTl(),
- dms: emptyTl()
+ mentions: emptyTl({ type: 'mentions' }),
+ public: emptyTl({ type: 'public' }),
+ user: emptyTl({ type: 'user' }), // TODO: switch to unregistered
+ publicAndExternal: emptyTl({ type: 'publicAndExternal' }),
+ friends: emptyTl({ type: 'friends' }),
+ tag: emptyTl({ type: 'tag' }),
+ dms: emptyTl({ type: 'dms' })
}
}
-const isNsfw = (status) => {
- const nsfwRegex = /#nsfw/i
- return includes(status.tags, 'nsfw') || !!status.text.match(nsfwRegex)
-}
-
export const prepareStatus = (status) => {
- // Parse nsfw tags
- if (status.nsfw === undefined) {
- status.nsfw = isNsfw(status)
- if (status.retweeted_status) {
- status.nsfw = status.retweeted_status.nsfw
- }
- }
-
// Set deleted flag
status.deleted = false
@@ -75,31 +63,6 @@ const visibleNotificationTypes = (rootState) => {
].filter(_ => _)
}
-export const statusType = (status) => {
- if (status.is_post_verb) {
- return 'status'
- }
-
- if (status.retweeted_status) {
- return 'retweet'
- }
-
- if ((typeof status.uri === 'string' && status.uri.match(/(fave|objectType=Favourite)/)) ||
- (typeof status.text === 'string' && status.text.match(/favorited/))) {
- return 'favorite'
- }
-
- if (status.text.match(/deleted notice {{tag/) || status.qvitter_delete_notice) {
- return 'deletion'
- }
-
- if (status.text.match(/started following/) || status.activity_type === 'follow') {
- return 'follow'
- }
-
- return 'unknown'
-}
-
export const findMaxId = (...args) => {
return (maxBy(flatten(args), 'id') || {}).id
}
@@ -137,7 +100,7 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
const allStatuses = state.allStatuses
const allStatusesObject = state.allStatusesObject
- const timelineObject = state.timelines[timeline]
+ const timelineObject = typeof timeline === 'object' ? timeline : state.timelines[timeline]
const maxNew = statuses.length > 0 ? maxBy(statuses, 'id').id : 0
const older = timeline && maxNew < timelineObject.maxId
@@ -153,13 +116,13 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
return
}
- const addStatus = (status, showImmediately, addToTimeline = true) => {
- const result = mergeOrAdd(allStatuses, allStatusesObject, status)
- status = result.item
+ const addStatus = (data, showImmediately, addToTimeline = true) => {
+ const result = mergeOrAdd(allStatuses, allStatusesObject, data)
+ const status = result.item
if (result.new) {
// We are mentioned in a post
- if (statusType(status) === 'status' && find(status.attentions, { id: user.id })) {
+ if (status.type === 'status' && find(status.attentions, { id: user.id })) {
const mentions = state.timelines.mentions
// Add the mention to the mentions timeline
@@ -270,7 +233,7 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
}
each(statuses, (status) => {
- const type = statusType(status)
+ const type = status.type
const processor = processors[type] || processors['default']
processor(status)
})
@@ -337,7 +300,7 @@ export const mutations = {
addNewStatuses,
addNewNotifications,
showNewStatuses (state, { timeline }) {
- const oldTimeline = (state.timelines[timeline])
+ const oldTimeline = (typeof timeline === 'object' ? timeline : state.timelines[timeline])
oldTimeline.newStatusCount = 0
oldTimeline.visibleStatuses = slice(oldTimeline.statuses, 0, 50)
@@ -346,7 +309,8 @@ export const mutations = {
each(oldTimeline.visibleStatuses, (status) => { oldTimeline.visibleStatusesObject[status.id] = status })
},
clearTimeline (state, { timeline }) {
- state.timelines[timeline] = emptyTl(state.timelines[timeline].userId)
+ const timelineObject = typeof timeline === 'object' ? timeline : state.timelines[timeline]
+ emptyTl(timelineObject, state.timelines[timeline].userId)
},
setFavorited (state, { status, value }) {
const newStatus = state.allStatusesObject[status.id]
@@ -366,7 +330,8 @@ export const mutations = {
newStatus.deleted = true
},
setLoading (state, { timeline, value }) {
- state.timelines[timeline].loading = value
+ const timelineObject = typeof timeline === 'object' ? timeline : state.timelines[timeline]
+ timelineObject.loading = value
},
setNsfw (state, { id, nsfw }) {
const newStatus = state.allStatusesObject[id]
@@ -387,7 +352,8 @@ export const mutations = {
})
},
queueFlush (state, { timeline, id }) {
- state.timelines[timeline].flushMarker = id
+ const timelineObject = typeof timeline === 'object' ? timeline : state.timelines[timeline]
+ timelineObject.flushMarker = id
}
}