Skip to content

Commit

Permalink
chore: add Debug logs to IAM methods
Browse files Browse the repository at this point in the history
  • Loading branch information
SoumenRautray committed Jun 5, 2024
1 parent 9a48c49 commit 28f11ea
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Sources/RInAppMessaging/CampaignDispatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ internal class CampaignDispatcher: CampaignDispatcherType, TaskSchedulable {
if permissionResponse.performPing {
delegate?.performPing()
}

print("IAM Debug: \(Date()) campaign.impressionsLeft \(campaign.impressionsLeft))")
guard campaign.impressionsLeft > 0 && (permissionResponse.display || campaign.data.isTest) else {
dispatchNext()
return
Expand Down Expand Up @@ -138,6 +138,7 @@ internal class CampaignDispatcher: CampaignDispatcherType, TaskSchedulable {
}

private func commitCampaignDisplay(_ campaign: Campaign, cancelled: Bool) {
print("IAM Debug: \(Date()) commitCampaignDisplay()")
if !cancelled {
campaignRepository.decrementImpressionsLeftInCampaign(id: campaign.id)
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/RInAppMessaging/CampaignsListManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ internal class CampaignsListManager: CampaignsListManagerType, TaskSchedulable {
}

func refreshList() {
print("IAM Debug: \(Date()) refreshList()")
pingQueue.sync {
pingMixerServer()
}
Expand All @@ -53,6 +54,7 @@ internal class CampaignsListManager: CampaignsListManagerType, TaskSchedulable {
handleError(error)
return
}
print("IAM Debug: \(Date()) pingMixerServer \(decodedResponse)")
handleSuccess(decodedResponse)
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/RInAppMessaging/InAppMessagingInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ final class InAppMessagingInteractor {
guard let userPerference else {
return
}
print("IAM Debug: \(Date()) registerPreference() userPerference")
iamModule?.registerPreference(userPerference)
}
}
Expand Down Expand Up @@ -82,6 +83,7 @@ final class InAppMessagingInteractor {
module.onVerifyContext = onVerifyContext
module.setAccessibilityCompatibleDisplay(accessibilityCompatibleDisplay)
if let userPerference {
print("IAM Debug: \(Date()) registerPreference() userPerference configure()")
module.registerPreference(userPerference)
}
iamModule = module
Expand Down
8 changes: 7 additions & 1 deletion Sources/RInAppMessaging/InAppMessagingModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,21 @@ internal class InAppMessagingModule: ErrorDelegate, CampaignDispatcherDelegate,
guard isInitialized else {
return false
}

print("IAM Debug: \(Date()) logEvent \(event)")
checkUserChanges()
eventMatcher.matchAndStore(event: event)
campaignTriggerAgent.validateAndTriggerCampaigns()
return true
}

func registerPreference(_ preference: UserInfoProvider) {
print("IAM Debug: \(Date()) registerPreference()")
accountRepository.setPreference(preference)

guard isInitialized else {
print("IAM Debug: \(Date()) registerPreference() not isInitialized")
if accountRepository.updateUserInfo() {
print("IAM Debug: \(Date()) registerPreference() accountRepository.updateUserInfo()")
campaignRepository.loadCachedData()
}
return
Expand All @@ -119,7 +122,9 @@ internal class InAppMessagingModule: ErrorDelegate, CampaignDispatcherDelegate,

// visible for testing
func checkUserChanges() {
print("IAM Debug: \(Date()) checkUserChanges()")
if accountRepository.updateUserInfo() {
print("IAM Debug: \(Date()) updateUserInfo()")
campaignRepository.loadCachedData()
campaignsListManager.refreshList()
}
Expand Down Expand Up @@ -169,6 +174,7 @@ extension InAppMessagingModule {
extension InAppMessagingModule {

func userDidChangeOrLogout() {
print("IAM Debug: \(Date()) userDidChangeOrLogout()")
eventMatcher.clearNonPersistentEvents()
}
}
2 changes: 1 addition & 1 deletion Sources/RInAppMessaging/RInAppMessaging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import RSDKUtils
@objc public static func configure(subscriptionID: String? = nil,
configurationURL: String? = nil,
enableTooltipFeature: Bool = false) {

print("IAM Debug: \(Date()) configure()")
guard verifyRMCEnvironment(subscriptionID: subscriptionID), !isInitialized else {
let description = "⚠️ SDK configure request rejected. Initialization status: \(isInitialized)"
let error = NSError.iamError(description: description)
Expand Down
6 changes: 6 additions & 0 deletions Sources/RInAppMessaging/Repositories/AccountRepository.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import class Foundation.Bundle
import Foundation

#if SWIFT_PACKAGE
import class RSDKUtilsMain.WeakWrapper
Expand Down Expand Up @@ -44,14 +45,17 @@ final class AccountRepository: AccountRepositoryType {
func updateUserInfo() -> Bool {
guard let userInfoProvider = userInfoProvider else {
// No userInfoProvider object has been registered yet
print("IAM Debug: \(Date()) No userInfoProvider object has been registered yet")
return false
}
if BundleInfo.applicationId?.contains("rakuten") == true, !Environment.isUnitTestEnvironment {
checkAssertions()
}

let newHash = userDataCache.userHash(from: userInfoProvider.userIdentifiers)
print("IAM Debug: \(Date()) newHash \(String(newHash))")
guard let currentHash = userInfoHash else {
print("IAM Debug: \(Date()) updateUserInfo() called for the first time after registering `userInfoProvider`)")
// updateUserInfo() has been called for the first time after registering `userInfoProvider`
userInfoHash = newHash
return true
Expand All @@ -63,6 +67,8 @@ final class AccountRepository: AccountRepositoryType {
}

userInfoHash = newHash
print("IAM Debug: \(Date()) userInfoHash \(String(describing: userInfoHash)) ")
print("IAM Debug: \(Date()) \(currentHash != userInfoHash)")
return currentHash != userInfoHash
}

Expand Down
13 changes: 10 additions & 3 deletions Sources/RInAppMessaging/Repositories/CampaignRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ internal class CampaignRepository: CampaignRepositoryType {
}

func syncWith(list: [Campaign], timestampMilliseconds: Int64, ignoreTooltips: Bool) {
print("IAM Debug: \(Date()) syncWith()")
lastSyncInMilliseconds = timestampMilliseconds
let oldList = allCampaigns.get()

Expand All @@ -105,7 +106,7 @@ internal class CampaignRepository: CampaignRepositoryType {
allCampaigns.set(value: updatedList)
tooltips.set(value: updatedList.filter({ $0.isTooltip }))
}

print("IAM Debug: \(Date()) updatedList \(updatedList)")
saveDataToCache(updatedList)
delegate?.didUpdateCampaignList()
}
Expand All @@ -131,7 +132,8 @@ internal class CampaignRepository: CampaignRepositoryType {

@discardableResult
func decrementImpressionsLeftInCampaign(id: String) -> Campaign? {
updateImpressionsLeftInCampaign(withID: id, by: -1)
print("IAM Debug: \(Date()) decrementImpressionsLeftInCampaign()")
return updateImpressionsLeftInCampaign(withID: id, by: -1)
}

@discardableResult
Expand All @@ -140,28 +142,33 @@ internal class CampaignRepository: CampaignRepositoryType {
}

func loadCachedData() {
print("IAM Debug: \(Date()) loadCachedData()")
let cachedData = userDataCache.getUserData(identifiers: accountRepository.getUserIdentifiers())?.campaignData ?? []
print("IAM Debug: \(Date()) cachedData \(cachedData)")
allCampaigns.set(value: cachedData)
}

// MARK: - Helpers

private func updateImpressionsLeftInCampaign(withID id: String, by value: Int) -> Campaign? {
print("IAM Debug: \(Date()) updateImpressionsLeftInCampaign()")
var newList = allCampaigns.get()
guard let index = newList.firstIndex(where: { $0.id == id }) else {
print("IAM Debug: \(Date()) Campaign \(id) could not be updated - not found in the repository")
Logger.debug("Campaign \(id) could not be updated - not found in the repository")
return nil
}
let campaign = newList[index]
let updatedCampaign = Campaign.updatedCampaign(campaign, withImpressionLeft: max(0, campaign.impressionsLeft + value))
newList[index] = updatedCampaign
allCampaigns.set(value: newList)

print("IAM Debug: \(Date()) newList : \(newList)")
saveDataToCache(newList)
return updatedCampaign
}

private func saveDataToCache(_ list: [Campaign]) {
print("IAM Debug: \(Date()) saveDataToCache()")
let user = accountRepository.getUserIdentifiers()
userDataCache.cacheCampaignData(list, userIdentifiers: user)
}
Expand Down

0 comments on commit 28f11ea

Please sign in to comment.