Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85630122
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/components/notifications/notifications.js b/src/components/notifications/notifications.js
index 650d23ec7e..c25bf74016 100644
--- a/src/components/notifications/notifications.js
+++ b/src/components/notifications/notifications.js
@@ -1,63 +1,59 @@
import Notification from '../notification/notification.vue'
-import notificationsFetcher from '../../services/notifications_fetcher/notifications_fetcher.service.js'
-import {
- unseenNotificationsFromStore
-} from '../../services/notification_utils/notification_utils.js'
import { map } from 'lodash'
const Notifications = {
created () {
this.$store.dispatch('startFetchingNotifications')
},
data () {
return {
bottomedOut: false
}
},
computed: {
error () {
// TODO: fix
return false
},
unseenNotifications () {
// TODO: fix
return []
},
visibleNotifications () {
const notifications = map(this.$store.state.notifications.visibleNotificationIds, (id) => {
return this.$store.state.notifications.notifications[id]
})
return notifications
},
unseenCount () {
return this.unseenNotifications.length
},
loading () {
// TODO: Fix
return false
}
},
components: {
Notification
},
watch: {
unseenCount (count) {
if (count > 0) {
this.$store.dispatch('setPageTitle', `(${count})`)
} else {
this.$store.dispatch('setPageTitle', '')
}
}
},
methods: {
markAsSeen () {
this.$store.dispatch('markNotificationsAsSeen', this.visibleNotifications)
},
fetchOlderNotifications () {
// TODO: Repair
}
}
}
export default Notifications
diff --git a/src/modules/api.js b/src/modules/api.js
index 3e21407401..ee11853012 100644
--- a/src/modules/api.js
+++ b/src/modules/api.js
@@ -1,70 +1,70 @@
import TimelineFetcher from '../services/timeline_fetcher/timeline_fetcher_two.service.js'
-import NotificationsFetcher from '../services/notifications_fetcher/notifications_fetcher_two.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 }
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 })
}
},
stopFetchingTimeline ({ state, commit }, { timelineName }) {
const fetcher = state.fetchers[timelineName]
clearInterval(fetcher)
commit('setFetcher', { fetcher: false, timelineName })
}
}
}
export default Api
diff --git a/src/services/notifications_fetcher/notifications_fetcher.service.js b/src/services/notifications_fetcher/notifications_fetcher.service.js
index 3ecdae6a78..42db803577 100644
--- a/src/services/notifications_fetcher/notifications_fetcher.service.js
+++ b/src/services/notifications_fetcher/notifications_fetcher.service.js
@@ -1,57 +1,11 @@
-import apiService from '../api/api.service.js'
+import Notifications from '../new_api/notifications.js'
-const update = ({store, notifications, older}) => {
- store.dispatch('setNotificationsError', { value: false })
-
- store.dispatch('addNewNotifications', { notifications, older })
-}
-
-const fetchAndUpdate = ({store, credentials, older = false}) => {
- const args = { credentials }
- const rootState = store.rootState || store.state
- const timelineData = rootState.statuses.notifications
-
- if (older) {
- if (timelineData.minId !== Number.POSITIVE_INFINITY) {
- args['until'] = timelineData.minId
- }
- } else {
- // load unread notifications repeadedly to provide consistency between browser tabs
- const notifications = timelineData.data
- const unread = notifications.filter(n => !n.seen).map(n => n.id)
- if (!unread.length) {
- args['since'] = timelineData.maxId
- } else {
- args['since'] = Math.min(...unread) - 1
- if (timelineData.maxId !== Math.max(...unread)) {
- args['until'] = Math.max(...unread, args['since'] + 20)
- }
- }
+const NotificationsFetcher = {
+ async create (store) {
+ const { notifications, links } = await Notifications.all({ store })
+ console.log(links)
+ store.dispatch('addNewNotificationsTwo', { notifications })
}
-
- args['timeline'] = 'notifications'
-
- return apiService.fetchTimeline(args)
- .then((notifications) => {
- update({store, notifications, older})
- return notifications
- }, () => store.dispatch('setNotificationsError', { value: true }))
- .catch(() => store.dispatch('setNotificationsError', { value: true }))
-}
-
-const startFetching = ({credentials, store}) => {
- fetchAndUpdate({ credentials, store })
- const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store })
- // Initially there's set flag to silence all desktop notifications so
- // that there won't spam of them when user just opened up the FE we
- // reset that flag after a while to show new notifications once again.
- setTimeout(() => store.dispatch('setNotificationsSilence', false), 10000)
- return setInterval(boundFetchAndUpdate, 10000)
-}
-
-const notificationsFetcher = {
- fetchAndUpdate,
- startFetching
}
-export default notificationsFetcher
+export default NotificationsFetcher
diff --git a/src/services/notifications_fetcher/notifications_fetcher_two.service.js b/src/services/notifications_fetcher/notifications_fetcher_two.service.js
deleted file mode 100644
index 42db803577..0000000000
--- a/src/services/notifications_fetcher/notifications_fetcher_two.service.js
+++ /dev/null
@@ -1,11 +0,0 @@
-import Notifications from '../new_api/notifications.js'
-
-const NotificationsFetcher = {
- async create (store) {
- const { notifications, links } = await Notifications.all({ store })
- console.log(links)
- store.dispatch('addNewNotificationsTwo', { notifications })
- }
-}
-
-export default NotificationsFetcher
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Aug 9, 10:09 AM (1 d, 15 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1724438
Default Alt Text
(8 KB)
Attached To
Mode
rPUFE pleroma-fe-upstream
Attached
Detach File
Event Timeline
Log In to Comment