2018-04-09 10:44:37 -07:00
|
|
|
import Notification from '../notification/notification.vue'
|
2018-08-12 04:14:34 -07:00
|
|
|
import notificationsFetcher from '../../services/notifications_fetcher/notifications_fetcher.service.js'
|
2017-05-31 01:47:18 -07:00
|
|
|
|
2018-08-16 03:57:16 -07:00
|
|
|
import { sortBy, filter } from 'lodash'
|
2016-11-27 10:44:56 -08:00
|
|
|
|
|
|
|
const Notifications = {
|
2018-12-10 12:12:51 -08:00
|
|
|
props: [ 'activatePanel' ],
|
2018-08-12 04:14:34 -07:00
|
|
|
created () {
|
|
|
|
const store = this.$store
|
|
|
|
const credentials = store.state.users.currentUser.credentials
|
|
|
|
|
|
|
|
notificationsFetcher.startFetching({ store, credentials })
|
2016-11-27 10:44:56 -08:00
|
|
|
},
|
|
|
|
computed: {
|
2018-08-28 11:21:29 -07:00
|
|
|
visibleTypes () {
|
|
|
|
return [
|
|
|
|
this.$store.state.config.notificationVisibility.likes && 'like',
|
|
|
|
this.$store.state.config.notificationVisibility.mentions && 'mention',
|
|
|
|
this.$store.state.config.notificationVisibility.repeats && 'repeat',
|
|
|
|
this.$store.state.config.notificationVisibility.follows && 'follow'
|
|
|
|
].filter(_ => _)
|
|
|
|
},
|
2017-02-18 11:42:00 -08:00
|
|
|
notifications () {
|
2018-08-12 04:14:34 -07:00
|
|
|
return this.$store.state.statuses.notifications.data
|
2017-02-18 11:42:00 -08:00
|
|
|
},
|
2018-08-20 10:45:54 -07:00
|
|
|
error () {
|
|
|
|
return this.$store.state.statuses.notifications.error
|
|
|
|
},
|
2017-02-18 11:42:00 -08:00
|
|
|
unseenNotifications () {
|
2018-08-28 11:21:29 -07:00
|
|
|
return filter(this.visibleNotifications, ({seen}) => !seen)
|
2017-02-18 11:42:00 -08:00
|
|
|
},
|
2016-11-27 10:44:56 -08:00
|
|
|
visibleNotifications () {
|
2017-02-18 11:42:00 -08:00
|
|
|
// Don't know why, but sortBy([seen, -action.id]) doesn't work.
|
|
|
|
let sortedNotifications = sortBy(this.notifications, ({action}) => -action.id)
|
|
|
|
sortedNotifications = sortBy(sortedNotifications, 'seen')
|
2018-08-28 11:21:29 -07:00
|
|
|
return sortedNotifications.filter((notification) => this.visibleTypes.includes(notification.type))
|
2017-02-18 11:42:00 -08:00
|
|
|
},
|
|
|
|
unseenCount () {
|
|
|
|
return this.unseenNotifications.length
|
|
|
|
}
|
|
|
|
},
|
2017-05-31 01:47:18 -07:00
|
|
|
components: {
|
2018-04-09 10:44:37 -07:00
|
|
|
Notification
|
2017-05-31 01:47:18 -07:00
|
|
|
},
|
2017-02-18 11:42:00 -08:00
|
|
|
watch: {
|
|
|
|
unseenCount (count) {
|
2017-02-19 03:19:47 -08:00
|
|
|
if (count > 0) {
|
|
|
|
this.$store.dispatch('setPageTitle', `(${count})`)
|
|
|
|
} else {
|
|
|
|
this.$store.dispatch('setPageTitle', '')
|
|
|
|
}
|
2017-02-18 11:42:00 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
markAsSeen () {
|
2018-12-02 02:36:11 -08:00
|
|
|
this.$store.dispatch('markNotificationsAsSeen', this.visibleNotifications)
|
2018-08-12 04:14:34 -07:00
|
|
|
},
|
|
|
|
fetchOlderNotifications () {
|
|
|
|
const store = this.$store
|
|
|
|
const credentials = store.state.users.currentUser.credentials
|
|
|
|
notificationsFetcher.fetchAndUpdate({
|
|
|
|
store,
|
|
|
|
credentials,
|
|
|
|
older: true
|
|
|
|
})
|
2016-11-27 10:44:56 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Notifications
|