Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85829168
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
7 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/modules/api.js b/src/modules/api.js
index e3d4632571..8a0081fc2b 100644
--- a/src/modules/api.js
+++ b/src/modules/api.js
@@ -1,70 +1,79 @@
import TimelineFetcher from '../services/timeline_fetcher/timeline_fetcher.service.js'
import NotificationsFetcher from '../services/notifications_fetcher/notifications_fetcher.service.js'
import ApiUtils from '../services/new_api/utils.js'
import parseLinkHeader from 'parse-link-header'
const Api = {
state: {
fetchers: {}
},
mutations: {
setFetcher (state, { fetcher, timelineName }) {
state.fetchers[timelineName] = fetcher
}
},
actions: {
async startFetchingNotifications ({ state, rootState, commit, dispatch }) {
if (state.fetchers['user_notifications']) {
return
}
const fetcher = await NotificationsFetcher.create({ state: rootState, commit, dispatch })
commit('setFetcher', { fetcher, timelineName: 'user_notifications' })
},
async startFetchingTimeline ({ state, rootState, commit, dispatch }, options) {
if (state.fetchers[options.timelineName]) {
return
}
const fetcher = await TimelineFetcher.create({ state: rootState, commit, dispatch }, options)
commit('setFetcher', { fetcher, timelineName: options.timelineName })
},
// TODO: DRY up.
async fetchPrevForTimeline ({ commit, rootState, dispatch }, { timelineName }) {
const store = { commit, state: rootState, dispatch }
const data = await ApiUtils.request({
store,
fullUrl: store.state.statuses.timelines[timelineName].links.prev.url
})
const statuses = await data.json()
const links = parseLinkHeader(data.headers.get('link'))
store.dispatch('addNewStatusesToTimeline', { statuses, timelineName })
// We don't always get new link headers.
if (links && links.prev) {
store.commit('setPrevLinkForTimeline', { link: links.prev, timelineName })
}
},
async fetchNextForTimeline ({ commit, rootState, dispatch }, { timelineName }) {
const store = { commit, state: rootState, dispatch }
+
+ // We don't want to fetch next if the previous fetching is still in progress
+ if (store.state.statuses.timelines[timelineName].loading) {
+ return
+ }
+
+ store.dispatch('startFetchingNextForTimeline', { timelineName })
+
const data = await ApiUtils.request({
store,
fullUrl: store.state.statuses.timelines[timelineName].links.next.url
})
const statuses = await data.json()
const links = parseLinkHeader(data.headers.get('link'))
store.dispatch('addNewStatusesToTimeline', { statuses, timelineName })
store.dispatch('showOldStatusesForTimeline', { timelineName, statuses })
// We don't always get new link headers.
if (links && links.next) {
store.commit('setNextLinkForTimeline', { link: links.next, timelineName })
}
+ store.dispatch('completeFetchingNextForTimeline', { timelineName })
},
stopFetchingTimeline ({ state, commit }, { timelineName }) {
const fetcher = state.fetchers[timelineName]
clearInterval(fetcher)
commit('setFetcher', { fetcher: false, timelineName })
}
}
}
export default Api
diff --git a/src/modules/statuses.js b/src/modules/statuses.js
index 6388c3b571..bae48c1bc0 100644
--- a/src/modules/statuses.js
+++ b/src/modules/statuses.js
@@ -1,104 +1,113 @@
import { take, filter, each, merge, clone, map, uniq } from 'lodash'
import Vue from 'vue'
const defaultTimeline = {
statusIds: [],
visibleStatusIds: [],
loading: false,
links: {},
newStatusCount: 0
}
const defaultState = {
statuses: {},
timelines: {},
contexts: {}
}
const statuses = {
state: defaultState,
mutations: {
addNewStatuses (state, newStatuses) {
each(newStatuses, (status) => {
Vue.set(state.statuses, status.id, merge(state.statuses[status.id] || {}, status))
})
},
addStatusesToTimeline (state, { timelineName, statusIds }) {
let timeline = state.timelines[timelineName]
// Dynamically create timeline if we don't have it yet.
if (!timeline) {
timeline = clone(defaultTimeline)
Vue.set(state.timelines, timelineName, timeline)
}
// Prepend the new statusIds before the old ones.
timeline.statusIds = uniq(statusIds.concat(timeline.statusIds))
timeline.newStatusCount = timeline.newStatusCount + statusIds.length
},
setVisibleStatusesForTimeline (state, { timelineName, statusIds }) {
const timeline = state.timelines[timelineName]
timeline.visibleStatusIds = statusIds
timeline.newStatusCount = 0
},
setContext (state, { id, context }) {
Vue.set(state.contexts, id, context)
},
setPrevLinkForTimeline (state, { link, timelineName }) {
const timeline = state.timelines[timelineName]
timeline.links = { ...(timeline.links || {}), prev: link }
},
setNextLinkForTimeline (state, { link, timelineName }) {
const timeline = state.timelines[timelineName]
timeline.links = { ...(timeline.links || {}), next: link }
+ },
+ setTimelineLoading (state, { timelineName, loading }) {
+ state.timelines[timelineName].loading = loading
}
},
actions: {
// Makes all availabe statuses visible. Should maybe be restricted.
showNewStatusesForTimeline ({ commit, state }, { timelineName }) {
const timeline = state.timelines[timelineName]
commit('setVisibleStatusesForTimeline', { timelineName, statusIds: clone(take(timeline.statusIds, 100)) })
},
showOldStatusesForTimeline ({ commit, state }, { timelineName, statuses }) {
const timeline = state.timelines[timelineName]
const statusIds = map(statuses, 'id')
commit('setVisibleStatusesForTimeline', { timelineName, statusIds: [...timeline.visibleStatusIds, ...statusIds] })
},
addNewStatus ({ commit, state }, { status }) {
commit('addNewUsers', [status.account])
commit('addNewStatuses', [status])
if (status.reblog) {
commit('addNewUsers', [status.reblog.account])
commit('addNewStatuses', [status.reblog])
}
},
addNewStatusesToTimeline ({ commit, state, dispatch }, { statuses, timelineName, showImmediately = false }) {
const newUsers = map(statuses, 'account')
commit('addNewUsers', newUsers)
const reblogs = map(filter(statuses, 'reblog'), 'reblog')
commit('addNewStatuses', reblogs)
const newRebloggedUsers = map(reblogs, 'account')
commit('addNewUsers', newRebloggedUsers)
commit('addNewStatuses', statuses)
const statusIds = map(statuses, 'id')
commit('addStatusesToTimeline', { timelineName, statusIds })
if (showImmediately) {
commit('setVisibleStatusesForTimeline', { timelineName, statusIds })
}
dispatch('fetchMissingRepliedUsers', { statuses })
},
addNewStatusesToContext ({ commit, state }, { context, status }) {
const statuses = [...context.ancestors, ...context.descendants]
const newUsers = map(statuses, 'account')
commit('addNewUsers', newUsers)
commit('addNewStatuses', statuses)
const idContext = {
descendants: map(context.descendants, 'id'),
ancestors: map(context.ancestors, 'id')
}
commit('setContext', { id: status.id, context: idContext })
+ },
+ startFetchingNextForTimeline ({ commit }, { timelineName }) {
+ commit('setTimelineLoading', { timelineName, loading: true })
+ },
+ completeFetchingNextForTimeline ({ commit }, { timelineName }) {
+ commit('setTimelineLoading', { timelineName, loading: false })
}
}
}
export default statuses
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Oct 31, 4:09 PM (17 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1801574
Default Alt Text
(7 KB)
Attached To
Mode
rPUFE pleroma-fe-upstream
Attached
Detach File
Event Timeline