WIP: new-activity notification #231

Draft
trentlarson wants to merge 80 commits from notify-api into master
Showing only changes of commit d4cdee0698 - Show all commits

View File

@@ -65,12 +65,22 @@ public class TimeSafariNativeFetcher implements NativeNotificationContentFetcher
this.apiBaseUrl = apiBaseUrl;
this.activeDid = activeDid;
this.jwtToken = jwtToken;
Log.i(TAG, "Configured with API: " + apiBaseUrl);
int starredCount = getStarredPlanIds().size();
Log.i(TAG, "Configured with API: " + apiBaseUrl + ", starredPlanIds count=" + starredCount);
}
@NonNull
@Override
public CompletableFuture<List<NotificationContent>> fetchContent(@NonNull FetchContext fetchContext) {
Long scheduled = fetchContext.scheduledTime;
Log.i(
TAG,
"fetchContent START trigger="
+ fetchContext.trigger
+ " scheduledTime="
+ (scheduled != null ? scheduled : "null")
+ " callerThread="
+ Thread.currentThread().getName());
Log.d(TAG, "Fetching notification content, trigger: " + fetchContext.trigger);
return fetchContentWithRetry(fetchContext, 0);
}
@@ -79,6 +89,7 @@ public class TimeSafariNativeFetcher implements NativeNotificationContentFetcher
@NonNull FetchContext context, int retryCount) {
return CompletableFuture.supplyAsync(() -> {
try {
Log.i(TAG, "fetchContent worker thread=" + Thread.currentThread().getName());
if (apiBaseUrl == null || activeDid == null || jwtToken == null) {
Log.e(TAG, "Not configured. Call configureNativeFetcher() from TypeScript first.");
return Collections.emptyList();
@@ -95,12 +106,21 @@ public class TimeSafariNativeFetcher implements NativeNotificationContentFetcher
connection.setDoOutput(true);
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("planIds", getStarredPlanIds());
List<String> planIds = getStarredPlanIds();
requestBody.put("planIds", planIds);
String afterId = getLastAcknowledgedJwtId();
if (afterId == null || afterId.isEmpty()) {
afterId = "0";
}
requestBody.put("afterId", afterId);
Log.i(
TAG,
"POST "
+ ENDORSER_ENDPOINT
+ " planCount="
+ planIds.size()
+ " afterId="
+ (afterId.length() > 12 ? afterId.substring(0, 12) + "" : afterId));
String jsonBody = gson.toJson(requestBody);
try (OutputStream os = connection.getOutputStream()) {
@@ -109,7 +129,7 @@ public class TimeSafariNativeFetcher implements NativeNotificationContentFetcher
}
int responseCode = connection.getResponseCode();
Log.d(TAG, "HTTP response code: " + responseCode);
Log.i(TAG, "HTTP response code: " + responseCode);
if (responseCode == 200) {
StringBuilder response = new StringBuilder();