diff options
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/api.js | 10 | ||||
| -rw-r--r-- | src/modules/statuses.js | 31 |
2 files changed, 22 insertions, 19 deletions
diff --git a/src/modules/api.js b/src/modules/api.js index a61340c2..b85b24be 100644 --- a/src/modules/api.js +++ b/src/modules/api.js @@ -5,7 +5,7 @@ import { Socket } from 'phoenix' const api = { state: { backendInteractor: backendInteractorService(), - fetchers: {}, + fetchers: new Map(), socket: null, chatDisabled: false, followRequests: [] @@ -15,10 +15,10 @@ const api = { state.backendInteractor = backendInteractor }, addFetcher (state, {timeline, fetcher}) { - state.fetchers[timeline] = fetcher + state.fetchers.set(timeline, fetcher) }, removeFetcher (state, {timeline}) { - delete state.fetchers[timeline] + delete state.fetchers.delete(timeline) }, setSocket (state, socket) { state.socket = socket @@ -41,13 +41,13 @@ const api = { } // Don't start fetching if we already are. - if (!store.state.fetchers[timeline]) { + if (!store.state.fetchers.has(timeline)) { const fetcher = store.state.backendInteractor.startFetching({timeline, store, userId}) store.commit('addFetcher', {timeline, fetcher}) } }, stopFetching (store, timeline) { - const fetcher = store.state.fetchers[timeline] + const fetcher = store.state.fetchers.get(timeline) window.clearInterval(fetcher) store.commit('removeFetcher', {timeline}) }, diff --git a/src/modules/statuses.js b/src/modules/statuses.js index dccccf72..33804d39 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -2,7 +2,7 @@ import { includes, remove, slice, sortBy, toInteger, each, find, flatten, maxBy, import apiService from '../services/api/api.service.js' // import parse from '../services/status_parser/status_parser.js' -const emptyTl = () => ({ +export const emptyTl = (tl) => (Object.assign(tl, { statuses: [], statusesObject: {}, faves: [], @@ -16,7 +16,7 @@ const emptyTl = () => ({ friends: [], userId: 0, flushMarker: 0 -}) +})) export const defaultState = { allStatuses: [], @@ -33,13 +33,13 @@ 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' }) } } @@ -137,7 +137,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 @@ -337,7 +337,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 +346,8 @@ export const mutations = { each(oldTimeline.visibleStatuses, (status) => { oldTimeline.visibleStatusesObject[status.id] = status }) }, clearTimeline (state, { timeline }) { - state.timelines[timeline] = emptyTl() + const timelineObject = typeof timeline === 'object' ? timeline : state.timelines[timeline] + emptyTl(timelineObject) }, setFavorited (state, { status, value }) { const newStatus = state.allStatusesObject[status.id] @@ -366,7 +367,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 +389,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 } } |
