aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2019-01-17 21:46:03 +0300
committerHenry Jameson <me@hjkos.com>2019-01-17 21:46:03 +0300
commitcab87744c830e4411ec20c1dcb2d454d657219bc (patch)
treeb9cc4054fda22ffdab706103f29bc404ef66d3e6 /src
parent0f8baff5a3cd865ca5e2bb420c44d7409a8dec9c (diff)
Revert "some initial work to make it possible to use "unregistered" timelines, i.e. not"
and some stuff to make favorites still work This reverts commit 039a4074006fb91ac9031b41b4e9af4a15766dfa.
Diffstat (limited to 'src')
-rw-r--r--src/components/timeline/timeline.js17
-rw-r--r--src/components/user_profile/user_profile.js9
-rw-r--r--src/modules/api.js10
-rw-r--r--src/modules/statuses.js36
-rw-r--r--src/services/api/api.service.js5
-rw-r--r--src/services/timeline_fetcher/timeline_fetcher.service.js4
6 files changed, 38 insertions, 43 deletions
diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js
index 23d2c1e8..98da8660 100644
--- a/src/components/timeline/timeline.js
+++ b/src/components/timeline/timeline.js
@@ -7,6 +7,7 @@ import { throttle } from 'lodash'
const Timeline = {
props: [
'timeline',
+ 'timelineName',
'title',
'userId',
'tag',
@@ -54,7 +55,7 @@ const Timeline = {
timelineFetcher.fetchAndUpdate({
store,
credentials,
- timeline: this.timeline,
+ timeline: this.timelineName,
showImmediately,
userId: this.userId,
tag: this.tag
@@ -69,32 +70,32 @@ const Timeline = {
destroyed () {
window.removeEventListener('scroll', this.scrollLoad)
if (typeof document.hidden !== 'undefined') document.removeEventListener('visibilitychange', this.handleVisibilityChange, false)
- this.$store.commit('setLoading', { timeline: this.timeline, value: false })
+ this.$store.commit('setLoading', { timeline: this.timelineName, value: false })
},
methods: {
showNewStatuses () {
if (this.timeline.flushMarker !== 0) {
- this.$store.commit('clearTimeline', { timeline: this.timeline })
- this.$store.commit('queueFlush', { timeline: this.timeline, id: 0 })
+ this.$store.commit('clearTimeline', { timeline: this.timelineName })
+ this.$store.commit('queueFlush', { timeline: this.timelineName, id: 0 })
this.fetchOlderStatuses()
} else {
- this.$store.commit('showNewStatuses', { timeline: this.timeline })
+ this.$store.commit('showNewStatuses', { timeline: this.timelineName })
this.paused = false
}
},
fetchOlderStatuses: throttle(function () {
const store = this.$store
const credentials = store.state.users.currentUser.credentials
- store.commit('setLoading', { timeline: this.timeline, value: true })
+ store.commit('setLoading', { timeline: this.timelineName, value: true })
timelineFetcher.fetchAndUpdate({
store,
credentials,
- timeline: this.timeline,
+ timeline: this.timelineName,
older: true,
showImmediately: true,
userId: this.userId,
tag: this.tag
- }).then(() => store.commit('setLoading', { timeline: this.timeline, value: false }))
+ }).then(() => store.commit('setLoading', { timeline: this.timelineName, value: false }))
}, 1000, this),
scrollLoad (e) {
const bodyBRect = document.body.getBoundingClientRect()
diff --git a/src/components/user_profile/user_profile.js b/src/components/user_profile/user_profile.js
index 245d55ca..7f17ef69 100644
--- a/src/components/user_profile/user_profile.js
+++ b/src/components/user_profile/user_profile.js
@@ -1,7 +1,6 @@
import UserCardContent from '../user_card_content/user_card_content.vue'
import UserCard from '../user_card/user_card.vue'
import Timeline from '../timeline/timeline.vue'
-import { emptyTl } from '../../modules/statuses.js'
const UserProfile = {
created () {
@@ -14,15 +13,13 @@ const UserProfile = {
destroyed () {
this.$store.dispatch('stopFetching', 'user')
},
- data () {
- return {
- favorites: emptyTl({ type: 'favorites', userId: this.userId })
- }
- },
computed: {
timeline () {
return this.$store.state.statuses.timelines.user
},
+ favorites () {
+ return this.$store.state.statuses.timelines.favorites
+ },
userId () {
return this.$route.params.id || this.user.id
},
diff --git a/src/modules/api.js b/src/modules/api.js
index b85b24be..a61340c2 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: new Map(),
+ fetchers: {},
socket: null,
chatDisabled: false,
followRequests: []
@@ -15,10 +15,10 @@ const api = {
state.backendInteractor = backendInteractor
},
addFetcher (state, {timeline, fetcher}) {
- state.fetchers.set(timeline, fetcher)
+ state.fetchers[timeline] = fetcher
},
removeFetcher (state, {timeline}) {
- delete state.fetchers.delete(timeline)
+ delete state.fetchers[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.has(timeline)) {
+ if (!store.state.fetchers[timeline]) {
const fetcher = store.state.backendInteractor.startFetching({timeline, store, userId})
store.commit('addFetcher', {timeline, fetcher})
}
},
stopFetching (store, timeline) {
- const fetcher = store.state.fetchers.get(timeline)
+ const fetcher = store.state.fetchers[timeline]
window.clearInterval(fetcher)
store.commit('removeFetcher', {timeline})
},
diff --git a/src/modules/statuses.js b/src/modules/statuses.js
index baeef8bf..f976fa42 100644
--- a/src/modules/statuses.js
+++ b/src/modules/statuses.js
@@ -2,7 +2,7 @@ import { remove, slice, each, find, maxBy, minBy, merge, last, isArray } from 'l
import apiService from '../services/api/api.service.js'
// import parse from '../services/status_parser/status_parser.js'
-export const emptyTl = (tl, userId = 0) => (Object.assign(tl, {
+const emptyTl = () => ({
statuses: [],
statusesObject: {},
faves: [],
@@ -14,9 +14,9 @@ export const emptyTl = (tl, userId = 0) => (Object.assign(tl, {
loading: false,
followers: [],
friends: [],
- flushMarker: 0,
- userId
-}))
+ userId: 0,
+ flushMarker: 0
+})
export const defaultState = {
allStatuses: [],
@@ -33,13 +33,14 @@ export const defaultState = {
favorites: new Set(),
error: false,
timelines: {
- 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' })
+ mentions: emptyTl(),
+ public: emptyTl(),
+ user: emptyTl(),
+ favorites: emptyTl(),
+ publicAndExternal: emptyTl(),
+ friends: emptyTl(),
+ tag: emptyTl(),
+ dms: emptyTl()
}
}
@@ -100,7 +101,7 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
const allStatuses = state.allStatuses
const allStatusesObject = state.allStatusesObject
- const timelineObject = typeof timeline === 'object' ? timeline : state.timelines[timeline]
+ const timelineObject = state.timelines[timeline]
const maxNew = statuses.length > 0 ? maxBy(statuses, 'id').id : 0
const older = timeline && maxNew < timelineObject.maxId
@@ -297,7 +298,7 @@ export const mutations = {
addNewStatuses,
addNewNotifications,
showNewStatuses (state, { timeline }) {
- const oldTimeline = (typeof timeline === 'object' ? timeline : state.timelines[timeline])
+ const oldTimeline = (state.timelines[timeline])
oldTimeline.newStatusCount = 0
oldTimeline.visibleStatuses = slice(oldTimeline.statuses, 0, 50)
@@ -306,8 +307,7 @@ export const mutations = {
each(oldTimeline.visibleStatuses, (status) => { oldTimeline.visibleStatusesObject[status.id] = status })
},
clearTimeline (state, { timeline }) {
- const timelineObject = typeof timeline === 'object' ? timeline : state.timelines[timeline]
- emptyTl(timelineObject, timeline.userId)
+ state.timelines[timeline] = emptyTl()
},
setFavorited (state, { status, value }) {
const newStatus = state.allStatusesObject[status.id]
@@ -327,8 +327,7 @@ export const mutations = {
newStatus.deleted = true
},
setLoading (state, { timeline, value }) {
- const timelineObject = typeof timeline === 'object' ? timeline : state.timelines[timeline]
- timelineObject.loading = value
+ state.timelines[timeline].loading = value
},
setNsfw (state, { id, nsfw }) {
const newStatus = state.allStatusesObject[id]
@@ -349,8 +348,7 @@ export const mutations = {
})
},
queueFlush (state, { timeline, id }) {
- const timelineObject = typeof timeline === 'object' ? timeline : state.timelines[timeline]
- timelineObject.flushMarker = id
+ state.timelines[timeline].flushMarker = id
}
}
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
index 14a526ef..0e267276 100644
--- a/src/services/api/api.service.js
+++ b/src/services/api/api.service.js
@@ -327,11 +327,10 @@ const fetchTimeline = ({timeline, credentials, since = false, until = false, use
favorites: MASTODON_USER_FAVORITES_TIMELINE_URL,
tag: TAG_TIMELINE_URL
}
- const type = timeline.type || timeline
- const isNotifications = type === 'notifications'
+ const isNotifications = timeline === 'notifications'
const params = []
- let url = timelineUrls[type]
+ let url = timelineUrls[timeline]
if (since) {
params.push(['since_id', since])
diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js
index 126e07cf..727f6c60 100644
--- a/src/services/timeline_fetcher/timeline_fetcher.service.js
+++ b/src/services/timeline_fetcher/timeline_fetcher.service.js
@@ -3,7 +3,7 @@ import { camelCase } from 'lodash'
import apiService from '../api/api.service.js'
const update = ({store, statuses, timeline, showImmediately, userId}) => {
- const ccTimeline = typeof timeline === 'object' ? timeline : camelCase(timeline)
+ const ccTimeline = camelCase(timeline)
store.dispatch('setError', { value: false })
@@ -18,7 +18,7 @@ const update = ({store, statuses, timeline, showImmediately, userId}) => {
const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false, showImmediately = false, userId = false, tag = false, until}) => {
const args = { timeline, credentials }
const rootState = store.rootState || store.state
- const timelineData = typeof timeline === 'object' ? timeline : rootState.statuses.timelines[camelCase(timeline)]
+ const timelineData = rootState.statuses.timelines[camelCase(timeline)]
if (older) {
args['until'] = until || timelineData.minVisibleId