Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve push devices when returning user profile #193

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ protected void buildEndpoint(ApiEndpoint baseEndpoint) {

@Override
protected OtpUser getUserProfile(RequestingUser profile) {
return profile.otpUser;
OtpUser otpUser = profile.otpUser;
if (otpUser != null) {
NotificationUtils.updatePushDevices(otpUser);
}
return otpUser;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,8 @@ private void sendNotifications() {
return;
}
// Update push notification devices count, which may change asynchronously
int numPushDevices = NotificationUtils.getPushInfo(otpUser.email);
if (numPushDevices != otpUser.pushDevices) {
otpUser.pushDevices = numPushDevices;
Persistence.otpUsers.replace(otpUser.id, otpUser);
}
NotificationUtils.updatePushDevices(otpUser);

if (notifications.size() == 0) {
// FIXME: Change log level
LOG.info("No notifications queued for trip. Skipping notify.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.opentripplanner.middleware.bugsnag.BugsnagReporter;
import org.opentripplanner.middleware.models.AdminUser;
import org.opentripplanner.middleware.models.OtpUser;
import org.opentripplanner.middleware.persistence.Persistence;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -324,6 +325,19 @@ public static int getPushInfo(String toUser) {
return 0;
}

/**
* Poll the push middleware for the number of devices registered to receive push notifications
* for the specified user, and update the corresponding field in memory and Mongo.
* @param otpUser The {@link OtpUser} for which to check and update push devices.
*/
public static void updatePushDevices(OtpUser otpUser) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any expectation to add Javadoc in this project?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the JavaDoc in c7b05af.

int numPushDevices = getPushInfo(otpUser.email);
if (numPushDevices != otpUser.pushDevices) {
otpUser.pushDevices = numPushDevices;
Persistence.otpUsers.replace(otpUser.id, otpUser);
}
}

static class NotificationInfo {
public String user;
public String message;
Expand Down
Loading