-
-
Notifications
You must be signed in to change notification settings - Fork 45
New response as per CCCT-1893 #3407
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
Conversation
📝 WalkthroughWalkthroughThe pull request modifies Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (2 warnings, 1 inconclusive)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
app/src/org/commcare/android/database/connect/models/PushNotificationRecord.kt(3 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: shubham1g5
Repo: dimagi/commcare-android PR: 0
File: :0-0
Timestamp: 2025-05-08T11:08:18.530Z
Learning: PR #3048 "Phase 4 Connect PR" introduces a substantial feature called "Connect" to the CommCare Android app, which includes messaging, job management, delivery tracking, payment processing, authentication flows, and learning modules. It follows a modern architecture using Navigation Components with three navigation graphs, segregated business logic in Manager classes, and proper database persistence.
Learnt from: OrangeAndGreen
Repo: dimagi/commcare-android PR: 3043
File: app/src/org/commcare/android/database/connect/models/ConnectMessagingChannelRecord.java:0-0
Timestamp: 2025-04-22T17:04:26.780Z
Learning: In the Connect API contract, the server doesn't include the fields `created`, `answered_consent`, and `key` in JSON responses for messaging channels, which is why the `fromJson` method in `ConnectMessagingChannelRecord` explicitly initializes these values rather than parsing them.
Learnt from: OrangeAndGreen
Repo: dimagi/commcare-android PR: 3043
File: app/src/org/commcare/android/database/connect/models/ConnectMessagingChannelRecord.java:0-0
Timestamp: 2025-04-22T17:04:26.780Z
Learning: In the Connect API contract, the server doesn't include the fields `created`, `answered_consent`, and `key` in JSON responses for messaging channels, which is why the `fromJson` method in `ConnectMessagingChannelRecord` explicitly initializes these values rather than parsing them from JSON.
📚 Learning: 2025-01-21T17:28:09.007Z
Learnt from: OrangeAndGreen
Repo: dimagi/commcare-android PR: 2912
File: app/src/org/commcare/android/database/connect/models/ConnectUserRecord.java:66-71
Timestamp: 2025-01-21T17:28:09.007Z
Learning: The ConnectUserRecord class in CommCare Android uses Persisting annotations with sequential indices for field persistence, and MetaField annotations for fields that have corresponding META constants. Fields should be documented with Javadoc comments explaining their purpose, format requirements, and relationships with other fields.
Applied to files:
app/src/org/commcare/android/database/connect/models/PushNotificationRecord.kt
📚 Learning: 2025-04-22T17:04:26.780Z
Learnt from: OrangeAndGreen
Repo: dimagi/commcare-android PR: 3043
File: app/src/org/commcare/android/database/connect/models/ConnectMessagingChannelRecord.java:0-0
Timestamp: 2025-04-22T17:04:26.780Z
Learning: In the Connect API contract, the server doesn't include the fields `created`, `answered_consent`, and `key` in JSON responses for messaging channels, which is why the `fromJson` method in `ConnectMessagingChannelRecord` explicitly initializes these values rather than parsing them.
Applied to files:
app/src/org/commcare/android/database/connect/models/PushNotificationRecord.kt
📚 Learning: 2025-04-22T17:04:26.780Z
Learnt from: OrangeAndGreen
Repo: dimagi/commcare-android PR: 3043
File: app/src/org/commcare/android/database/connect/models/ConnectMessagingChannelRecord.java:0-0
Timestamp: 2025-04-22T17:04:26.780Z
Learning: In the Connect API contract, the server doesn't include the fields `created`, `answered_consent`, and `key` in JSON responses for messaging channels, which is why the `fromJson` method in `ConnectMessagingChannelRecord` explicitly initializes these values rather than parsing them from JSON.
Applied to files:
app/src/org/commcare/android/database/connect/models/PushNotificationRecord.kt
📚 Learning: 2025-04-18T20:13:29.655Z
Learnt from: OrangeAndGreen
Repo: dimagi/commcare-android PR: 3040
File: app/src/org/commcare/android/database/connect/models/ConnectJobDeliveryFlagRecord.java:39-55
Timestamp: 2025-04-18T20:13:29.655Z
Learning: In the CommCare Android Connect feature, the JSON object passed to `ConnectJobDeliveryFlagRecord.fromJson()` method should never be null based on the implementation design.
Applied to files:
app/src/org/commcare/android/database/connect/models/PushNotificationRecord.kt
| val record = | ||
| PushNotificationRecord().apply { | ||
| notificationId = obj.optString(META_NOTIFICATION_ID, "") | ||
| title = obj.optString(META_TITLE, "") | ||
| body = obj.optString(META_BODY, "") | ||
| notificationType = obj.optString(META_NOTIFICATION_TYPE, "") | ||
| confirmationStatus = obj.optString(META_CONFIRMATION_STATUS, "") | ||
| paymentId = obj.optString(META_PAYMENT_ID, "") | ||
| readStatus = obj.optBoolean(META_READ_STATUS, false) | ||
| val dateString: String = obj.getString(META_TIME_STAMP) | ||
| createdDate = DateUtils.parseDateTime(dateString) | ||
| connectMessageId = obj.optString(META_MESSAGE_ID, "") | ||
| channel = obj.optString(META_CHANNEL, "") | ||
| action = obj.optString(META_ACTION, "") | ||
| opportunityId = obj.optString(META_OPPORTUNITY_ID, "") | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Populate acknowledged state from JSON
We introduced META_ACKNOWLEDGED, but fromJsonArray never assigns the new acknowledged field. Every record will therefore persist false, even if the server marks it as acknowledged. Please read the value from the payload so we don’t lose that state.
Apply this diff inside the apply { ... } block:
- opportunityId = obj.optString(META_OPPORTUNITY_ID, "")
+ opportunityId = obj.optString(META_OPPORTUNITY_ID, "")
+ acknowledged = obj.optBoolean(META_ACKNOWLEDGED, false)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| val record = | |
| PushNotificationRecord().apply { | |
| notificationId = obj.optString(META_NOTIFICATION_ID, "") | |
| title = obj.optString(META_TITLE, "") | |
| body = obj.optString(META_BODY, "") | |
| notificationType = obj.optString(META_NOTIFICATION_TYPE, "") | |
| confirmationStatus = obj.optString(META_CONFIRMATION_STATUS, "") | |
| paymentId = obj.optString(META_PAYMENT_ID, "") | |
| readStatus = obj.optBoolean(META_READ_STATUS, false) | |
| val dateString: String = obj.getString(META_TIME_STAMP) | |
| createdDate = DateUtils.parseDateTime(dateString) | |
| connectMessageId = obj.optString(META_MESSAGE_ID, "") | |
| channel = obj.optString(META_CHANNEL, "") | |
| action = obj.optString(META_ACTION, "") | |
| opportunityId = obj.optString(META_OPPORTUNITY_ID, "") | |
| } | |
| val record = | |
| PushNotificationRecord().apply { | |
| notificationId = obj.optString(META_NOTIFICATION_ID, "") | |
| title = obj.optString(META_TITLE, "") | |
| body = obj.optString(META_BODY, "") | |
| notificationType = obj.optString(META_NOTIFICATION_TYPE, "") | |
| confirmationStatus = obj.optString(META_CONFIRMATION_STATUS, "") | |
| paymentId = obj.optString(META_PAYMENT_ID, "") | |
| readStatus = obj.optBoolean(META_READ_STATUS, false) | |
| val dateString: String = obj.getString(META_TIME_STAMP) | |
| createdDate = DateUtils.parseDateTime(dateString) | |
| connectMessageId = obj.optString(META_MESSAGE_ID, "") | |
| channel = obj.optString(META_CHANNEL, "") | |
| action = obj.optString(META_ACTION, "") | |
| opportunityId = obj.optString(META_OPPORTUNITY_ID, "") | |
| acknowledged = obj.optBoolean(META_ACKNOWLEDGED, false) | |
| } |
🤖 Prompt for AI Agents
In
app/src/org/commcare/android/database/connect/models/PushNotificationRecord.kt
around lines 92 to 107, the newly added META_ACKNOWLEDGED value is not read when
constructing PushNotificationRecord, so acknowledged remains default false;
update the apply { ... } block to read obj.optBoolean(META_ACKNOWLEDGED, false)
and assign it to the record's acknowledged property (e.g., acknowledged =
obj.optBoolean(META_ACKNOWLEDGED, false)) so the persisted record reflects the
payload's acknowledged state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
META_ACKNOWLEDGED is not coming from server so no need to read here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jignesh-dimagi, thank you for the clarification! I understand now that acknowledged is a client-side field managed within the app and not part of the server's JSON response for push notifications. That makes sense—the field will be updated locally when the user acknowledges a notification.
✏️ Learnings added
Learnt from: Jignesh-dimagi
Repo: dimagi/commcare-android PR: 3407
File: app/src/org/commcare/android/database/connect/models/PushNotificationRecord.kt:92-107
Timestamp: 2025-11-06T11:44:23.923Z
Learning: In PushNotificationRecord, the `acknowledged` field (META_ACKNOWLEDGED) is a client-side field that is not included in the server's JSON response, so it should not be read in the fromJsonArray method.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
🧠 Learnings used
Learnt from: OrangeAndGreen
Repo: dimagi/commcare-android PR: 3043
File: app/src/org/commcare/android/database/connect/models/ConnectMessagingChannelRecord.java:0-0
Timestamp: 2025-04-22T17:04:26.780Z
Learning: In the Connect API contract, the server doesn't include the fields `created`, `answered_consent`, and `key` in JSON responses for messaging channels, which is why the `fromJson` method in `ConnectMessagingChannelRecord` explicitly initializes these values rather than parsing them from JSON.
Learnt from: OrangeAndGreen
Repo: dimagi/commcare-android PR: 3043
File: app/src/org/commcare/android/database/connect/models/ConnectMessagingChannelRecord.java:0-0
Timestamp: 2025-04-22T17:04:26.780Z
Learning: In the Connect API contract, the server doesn't include the fields `created`, `answered_consent`, and `key` in JSON responses for messaging channels, which is why the `fromJson` method in `ConnectMessagingChannelRecord` explicitly initializes these values rather than parsing them.
Learnt from: pm-dimagi
Repo: dimagi/commcare-android PR: 2847
File: app/src/org/commcare/android/database/connect/models/ConnectJobDeliveryRecord.java:86-93
Timestamp: 2025-01-27T09:08:32.722Z
Learning: The JSON fields (status, unitName, slug, entityId, entityName, reason) in ConnectJobDeliveryRecord's fromJson method are guaranteed to be non-null through the application's data contract, except for the 'id' field which is explicitly checked.
Learnt from: OrangeAndGreen
Repo: dimagi/commcare-android PR: 3040
File: app/src/org/commcare/android/database/connect/models/ConnectJobDeliveryFlagRecord.java:39-55
Timestamp: 2025-04-18T20:13:29.655Z
Learning: In the CommCare Android Connect feature, the JSON object passed to `ConnectJobDeliveryFlagRecord.fromJson()` method should never be null based on the implementation design.
Learnt from: OrangeAndGreen
Repo: dimagi/commcare-android PR: 3043
File: app/src/org/commcare/android/database/connect/models/ConnectMessagingChannelRecord.java:86-99
Timestamp: 2025-04-22T16:44:26.867Z
Learning: In ConnectMessagingChannelRecord, fields like META_CHANNEL_ID, META_CONSENT, META_CHANNEL_NAME, and META_KEY_URL are required fields, and the code is intentionally designed to crash if they're missing to raise awareness of data integrity issues rather than handling them silently.
Learnt from: shubham1g5
Repo: dimagi/commcare-android PR: 0
File: :0-0
Timestamp: 2025-05-08T11:08:18.530Z
Learning: PR #3048 "Phase 4 Connect PR" introduces a substantial feature called "Connect" to the CommCare Android app, which includes messaging, job management, delivery tracking, payment processing, authentication flows, and learning modules. It follows a modern architecture using Navigation Components with three navigation graphs, segregated business logic in Manager classes, and proper database persistence.
| opportunityId = it.optString(META_OPPORTUNITY_ID, "") | ||
| val record = | ||
| PushNotificationRecord().apply { | ||
| notificationId = obj.optString(META_NOTIFICATION_ID, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use getString for anything required ? Or are we doing payload validation at some other place ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not raising the exception to grab the non-corrupt ones and ignoring the corrupt one.
Technical Summary
https://dimagi.atlassian.net/browse/CCCT-1893
Labels and Review