Simplify push notification flow by using locally stored values for pending pushes (#6258)
* Create `PushRequest` in push history DB: this will be used to store requests for push notifications, either pending or completed ones. * Rename `WorkManagerRequest` to `WorkManagerRequestBuilder`: make its `build` method return a list of `WorkManagerRequestWrapper`, which can be used to enqueue normal or unique workers. * Rename `PerformDatabaseVacuumRequestBuilder` and adapt it to the new API. * Adjust other components using `WorkManagerRequest`. * Replace `SyncNotificationWorkManagerRequestBuilder` with `SyncPendingNotificationsRequestBuilder` and `FetchNotificationsWorker` with `FetchPendingNotificationsWorker`: this new pair of request builder and worker allow enqueuing requests for a session id and, once the worker runs, retrieve all the pending request data and use it to fetch the associated events. This simplifies quite a bit how this data had to be passed or grouped, since it's no longer necessary to do so * Add new methods to `PushHistoryService` to modify the `PushDatabase`: - insertOrUpdatePushRequest - insertOrUpdatePushRequests - getPendingPushRequests - removeOldPushRequests * Make `PushHandler` just handle incoming pushes: those will be inserted into the pending push request table in DB, then handled by the new worker. Once the process finished, a new `NotificationResultProcessor` will handle the results and what needs to be done with them (call ringing, displaying notifications, etc.) * Add `requestType` optional parameter to `WorkManagerScheduler.cancel` so we can decide to only cancel some kinds of requests. * Add migration to remove existing work manager requests for fetching notifications, since the previous worker class no longer exists.
This commit is contained in:
parent
a8c66381f2
commit
721add707c
48 changed files with 1715 additions and 1892 deletions
BIN
libraries/push/impl/src/main/sqldelight/databases/1.db
Normal file
BIN
libraries/push/impl/src/main/sqldelight/databases/1.db
Normal file
Binary file not shown.
BIN
libraries/push/impl/src/main/sqldelight/databases/2.db
Normal file
BIN
libraries/push/impl/src/main/sqldelight/databases/2.db
Normal file
Binary file not shown.
|
|
@ -17,6 +17,5 @@ INSERT INTO PushHistory VALUES ?;
|
|||
removeAll:
|
||||
DELETE FROM PushHistory;
|
||||
|
||||
-- add query to keep only the last x entries
|
||||
removeOldest:
|
||||
DELETE FROM PushHistory WHERE rowid NOT IN (SELECT rowid FROM PushHistory ORDER BY pushDate DESC LIMIT ?);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
CREATE TABLE PushRequest (
|
||||
pushDate INTEGER NOT NULL,
|
||||
providerInfo TEXT NOT NULL,
|
||||
eventId TEXT NOT NULL,
|
||||
roomId TEXT NOT NULL,
|
||||
sessionId TEXT NOT NULL,
|
||||
status INTEGER NOT NULL DEFAULT 0,
|
||||
retries INTEGER NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY(sessionId, eventId)
|
||||
);
|
||||
|
||||
CREATE INDEX PushRequestSessionAndStatus ON PushRequest (sessionId, status);
|
||||
|
||||
selectAllPendingForSession:
|
||||
SELECT * FROM PushRequest WHERE status = 0 AND sessionId = ? AND pushDate > ? ORDER BY pushDate ASC;
|
||||
|
||||
insertPushRequest:
|
||||
INSERT OR REPLACE INTO PushRequest VALUES ?;
|
||||
|
||||
removeAll:
|
||||
DELETE FROM PushRequest;
|
||||
|
||||
removeOldest:
|
||||
DELETE FROM PushRequest WHERE rowid NOT IN (SELECT rowid FROM PushRequest ORDER BY pushDate DESC LIMIT ?);
|
||||
14
libraries/push/impl/src/main/sqldelight/migrations/1.sqm
Normal file
14
libraries/push/impl/src/main/sqldelight/migrations/1.sqm
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
-- Migrate DB from version 1
|
||||
|
||||
CREATE TABLE PushRequest (
|
||||
pushDate INTEGER NOT NULL,
|
||||
providerInfo TEXT NOT NULL,
|
||||
eventId TEXT NOT NULL,
|
||||
roomId TEXT NOT NULL,
|
||||
sessionId TEXT NOT NULL,
|
||||
status INTEGER NOT NULL DEFAULT 0,
|
||||
retries INTEGER NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY(sessionId, eventId)
|
||||
);
|
||||
|
||||
CREATE INDEX PushRequestSessionAndStatus ON PushRequest (sessionId, status);
|
||||
Loading…
Add table
Add a link
Reference in a new issue