Merge branch 'notifications-thru-sw' into shigusegubu-vue3

This commit is contained in:
Henry Jameson 2023-11-20 00:17:23 +02:00
commit ea274e2364
3 changed files with 49 additions and 47 deletions

View file

@ -8,7 +8,8 @@ import {
notificationsFromStore, notificationsFromStore,
filteredNotificationsFromStore, filteredNotificationsFromStore,
unseenNotificationsFromStore, unseenNotificationsFromStore,
countExtraNotifications countExtraNotifications,
ACTIONABLE_NOTIFICATION_TYPES
} from '../../services/notification_utils/notification_utils.js' } from '../../services/notification_utils/notification_utils.js'
import FaviconService from '../../services/favicon_service/favicon_service.js' import FaviconService from '../../services/favicon_service/favicon_service.js'
import { library } from '@fortawesome/fontawesome-svg-core' import { library } from '@fortawesome/fontawesome-svg-core'
@ -21,7 +22,6 @@ library.add(
) )
const DEFAULT_SEEN_TO_DISPLAY_COUNT = 30 const DEFAULT_SEEN_TO_DISPLAY_COUNT = 30
const ACTIONABLE_NOTIFICATION_TYPES = new Set(['mention', 'pleroma:report', 'follow_request'])
const Notifications = { const Notifications = {
components: { components: {
@ -85,11 +85,7 @@ const Notifications = {
return `${this.unseenCount ? this.unseenCount : ''}${this.extraNotificationsCount ? '*' : ''}` return `${this.unseenCount ? this.unseenCount : ''}${this.extraNotificationsCount ? '*' : ''}`
}, },
unseenCount () { unseenCount () {
if (this.ignoreInactionableSeen) {
return this.unseenNotifications.filter(n => ACTIONABLE_NOTIFICATION_TYPES.has(n.type)).length
} else {
return this.unseenNotifications.length return this.unseenNotifications.length
}
}, },
ignoreInactionableSeen () { return this.$store.getters.mergedConfig.ignoreInactionableSeen }, ignoreInactionableSeen () { return this.$store.getters.mergedConfig.ignoreInactionableSeen },
extraNotificationsCount () { extraNotificationsCount () {

View file

@ -1,9 +1,10 @@
import { filter, includes } from 'lodash'
import { muteWordHits } from '../status_parser/status_parser.js' import { muteWordHits } from '../status_parser/status_parser.js'
import { showDesktopNotification } from '../desktop_notification_utils/desktop_notification_utils.js' import { showDesktopNotification } from '../desktop_notification_utils/desktop_notification_utils.js'
import FaviconService from 'src/services/favicon_service/favicon_service.js' import FaviconService from 'src/services/favicon_service/favicon_service.js'
export const ACTIONABLE_NOTIFICATION_TYPES = new Set(['mention', 'pleroma:report', 'follow_request'])
let cachedBadgeUrl = null let cachedBadgeUrl = null
export const notificationsFromStore = store => store.state.notifications.data export const notificationsFromStore = store => store.state.notifications.data
@ -24,9 +25,9 @@ export const visibleTypes = store => {
].filter(_ => _)) ].filter(_ => _))
} }
const statusNotifications = ['like', 'mention', 'repeat', 'pleroma:emoji_reaction', 'poll'] const statusNotifications = new Set(['like', 'mention', 'repeat', 'pleroma:emoji_reaction', 'poll'])
export const isStatusNotification = (type) => includes(statusNotifications, type) export const isStatusNotification = (type) => statusNotifications.has(type)
export const isValidNotification = (notification) => { export const isValidNotification = (notification) => {
if (isStatusNotification(notification.type) && !notification.status) { if (isStatusNotification(notification.type) && !notification.status) {
@ -76,16 +77,25 @@ export const filteredNotificationsFromStore = (store, types) => {
) )
} }
export const unseenNotificationsFromStore = store => export const unseenNotificationsFromStore = store => {
filter(filteredNotificationsFromStore(store), ({ seen }) => !seen) const ignoreInactionableSeen = store.getters.mergedConfig.ignoreInactionableSeen
return filteredNotificationsFromStore(store).filter(({ seen, type }) => {
if (!ignoreInactionableSeen) return !seen
if (seen) return false
return ACTIONABLE_NOTIFICATION_TYPES.has(type)
})
}
export const prepareNotificationObject = (notification, i18n) => { export const prepareNotificationObject = (notification, i18n) => {
if (cachedBadgeUrl === null) { if (cachedBadgeUrl === null) {
const favicon = FaviconService.getOriginalFavicons()[0] const favicon = FaviconService.getOriginalFavicons()[0]
console.log('TEST FAVICON', favicon)
if (!favicon) { if (!favicon) {
cachedBadgeUrl = 'about:blank' cachedBadgeUrl = 'about:blank'
} else { } else {
cachedBadgeUrl = favicon.favimg.href cachedBadgeUrl = favicon.favimg.href
console.log('TEST FAVICON', cachedBadgeUrl)
} }
} }

View file

@ -5,7 +5,6 @@ describe('NotificationUtils', () => {
it('should return sorted notifications with configured types', () => { it('should return sorted notifications with configured types', () => {
const store = { const store = {
state: { state: {
statuses: {
notifications: { notifications: {
data: [ data: [
{ {
@ -24,7 +23,6 @@ describe('NotificationUtils', () => {
type: 'repeat' type: 'repeat'
} }
] ]
}
}, },
config: { config: {
notificationVisibility: { notificationVisibility: {
@ -55,7 +53,6 @@ describe('NotificationUtils', () => {
it('should return only notifications not marked as seen', () => { it('should return only notifications not marked as seen', () => {
const store = { const store = {
state: { state: {
statuses: {
notifications: { notifications: {
data: [ data: [
{ {
@ -69,7 +66,6 @@ describe('NotificationUtils', () => {
seen: true seen: true
} }
] ]
}
}, },
config: { config: {
notificationVisibility: { notificationVisibility: {