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

Keep Remote Messages in database if they were shown #911

Merged
merged 5 commits into from
Jul 25, 2024

Conversation

ayoy
Copy link
Contributor

@ayoy ayoy commented Jul 24, 2024

Please review the release process for BrowserServicesKit here.

Required:

Task/Issue URL: https://app.asana.com/0/1207619243206445/1207864976004819/f
iOS PR: duckduckgo/iOS#3136
macOS PR: duckduckgo/macos-browser#3012
What kind of version bump will this require?: Major

Description:
Update RemoteMessagingStore to keep track of messages that have ever been shown to the user,
also if the user didn't interact with them (by dismissing or clicking any buttons).

Steps to test this PR:
See platform PRs for steps to test.

OS Testing:

  • iOS 14
  • iOS 15
  • iOS 16
  • macOS 10.15
  • macOS 11
  • macOS 12

Internal references:

Software Engineering Expectations
Technical Design Template

@ayoy ayoy self-assigned this Jul 24, 2024
@@ -86,16 +83,23 @@ public final class RemoteMessagingStore: RemoteMessagingStoring {
os_log("Remote messaging config - save processed version: %d", log: log, type: .debug, processorResult.version)

let context = database.makeContext(concurrencyType: .privateQueueConcurrencyType, name: Constants.privateContextName)
saveRemoteMessagingConfig(withVersion: processorResult.version, in: context)
context.performAndWait {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated how DB context is used in the store. Currently all changes triggered externally (all public API of RemoteMessagingStore) always happen within one database transaction. All private API takes context as parameter but never calls save.

os_log("Failed to save remote message entity: %@", log: log, type: .error, error.localizedDescription)
if remoteMessageManagedObject.isInserted {
remoteMessageManagedObject.id = remoteMessage.id
remoteMessageManagedObject.shown = false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We only set shown to false when it's a new message. For reused message IDs we don't clear shown flag (this is in line with Android implementation).

Comment on lines +89 to +94
if let remoteMessage = processorResult.message {
addOrUpdate(remoteMessage: remoteMessage, in: context)
} else {
markScheduledMessagesAsDone(in: context)
}
deleteNotShownDoneMessages(in: context)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there's a new message to be saved, add or update it. Update, in case that ID has already been shown to the user, in which case we're reusing the database object.

If there's no message in the config, we mark scheduled messages as done.

After that, delete all messages that were previously scheduled and never shown (that includes messages just marked as done in markScheduledMessagesAsDone).

@ayoy ayoy requested a review from samsymons July 24, 2024 15:20
@ayoy ayoy assigned samsymons and unassigned ayoy Jul 24, 2024
@ayoy ayoy marked this pull request as ready for review July 24, 2024 15:21
Copy link
Contributor

@samsymons samsymons left a comment

Choose a reason for hiding this comment

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

Overall looks good, left one question about making sure the save config pixel still has enough information to debug with, but otherwise the functionality has worked as expected. Great job!

@ayoy ayoy merged commit fc03a7c into main Jul 25, 2024
7 checks passed
@ayoy ayoy deleted the dominik/rmf-track-shown-messages branch July 25, 2024 06:20
samsymons added a commit that referenced this pull request Jul 28, 2024
* main:
  Update Xcode version to 15.4 (#912)
  Keep Remote Messages in database if they were shown (#911)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants