fix sw build
This commit is contained in:
parent
37f501108b
commit
c723977d90
6 changed files with 85 additions and 83 deletions
|
|
@ -7,7 +7,7 @@ import Timeago from 'src/components/timeago/timeago.vue'
|
|||
import UserAvatar from 'src/components/user_avatar/user_avatar.vue'
|
||||
import UserLink from 'src/components/user_link/user_link.vue'
|
||||
import UserPopover from 'src/components/user_popover/user_popover.vue'
|
||||
import { isStatusNotification } from '../../services/notification_utils/notification_utils.js'
|
||||
import { isStatusNotification } from '../../services/notification_utils/notification_utils_sw.js'
|
||||
import {
|
||||
highlightClass,
|
||||
highlightStyle,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { unescape as lodashUnescape } from 'lodash'
|
|||
import punycode from 'punycode.js'
|
||||
|
||||
import { fileType } from '../file_type/file_type.service.js'
|
||||
import { isStatusNotification } from '../notification_utils/notification_utils.js'
|
||||
import { isStatusNotification } from '../notification_utils/notification_utils_sw.js'
|
||||
|
||||
/** NOTICE! **
|
||||
* Do not initialize UI-generated data here.
|
||||
|
|
|
|||
|
|
@ -1,18 +1,15 @@
|
|||
import { showDesktopNotification } from '../desktop_notification_utils/desktop_notification_utils.js'
|
||||
import { muteFilterHits } from '../status_parser/status_parser.js'
|
||||
import { prepareNotificationObject, isStatusNotification } from './notification_utils_sw.js'
|
||||
|
||||
import { useNotificationsStore } from 'src/stores/notifications.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
|
||||
|
||||
const visibleTypes = (notificationVisibility) => {
|
||||
return [
|
||||
notificationVisibility.likes && 'like',
|
||||
|
|
@ -28,17 +25,6 @@ const visibleTypes = (notificationVisibility) => {
|
|||
].filter(Boolean)
|
||||
}
|
||||
|
||||
const statusNotifications = new Set([
|
||||
'like',
|
||||
'mention',
|
||||
'status',
|
||||
'repeat',
|
||||
'pleroma:emoji_reaction',
|
||||
'poll',
|
||||
])
|
||||
|
||||
export const isStatusNotification = (type) => statusNotifications.has(type)
|
||||
|
||||
export const isValidNotification = (notification) => {
|
||||
if (isStatusNotification(notification.type) && !notification.status) {
|
||||
return false
|
||||
|
|
@ -108,70 +94,6 @@ export const unseenNotifications = (
|
|||
)
|
||||
}
|
||||
|
||||
export const prepareNotificationObject = (notification, i18n) => {
|
||||
if (cachedBadgeUrl === null) {
|
||||
const favicons = FaviconService.getOriginalFavicons()
|
||||
const favicon = favicons[favicons.length - 1]
|
||||
if (!favicon) {
|
||||
cachedBadgeUrl = 'about:blank'
|
||||
} else {
|
||||
cachedBadgeUrl = favicon.favimg.src
|
||||
}
|
||||
}
|
||||
|
||||
const notifObj = {
|
||||
tag: notification.id,
|
||||
type: notification.type,
|
||||
badge: cachedBadgeUrl,
|
||||
}
|
||||
const status = notification.status
|
||||
const title = notification.from_profile.name
|
||||
notifObj.title = title
|
||||
notifObj.icon = notification.from_profile.profile_image_url
|
||||
let i18nString
|
||||
switch (notification.type) {
|
||||
case 'like':
|
||||
i18nString = 'favorited_you'
|
||||
break
|
||||
case 'status':
|
||||
i18nString = 'subscribed_status'
|
||||
break
|
||||
case 'repeat':
|
||||
i18nString = 'repeated_you'
|
||||
break
|
||||
case 'follow':
|
||||
i18nString = 'followed_you'
|
||||
break
|
||||
case 'move':
|
||||
i18nString = 'migrated_to'
|
||||
break
|
||||
case 'follow_request':
|
||||
i18nString = 'follow_request'
|
||||
break
|
||||
case 'pleroma:report':
|
||||
i18nString = 'submitted_report'
|
||||
break
|
||||
case 'poll':
|
||||
i18nString = 'poll_ended'
|
||||
break
|
||||
}
|
||||
|
||||
if (notification.type === 'pleroma:emoji_reaction') {
|
||||
notifObj.body = i18n.t('notifications.reacted_with', [notification.emoji])
|
||||
} else if (i18nString) {
|
||||
notifObj.body = i18n.t('notifications.' + i18nString)
|
||||
} else if (isStatusNotification(notification.type)) {
|
||||
notifObj.body = notification.status.text
|
||||
}
|
||||
|
||||
// Shows first attached non-nsfw image, if any. Should add configuration for this somehow...
|
||||
if (!status.nsfw && status?.attachments?.[0]?.mimetype.startsWith('image/')) {
|
||||
notifObj.image = status.attachments[0].url
|
||||
}
|
||||
|
||||
return notifObj
|
||||
}
|
||||
|
||||
export const countExtraNotifications = (
|
||||
store,
|
||||
mergedConfig,
|
||||
|
|
|
|||
78
src/services/notification_utils/notification_utils_sw.js
Normal file
78
src/services/notification_utils/notification_utils_sw.js
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
import FaviconService from 'src/services/favicon_service/favicon_service.js'
|
||||
|
||||
const statusNotifications = new Set([
|
||||
'like',
|
||||
'mention',
|
||||
'status',
|
||||
'repeat',
|
||||
'pleroma:emoji_reaction',
|
||||
'poll',
|
||||
])
|
||||
|
||||
let cachedBadgeUrl = null
|
||||
|
||||
export const isStatusNotification = (type) => statusNotifications.has(type)
|
||||
|
||||
export const prepareNotificationObject = (notification, i18n) => {
|
||||
if (cachedBadgeUrl === null) {
|
||||
const favicons = FaviconService.getOriginalFavicons()
|
||||
const favicon = favicons[favicons.length - 1]
|
||||
if (!favicon) {
|
||||
cachedBadgeUrl = 'about:blank'
|
||||
} else {
|
||||
cachedBadgeUrl = favicon.favimg.src
|
||||
}
|
||||
}
|
||||
|
||||
const notifObj = {
|
||||
tag: notification.id,
|
||||
type: notification.type,
|
||||
badge: cachedBadgeUrl,
|
||||
}
|
||||
const status = notification.status
|
||||
const title = notification.from_profile.name
|
||||
notifObj.title = title
|
||||
notifObj.icon = notification.from_profile.profile_image_url
|
||||
let i18nString
|
||||
switch (notification.type) {
|
||||
case 'like':
|
||||
i18nString = 'favorited_you'
|
||||
break
|
||||
case 'status':
|
||||
i18nString = 'subscribed_status'
|
||||
break
|
||||
case 'repeat':
|
||||
i18nString = 'repeated_you'
|
||||
break
|
||||
case 'follow':
|
||||
i18nString = 'followed_you'
|
||||
break
|
||||
case 'move':
|
||||
i18nString = 'migrated_to'
|
||||
break
|
||||
case 'follow_request':
|
||||
i18nString = 'follow_request'
|
||||
break
|
||||
case 'pleroma:report':
|
||||
i18nString = 'submitted_report'
|
||||
break
|
||||
case 'poll':
|
||||
i18nString = 'poll_ended'
|
||||
break
|
||||
}
|
||||
|
||||
if (notification.type === 'pleroma:emoji_reaction') {
|
||||
notifObj.body = i18n.t('notifications.reacted_with', [notification.emoji])
|
||||
} else if (i18nString) {
|
||||
notifObj.body = i18n.t('notifications.' + i18nString)
|
||||
} else if (isStatusNotification(notification.type)) {
|
||||
notifObj.body = notification.status.text
|
||||
}
|
||||
|
||||
// Shows first attached non-nsfw image, if any. Should add configuration for this somehow...
|
||||
if (!status.nsfw && status?.attachments?.[0]?.mimetype.startsWith('image/')) {
|
||||
notifObj.image = status.attachments[0].url
|
||||
}
|
||||
|
||||
return notifObj
|
||||
}
|
||||
|
|
@ -5,10 +5,12 @@ import {
|
|||
closeDesktopNotification,
|
||||
} from '../services/desktop_notification_utils/desktop_notification_utils.js'
|
||||
import {
|
||||
isStatusNotification,
|
||||
isValidNotification,
|
||||
maybeShowNotification,
|
||||
} from '../services/notification_utils/notification_utils.js'
|
||||
import {
|
||||
isStatusNotification,
|
||||
} from '../services/notification_utils/notification_utils_sw.js'
|
||||
|
||||
import { useI18nStore } from 'src/stores/i18n.js'
|
||||
import { useMergedConfigStore } from 'src/stores/merged_config.js'
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import { createI18n } from 'vue-i18n'
|
|||
import { storage } from 'src/lib/storage.js'
|
||||
import { INSTANCE_DEFAULT_CONFIG } from 'src/modules/default_config_state.js'
|
||||
import { parseNotification } from 'src/services/entity_normalizer/entity_normalizer.service.js'
|
||||
import { prepareNotificationObject } from 'src/services/notification_utils/notification_utils.js'
|
||||
import { prepareNotificationObject } from 'src/services/notification_utils/notification_utils_sw.js'
|
||||
import { cacheKey, emojiCacheKey, shouldCache } from 'src/services/sw/sw.js'
|
||||
|
||||
// Collects all messages for service workers
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue