fix push notification delivery on android
This commit is contained in:
+1
-1
@@ -50,7 +50,7 @@ CREATE TABLE IF NOT EXISTS public.users
|
||||
email character varying(255) COLLATE pg_catalog."default" NOT NULL,
|
||||
password character varying(255) COLLATE pg_catalog."default" NOT NULL,
|
||||
reg_time timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
notification_type character varying(255) COLLATE pg_catalog."default" NOT NULL DEFAULT 'NO_NOTIFICATION'::character varying,
|
||||
notification_type character varying(255) COLLATE pg_catalog."default" NOT NULL DEFAULT 'PUSH_NOTIFICATION'::character varying,
|
||||
CONSTRAINT users_pkey PRIMARY KEY (id),
|
||||
CONSTRAINT unique_email UNIQUE (email)
|
||||
);
|
||||
|
||||
@@ -24,8 +24,20 @@ public class NotificationService {
|
||||
|
||||
for (DeviceToken token : tokens) {
|
||||
|
||||
// Include a notification block so Android's system tray displays it
|
||||
// even when the app is killed/dozing (a data-only message is only
|
||||
// ever shown by the app's own JS handler, which won't run when the
|
||||
// OS has force-stopped the app). HIGH priority tells FCM to deliver
|
||||
// promptly and wake the device out of Doze.
|
||||
Message message = Message.builder()
|
||||
.setToken(token.getFcmToken())
|
||||
.setNotification(Notification.builder()
|
||||
.setTitle(title)
|
||||
.setBody(body)
|
||||
.build())
|
||||
.setAndroidConfig(AndroidConfig.builder()
|
||||
.setPriority(AndroidConfig.Priority.HIGH)
|
||||
.build())
|
||||
.putData("title", title)
|
||||
.putData("body", body)
|
||||
.build();
|
||||
|
||||
@@ -74,6 +74,11 @@ public class SubjectService {
|
||||
@Async
|
||||
public void notifyAsync(Entry entry) {
|
||||
|
||||
// The scraper couldn't always match an announcement to a known subject, in
|
||||
// which case there's nobody to notify. Guard against the NPE that would
|
||||
// otherwise be thrown (and silently swallowed) on this async thread.
|
||||
if (entry.getSubject() == null) return;
|
||||
|
||||
List<User> users =
|
||||
userService.findUsersBySubjectId(entry.getSubject().getId());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user