Skip to content

Conversation

@nan-li
Copy link
Contributor

@nan-li nan-li commented Dec 21, 2022

Description

One Line Summary

Remove Swift print (updating the message to be cleaner) and NSLog from SDK, and use OneSignalLog instead.

Motivation

Logging

Scope

Logging

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

This change is Reviewable

@nan-li nan-li changed the title [User model] use onesignallog [User model] Logging fixes Dec 21, 2022
@nan-li nan-li changed the base branch from main to user_model/more_alpha_1_fixes December 21, 2022 11:43
@nan-li nan-li force-pushed the user_model/more_alpha_1_fixes branch from dd537b3 to 42a11e3 Compare December 28, 2022 21:24
* Replace all Swift `print()` calls with OneSignalLog.
* Replace a few NSLogs in the SDK with OneSignalLog as well.
@nan-li nan-li force-pushed the user_model/use_onesignal_log branch from aa59b9a to 02cfc96 Compare December 28, 2022 21:27
Refine some more APIs for Swift
* For clarity, rename `OSUD_PLAYER_ID_TO` to `OSUD_PUSH_SUBSCRIPTION_ID`
* And `OSUD_PUSH_TOKEN_TO` to `OSUD_PUSH_TOKEN`
* Remove from Common Defines values no longer used
* Motivation: push sub behaves differently from other subscriptions and is not cleared from the store when a user changes. Separate it into its own store so that the email and sms subscriptions stores can be cleared but the push subscription store is not.
* Motivation: hydrating subscriptions can create a model and add to store if it doesn't exist locally. Guard against hydrating here as well so that a request isn't extraneously created.
* Motivation: Hydrating the push subscription is problematic. We will hydrate it if:
 - the push subscription ID does not already exist locally
 - the type of the returned subscription is iOSPush
 - the token at the time the request is made matches the returned token
 - we hydrate using the first matching subscription that is returned (there may be multiple iOS push subscriptions in the response but we will accept the first one that fulfills our conditions above)

* This can still be faulty behavior but we get as close as we can to correct behavior for now.
* Add push subscription observer and permission observer
* Missed this requirement for testing -> update bundle ID to staging, needs to be `com.onesignal.example.staging`
* Move set log level up to capture logs earlier.
* Not making any structural changes to example app, but link some buttons to new methods like login, logout
* Motivation: When initializing the delta queue and request queue, the executors need to hook up the Deltas' and Requests' models to the ones in the store, so that they can get the updated information needed to send the requests, and hydrate the correct models.
* When model stores, deltas, and requests are initialized from cache, they lose their references as they are new instances.
* To simplify uncaching, we maintain separate request queues for each request type in the executor
* Also needed to update some `let` properties to be `var`
* Motivation: Must be careful of accessing `OneSignalUserManagerImpl.sharedInstance` before it's actually finished initializing, as the initializer for it does a lot of things!
* What was happening was that during the process of initializing the `sharedInstance`, we initialized the executors, but the executors' initializer accessed model stores via OneSignalUserManagerImpl.sharedInstance` which is a problem.
* Instead, initialize these in `start()`, but now they will be Optional.
* And we may need to note if any other areas can have the same issue.
* Comments, TODOs, and swiftlint
* Remove too extraneous logging
* add informational logging
* On logout, we were setting the user to `nil` to early
* When logout is called, we prepare for new user, and the operation repo and executors flush their Deltas. However, they still need access to user properties, so set user to `nil` after this.
* We want to remove this request from the request queue and cache when it returns successfully, even if we don't hydrate.
* It can return just `success` with no subscription info if this subscription already exists.
* Update check for 2 tokens being equal, since "" is equal to nil
* Motivation: Create User's response won't send us the user's complete info if this user already existed.
* For now, do both, as we should parse to get the subscription_id from this request.
* TODO: Differentiate if we need to Fetch based on response code to not make extraneous call.
* It seems we cannot send `enabled = true` without sending `notification_types` for creating an email or SMS. Even sending -99 is ok.
* Or, we send neither.
* The server is still in flux. For now, don't send any of these, but we need to revisit
…_round_2

[user model] More fixes for alpha release (round 3)
@nan-li nan-li merged commit 62de979 into user_model/more_alpha_1_fixes Jan 6, 2023
@nan-li nan-li deleted the user_model/use_onesignal_log branch January 6, 2023 03:02
nan-li added a commit that referenced this pull request Oct 30, 2023
nan-li added a commit that referenced this pull request Oct 30, 2023
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.

4 participants