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

Activity stream #58

Merged
merged 3 commits into from
Oct 26, 2021
Merged

Activity stream #58

merged 3 commits into from
Oct 26, 2021

Conversation

olivierdalang
Copy link
Contributor

Initial implementation of activity stream using django-notifications.

I'm not 100% this is the best choice.
There's also django-activity-stream, which looks includes feature to follow/unfollow, but lacks seen/unseen.
There's also pinax-notifications, which looks like it it also takes care of the actual sending of the emails (the other ones don't do that)

But it is installed in a separate activity app, it should be relatively independent and not too hard to change afterwards. We also probably would need to sort out proper emailing solution on production as otherwise we'll very likely end up having all our sent emails flagged as spam.

Currently, it logs user creation, organization creation, membership addition/removal. But I didn't really think of what notification actually make sense. Can we list those ? (esp. for stuff linked to deltas/conflicts/etc).

@olivierdalang olivierdalang marked this pull request as draft July 15, 2021 15:52
@olivierdalang olivierdalang marked this pull request as ready for review August 10, 2021 12:31
@olivierdalang
Copy link
Contributor Author

Had some strange failures happening from tearDown methods of tests, when it deletes all created objects.

Not exactly sure why it failed though...

But anyways, the deletion in tearDown should not be needed, as Django's TestCase are ran in transactions that are rolled back, so I just removed that code.

Comment on lines 161 to 416
notifs_frequency = models.CharField(
max_length=25,
verbose_name=_("Email frequency for notifications"),
choices=NOTIF_CHOICES,
default=NOTIF_DAILY,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to have this a configuration like notifs_frequency_m = models.UIntField(min=0, choices=IntChoices)? This way it would be easier to change the configuration for the users.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently there's just four different django_crons set up (SendNotificationsJobImmediately, SendNotificationsJobHourly, SendNotificationsJobDaily, SendNotificationsJobWeekly).
If we wanted this to be customizable, we'd run every minute for everybody, but would then need to store last execution time for each user.

Not sure it's worth going down that rabbit hole ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

hm, isn't it enough to have a sent_at field in the Notification model? Whenever the cron runs, you call:

notifs = Notification.objects.filter(user=user, sent_at__isnull=True)
send_notif_emails(notifs)

Or you mean that we don't have sent_at field at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue is that if we wanted to make it easy to customize the frequency using an integer (minutes) rather than predefined choices, we'd also need some kind of scheduling strategy.

Currently it uses 4 different crons, on for each frequency, so we have predefined/hard-coded available schedules only.

It's not impossible to make it customizable, but then we'd need to store when the cron was last sending emails run for every user as they'd all run on the same minutely cron. IMO not really worth the complexity.

We could add more predefine frequencies if you think it's needed, but I think with immediate (minute), hourly, daily and weekly we've got most need covered ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok as per discussion implemented this (hehe not sure why this was overcomplex in my head ?). Used a DurationField instead of int field so it simplifies date arithmetic functions

@olivierdalang
Copy link
Contributor Author

Did you check the changes under docker-app/qfieldcloud/core/tests/test_* ? Not sure why these were required, but here test used to fail without those.

Do you want me to squash this in a more detailed way (differentiating strictly notification based stuff from the rest) ?

Also we've got branching migrations (42, merged in 46), should I linearize that ?

@suricactus
Copy link
Collaborator

Let me know when you think we are ready for a final review and merge.

(messes with test discovery)
(these are already rollback by the test's transaction)
@olivierdalang
Copy link
Contributor Author

ok cleaned up commit history (to isolate unrelated changes), ready for final review/merge

@suricactus suricactus added enhancement New feature or request minor Requires minor version change labels Oct 26, 2021
@suricactus suricactus merged commit e385249 into master Oct 26, 2021
@suricactus suricactus deleted the activity_stream branch October 26, 2021 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request minor Requires minor version change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants