summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/message/app.rs4
-rw-r--r--ui/service-worker.js44
2 files changed, 26 insertions, 22 deletions
diff --git a/src/message/app.rs b/src/message/app.rs
index 8200650..b79dad0 100644
--- a/src/message/app.rs
+++ b/src/message/app.rs
@@ -10,7 +10,7 @@ use crate::{
db,
db::NotFound as _,
error::failed::{Failed, ResultExt as _},
- event::{Broadcaster, Sequence, repo::Provider as _},
+ event::{Broadcaster, Event, Sequence, repo::Provider as _},
login::Login,
push::{Publish, repo::Provider as _},
user::{self, repo::Provider as _},
@@ -186,7 +186,7 @@ where
for event in events {
let failures = self
.publisher
- .publish(event, &signer, &push_recipients)
+ .publish(Event::from(event), &signer, &push_recipients)
.await
.fail("Failed to publish push events")?;
diff --git a/ui/service-worker.js b/ui/service-worker.js
index 391705c..81d0752 100644
--- a/ui/service-worker.js
+++ b/ui/service-worker.js
@@ -26,26 +26,30 @@ function countUnreadChannels() {
}
self.addEventListener('push', (event) => {
- // Let's show a notification right away so Safari doesn't tell Apple to be
- // mad at us:
- event.waitUntil(
- self.registration.showNotification('Test notification', {
- actions: [],
- body: event.data.text(),
- }),
- );
+ const data = event.data.json();
+ if (data.type === 'heartbeat') {
+ // Let's show a notification right away so Safari doesn't tell Apple to be
+ // mad at us:
+ event.waitUntil(
+ self.registration.showNotification('Test notification', {
+ actions: [],
+ body: event.data.text(),
+ }),
+ );
+ }
- const data = event.data?.json();
- // Now we can do slower things that might fail:
- conversationReadStatus[data.conversation] ||= { lastRead: null, lastMessage: null };
- conversationReadStatus[data.conversation].lastMessage = new Date();
- event.waitUntil(
- (async () => {
- if (navigator.setAppBadge) {
- navigator.setAppBadge(countUnreadChannels());
- }
- })(),
- );
+ if (data.type === 'message' && data.event === 'sent') {
+ // Now we can do slower things that might fail:
+ conversationReadStatus[data.conversation] ||= { lastRead: null, lastMessage: null };
+ conversationReadStatus[data.conversation].lastMessage = new Date();
+ event.waitUntil(
+ (async () => {
+ if (navigator.setAppBadge) {
+ await navigator.setAppBadge(countUnreadChannels());
+ }
+ })(),
+ );
+ }
});
// The client has to tell us when it has read a conversation:
@@ -62,7 +66,7 @@ self.addEventListener('message', (event) => {
event.waitUntil(
(async () => {
if (navigator.setAppBadge) {
- navigator.setAppBadge(countUnreadChannels());
+ await navigator.setAppBadge(countUnreadChannels());
}
})(),
);