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

Revamp Notif Logic #324

Merged
merged 6 commits into from
Nov 17, 2024
Merged

Revamp Notif Logic #324

merged 6 commits into from
Nov 17, 2024

Conversation

vcai122
Copy link
Contributor

@vcai122 vcai122 commented Nov 11, 2024

Refactors notification logic, allow for multiple tokens per user, restructure to support android (very soon), make views cleaner, etc.

For future PR: fix remaining test cases and management commands.

@vcai122 vcai122 requested a review from tuneerroy November 11, 2024 15:49
@vcai122 vcai122 marked this pull request as draft November 11, 2024 15:50
Base automatically changed from remove-me-groups to master November 12, 2024 03:16
Copy link
Contributor

@tuneerroy tuneerroy left a comment

Choose a reason for hiding this comment

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

Did we want to handle switching users to holding a list of tokens rather than individual tokens in this PR or a later PR? (for ex, user has Android phone + iPad)

is_dev = models.BooleanField(default=False)

class AndroidNotificationToken(NotificationToken):
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

would an is_dev field not make sense here too? I don't know the Android notif system but would be surprised if they didn't have similar optionality to iOS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

after talking to android didn't seem like they had

enabled = models.BooleanField(default=True)

# service = models.CharField(max_length=30, choices=SERVICE_OPTIONS, default=SERVICE_PENN_MOBILE)
# enabled = models.BooleanField(default=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume you'll delete these commented out code once you merge the PR?

return success_users, []
failed_users = list(set(users) - set(success_users))
return success_users, failed_users
send_immediate_notifications(tokens, title, body, category, is_dev, is_shadow)
Copy link
Contributor

Choose a reason for hiding this comment

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

thoughts on doing:

params = (tokens, title, body, category, is_dev, is_shadow)
if delay:
    send_delayed_notifications(*params, delay=delay)
else:
    send_immediate_notifications(*params)

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 feel like its overkill, we want to supply an easy to use interface, forcing the user to pass a tuple is more inconvenient.

I mean you can just take it in as args or kwargs and just shove it in that way? but um, this current one feels safer? maybe?

Copy link
Contributor

Choose a reason for hiding this comment

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

this wouldn't change the interface of the functions? note the *params, its just being deconstructed.

# def update(self, instance, validated_data):
# if instance.service != validated_data["service"]:
# raise serializers.ValidationError(detail={"detail": "Cannot change setting service."})
# return super().update(instance, validated_data)
Copy link
Contributor

Choose a reason for hiding this comment

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

just a note so we can delete this code before merge PR?

Return notification tokens of user.
"""

class NotificationTokenView(APIView, ABC):
Copy link
Contributor

Choose a reason for hiding this comment

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

yoooo ABC lol

class NotificationServiceView(APIView):
permission_classes = [IsAuthenticated]

# TODO: this is becoming a common pattern, consider abstracting
Copy link
Contributor

Choose a reason for hiding this comment

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

note on the TODO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nah this seems low low priority, will be different PR


users_with_service = service_obj.enabled_users.filter(username__in=usernames)

tokens = list(IOSNotificationToken.objects.filter(user__in=users_with_service, is_dev=is_dev).values_list(
Copy link
Contributor

Choose a reason for hiding this comment

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

just an opinion but probably prettier to extract this into a get_tokens() method within the post method but I defer to your judgement

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ifl its fine because its just doing 1 thing. Was going to with the 2 lines but then realized I need users_with_service later.

@vcai122
Copy link
Contributor Author

vcai122 commented Nov 14, 2024

Did we want to handle switching users to holding a list of tokens rather than individual tokens in this PR or a later PR? (for ex, user has Android phone + iPad)

I think we do right? I changed the user relation on token to be a foreign key.

Copy link

codecov bot commented Nov 17, 2024

Codecov Report

Attention: Patch coverage is 92.77108% with 6 lines in your changes missing coverage. Please review.

Project coverage is 90.59%. Comparing base (44965e9) to head (b04eafa).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
backend/user/notifications.py 55.55% 4 Missing ⚠️
backend/user/views.py 96.42% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #324      +/-   ##
==========================================
- Coverage   90.83%   90.59%   -0.24%     
==========================================
  Files          63       61       -2     
  Lines        2629     2552      -77     
==========================================
- Hits         2388     2312      -76     
+ Misses        241      240       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vcai122 vcai122 marked this pull request as ready for review November 17, 2024 05:22
@vcai122 vcai122 merged commit 8315c52 into master Nov 17, 2024
8 of 9 checks passed
@vcai122 vcai122 deleted the revamp-notifications branch November 17, 2024 17:09
Copy link

sentry-io bot commented Nov 24, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ UnreadablePostError: error during read(16) on wsgi.input /api/user/notifications/tokens/ios/{token}/ View Issue

Did you find this useful? React with a 👍 or 👎

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