Skip to content

Conversation

@pandeymangg
Copy link
Contributor

Fixes several issues with the sdk: #34 #33 #32

@coderabbitai
Copy link

coderabbitai bot commented Sep 29, 2025

Walkthrough

Replaced days-between calculation to clamp at zero. SurveyManager: added guard for unknown action classes, clamped display-percentage to [0,100] with random draw, added logs/early exits for display restrictions, switched recontact check to seconds→days, and use survey.delay/survey.id when delaying. Added Placement enum and ProjectOverwrites struct; Survey gains projectOverwrites. WebView/FormbricksViewModel now prefers survey-level overwrites for placement, darkOverlay, languages, and styling. PresentSurveyManager.present gained an optional completion. UpdateQueue: main-thread timer cleanup, snapshotting of userId/attributes, and new cleanup(). Tests and mock JSON updated.

Pre-merge checks

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title Check ❓ Inconclusive The title mentions fixing survey placement and other cosmetic issues, which touches on one aspect of the changeset, but it is overly broad and does not clearly summarize the primary functional updates such as the new projectOverwrites feature, Calendar days‐between clamping, and API enhancements, making it difficult for reviewers to understand the scope at a glance. Please revise the title to concisely reflect the main changes, for example “Add survey projectOverwrites with placement overrides and clamp Calendar daysBetween result,” so it accurately conveys the core updates in this PR.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed The description indicates that multiple SDK issues are being fixed and references the related issue numbers, which aligns with the changes made and is not off-topic for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 9

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c6f7233 and e303184.

📒 Files selected for processing (4)
  • Sources/FormbricksSDK/Extension/Calendar+DaysBetween.swift (1 hunks)
  • Sources/FormbricksSDK/Manager/SurveyManager.swift (3 hunks)
  • Sources/FormbricksSDK/Model/Environment/Survey.swift (2 hunks)
  • Sources/FormbricksSDK/WebView/FormbricksViewModel.swift (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
Sources/FormbricksSDK/Manager/SurveyManager.swift (1)
Sources/FormbricksSDK/Logger/Logger.swift (2)
  • error (37-39)
  • info (29-31)
Sources/FormbricksSDK/WebView/FormbricksViewModel.swift (1)
Sources/FormbricksSDK/Model/Environment/EnvironmentResponse.swift (1)
  • getSurveyJson (15-22)
🔇 Additional comments (5)
Sources/FormbricksSDK/WebView/FormbricksViewModel.swift (5)

94-96: LGTM: local matchedSurvey and project improve readability.
No issues spotted with the optional chaining and early binding.


102-103: Confirm default branding behavior.
Setting data["isBrandingEnabled"] = project.inAppSurveyBranding ?? true means branding is enabled when the project flag is nil. Is that the intended product default? If not, consider defaulting to false.


110-110: LGTM: darkOverlay override with project fallback.
The nil-coalescing to the project value is correct and straightforward.


120-121: Confirm backend sets allowStyleOverwrite in project styling JSON.
FormbricksViewModel correctly uses project.styling?.allowStyleOverwrite ?? false to gate custom survey styling; ensure the API includes and enables this flag when intended.


104-108: Incorrect nil-coalescing of optional String
project.placement is declared as String?, so

matchedSurvey?.projectOverwrites?.placement?.rawValue ?? project.placement

won’t compile. You must either provide a non-optional fallback or unwrap the optional twice, for example:

let placementValue = matchedSurvey?.projectOverwrites?.placement?.rawValue 
                   ?? project.placement 
                   ?? "defaultPlacement"
data["placement"] = placementValue

Likely an incorrect or invalid review comment.

Copy link

@coderabbitai coderabbitai bot left a 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: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e303184 and 7747183.

📒 Files selected for processing (3)
  • Sources/FormbricksSDK/Manager/PresentSurveyManager.swift (2 hunks)
  • Sources/FormbricksSDK/Manager/SurveyManager.swift (4 hunks)
  • Sources/FormbricksSDK/WebView/FormbricksViewModel.swift (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
Sources/FormbricksSDK/Manager/SurveyManager.swift (2)
Sources/FormbricksSDK/Logger/Logger.swift (2)
  • error (37-39)
  • info (29-31)
Sources/FormbricksSDK/Manager/PresentSurveyManager.swift (1)
  • present (16-35)
Sources/FormbricksSDK/WebView/FormbricksViewModel.swift (1)
Sources/FormbricksSDK/Model/Environment/EnvironmentResponse.swift (1)
  • getSurveyJson (15-22)
🔇 Additional comments (2)
Sources/FormbricksSDK/WebView/FormbricksViewModel.swift (1)

112-124: Multi-language handling looks correct now.

Wrapping the coalesced count before comparison fixes the precedence issue and keeps the override logic clear. The rest of the override selection reads well.

Sources/FormbricksSDK/Manager/SurveyManager.swift (1)

298-301: Clamp negative elapsed time before converting to days.

If lastDisplayedAt ends up in the future (e.g., clock skew), timeIntervalSince becomes negative, so daysBetween is negative and the survey stays filtered out indefinitely. Clamp the elapsed seconds (or days) to zero before comparing so recontact semantics stay non-negative.

-                let secondsElapsed = Date().timeIntervalSince(lastDisplayedAt)
-                let daysBetween = Int(secondsElapsed / 86_400)
+                let secondsElapsed = max(0, Date().timeIntervalSince(lastDisplayedAt))
+                let daysBetween = Int(secondsElapsed / 86_400)
                 return daysBetween >= recontactDays

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7747183 and 0816d95.

📒 Files selected for processing (2)
  • Tests/FormbricksSDKTests/FormbricksSDKTests.swift (2 hunks)
  • Tests/FormbricksSDKTests/Mock/Environment.json (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
Tests/FormbricksSDKTests/FormbricksSDKTests.swift (3)
Sources/FormbricksSDK/Helpers/ConfigBuilder.swift (3)
  • setLogLevel (56-59)
  • service (61-64)
  • build (67-69)
Sources/FormbricksSDK/Formbricks.swift (1)
  • setup (41-95)
Sources/FormbricksSDK/Manager/SurveyManager.swift (1)
  • refreshEnvironmentIfNeeded (141-164)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-and-analyze
🔇 Additional comments (1)
Tests/FormbricksSDKTests/FormbricksSDKTests.swift (1)

245-247: Initializer update acknowledged

Explicit projectOverwrites: nil keeps the constructor in sync with the new model and documents the fallback path. Consider adding a test that removes survey overwrites and asserts fallback to project-level placement/darkOverlay.

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
74.5% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Copy link

@coderabbitai coderabbitai bot left a 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: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4746df6 and 50d49a3.

📒 Files selected for processing (1)
  • Tests/FormbricksSDKTests/CalendarDaysBetweenTests.swift (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
Tests/FormbricksSDKTests/CalendarDaysBetweenTests.swift (1)
Sources/FormbricksSDK/Extension/Calendar+DaysBetween.swift (1)
  • numberOfDaysBetween (5-12)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-and-analyze

@mattinannt mattinannt merged commit 651f80e into main Sep 30, 2025
3 of 4 checks passed
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.

3 participants