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

feat: add function to update channel in notifications preferences #34

Merged
merged 5 commits into from
Apr 11, 2024
Merged

feat: add function to update channel in notifications preferences #34

merged 5 commits into from
Apr 11, 2024

Conversation

stigi
Copy link
Member

@stigi stigi commented Apr 11, 2024

In this PR

This PR contains two things:

  • A new function to easily update a single channel in notification preferences:
user.preferences.update(categorySlug: categorySlug, channelSlug: channelSlug, enabled: enabled) { result in }
  • Additions to the Example app to demonstrate that & how it works

Discussion

The /notification_preferences endpoint is funny in the way that a GET request returns a different shape than a PUT request expects. The former returns labels while the later does not expect labels. It doesn't hurt passing them, and the PUT will simply ignore them, but I've opted for making this behaviour explicit in the docstrings, and unit tests.

The solution I went with simply drops the label keys when encoding NotificationPreferencesEntity (see changes in Source/Features/NotificationPreferences/Data/NotificationPreferencesEntity.swift). I tried alternative approaches, but the Harmony framework in use is expecting GET and PUT datasources to have the same entity type, making it impossible to have one with, and one without labels (see this line of code and the Get.T == T, Put.T == T). I've added a comment to the codebase that describes the behaviour.

Test Plan

Tested in the sample App as shown in this video:

notification.preferences.mp4

@smeijer smeijer changed the title Adds convenience function to update channel in notifications preferences feat: add function to update channel in notifications preferences Apr 11, 2024
@smeijer smeijer merged commit 1da2cbb into magicbell:main Apr 11, 2024
@stigi stigi deleted the ullrich/example-notification-preferences branch April 11, 2024 12:09
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