Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pleroma-fe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pleroma
pleroma-fe
Commits
5b0190be
Commit
5b0190be
authored
4 years ago
by
lain
Browse files
Options
Downloads
Patches
Plain Diff
ServiceWorker: Grab the notification and display it with i18n.
parent
a52a3932
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!1217
2.1.0 into master
,
!1142
Notification unification / WebPush i18n.
Pipeline
#27093
passed
4 years ago
Stage: lint
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/sw.js
+68
-8
68 additions, 8 deletions
src/sw.js
with
68 additions
and
8 deletions
src/sw.js
+
68
−
8
View file @
5b0190be
/* eslint-env serviceworker */
import
localForage
from
'
localforage
'
import
{
parseNotification
}
from
'
./services/entity_normalizer/entity_normalizer.service.js
'
import
{
prepareNotificationObject
}
from
'
./services/notification_utils/notification_utils.js
'
import
Vue
from
'
vue
'
import
VueI18n
from
'
vue-i18n
'
const
messages
=
{
ar
:
require
(
'
./i18n/ar.json
'
),
ca
:
require
(
'
./i18n/ca.json
'
),
cs
:
require
(
'
./i18n/cs.json
'
),
de
:
require
(
'
./i18n/de.json
'
),
eo
:
require
(
'
./i18n/eo.json
'
),
es
:
require
(
'
./i18n/es.json
'
),
et
:
require
(
'
./i18n/et.json
'
),
eu
:
require
(
'
./i18n/eu.json
'
),
fi
:
require
(
'
./i18n/fi.json
'
),
fr
:
require
(
'
./i18n/fr.json
'
),
ga
:
require
(
'
./i18n/ga.json
'
),
he
:
require
(
'
./i18n/he.json
'
),
hu
:
require
(
'
./i18n/hu.json
'
),
it
:
require
(
'
./i18n/it.json
'
),
ja
:
require
(
'
./i18n/ja_pedantic.json
'
),
ja_easy
:
require
(
'
./i18n/ja_easy.json
'
),
ko
:
require
(
'
./i18n/ko.json
'
),
nb
:
require
(
'
./i18n/nb.json
'
),
nl
:
require
(
'
./i18n/nl.json
'
),
oc
:
require
(
'
./i18n/oc.json
'
),
pl
:
require
(
'
./i18n/pl.json
'
),
pt
:
require
(
'
./i18n/pt.json
'
),
ro
:
require
(
'
./i18n/ro.json
'
),
ru
:
require
(
'
./i18n/ru.json
'
),
te
:
require
(
'
./i18n/te.json
'
),
zh
:
require
(
'
./i18n/zh.json
'
),
en
:
require
(
'
./i18n/en.json
'
)
}
Vue
.
use
(
VueI18n
)
const
i18n
=
new
VueI18n
({
// By default, use the browser locale, we will update it if neccessary
locale
:
'
en
'
,
fallbackLocale
:
'
en
'
,
messages
})
function
isEnabled
()
{
return
localForage
.
getItem
(
'
vuex-lz
'
)
...
...
@@ -12,15 +54,33 @@ function getWindowClients () {
.
then
((
clientList
)
=>
clientList
.
filter
(({
type
})
=>
type
===
'
window
'
))
}
self
.
addEventListener
(
'
push
'
,
(
event
)
=>
{
if
(
event
.
data
)
{
event
.
waitUntil
(
isEnabled
().
then
((
isEnabled
)
=>
{
return
isEnabled
&&
getWindowClients
().
then
((
list
)
=>
{
const
data
=
event
.
data
.
json
()
const
setLocale
=
async
()
=>
{
const
state
=
await
localForage
.
getItem
(
'
vuex-lz
'
)
const
locale
=
state
.
config
.
interfaceLanguage
||
'
en
'
i18n
.
locale
=
locale
}
const
maybeShowNotification
=
async
(
event
)
=>
{
const
enabled
=
await
isEnabled
()
const
activeClients
=
await
getWindowClients
()
await
setLocale
()
if
(
enabled
&&
activeClients
)
{
const
data
=
event
.
data
.
json
()
if
(
list
.
length
===
0
)
return
self
.
registration
.
showNotification
(
data
.
title
,
data
)
})
}))
const
url
=
`
${
self
.
registration
.
scope
}
api/v1/notifications/
${
data
.
notification_id
}
`
const
notification
=
await
fetch
(
url
,
{
headers
:
{
Authorization
:
'
Bearer
'
+
data
.
access_token
}
})
let
nj
=
await
notification
.
json
()
nj
=
parseNotification
(
nj
)
const
res
=
prepareNotificationObject
(
nj
,
i18n
)
self
.
registration
.
showNotification
(
res
.
title
,
res
)
}
}
self
.
addEventListener
(
'
push
'
,
async
(
event
)
=>
{
if
(
event
.
data
)
{
event
.
waitUntil
(
maybeShowNotification
(
event
))
}
})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment