1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2024-12-26 08:44:36 +01:00
Whalebird-desktop-client-ma.../renderer/utils/notification.ts

75 lines
2.6 KiB
TypeScript
Raw Normal View History

2023-11-09 15:29:10 +01:00
import sanitizeHtml from 'sanitize-html'
import { Entity } from 'megalodon'
import { MessageDescriptor } from 'react-intl'
const generateNotification = (
notification: Entity.Notification,
formatMessage: (descriptor: MessageDescriptor, values?: any, opts?: any) => string
): [string, string] => {
switch (notification.type) {
case 'follow':
return [
2023-12-02 03:50:42 +01:00
formatMessage({ id: 'notification.follow.title' }),
formatMessage({ id: 'notification.follow.body' }, { user: notification.account.acct })
2023-11-09 15:29:10 +01:00
]
case 'follow_request':
return [
2023-12-02 03:50:42 +01:00
formatMessage({ id: 'notification.follow_request.title' }),
formatMessage({ id: 'notification.follow_requested.body' }, { user: notification.account.acct })
2023-11-09 15:29:10 +01:00
]
case 'favourite':
return [
2023-12-02 03:50:42 +01:00
formatMessage({ id: 'notification.favourite.title' }),
formatMessage({ id: 'notification.favourite.body' }, { user: notification.account.acct })
2023-11-09 15:29:10 +01:00
]
case 'reblog':
return [
2023-12-02 03:50:42 +01:00
formatMessage({ id: 'notification.reblog.title' }),
formatMessage({ id: 'notification.reblog.body' }, { user: notification.account.acct })
2023-11-09 15:29:10 +01:00
]
case 'poll_expired':
return [
2023-12-02 03:50:42 +01:00
formatMessage({ id: 'notification.poll_expired.title' }),
formatMessage({ id: 'notification.poll_expired.body' }, { user: notification.account.acct })
2023-11-09 15:29:10 +01:00
]
case 'poll_vote':
return [
2023-12-02 03:50:42 +01:00
formatMessage({ id: 'notification.poll_vote.title' }),
formatMessage({ id: 'notification.poll_vote.body' }, { user: notification.account.acct })
2023-11-09 15:29:10 +01:00
]
case 'quote':
return [
2023-12-02 03:50:42 +01:00
formatMessage({ id: 'notification.quote.title' }),
formatMessage({ id: 'notification.quote.body' }, { user: notification.account.acct })
2023-11-09 15:29:10 +01:00
]
case 'status':
return [
2023-12-02 03:50:42 +01:00
formatMessage({ id: 'notification.status.title' }),
formatMessage({ id: 'notification.status.body' }, { user: notification.account.acct })
2023-11-09 15:29:10 +01:00
]
case 'update':
return [
2023-12-02 03:50:42 +01:00
formatMessage({ id: 'notification.update.title' }),
formatMessage({ id: 'notification.update.body' }, { user: notification.account.acct })
2023-11-09 15:29:10 +01:00
]
case 'emoji_reaction':
case 'reaction':
return [
2023-12-02 03:50:42 +01:00
formatMessage({ id: 'notification.emoji_reaction.title' }),
formatMessage({ id: 'notification.emoji_reaction.body' }, { user: notification.account.acct })
2023-11-09 15:29:10 +01:00
]
case 'mention':
return [
`${notification.account.acct}`,
sanitizeHtml(notification.status!.content, {
allowedTags: [],
allowedAttributes: false
})
]
default:
return ['', '']
}
}
export default generateNotification