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

Add a user setting that toggles notifications from accounts the user follows #20545

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

tonymet
Copy link

@tonymet tonymet commented Jan 20, 2024

What type of PR is this? (check all applicable)

  • [✅ ] Feature

Description

  • As a Forem user, I want to follow accounts I like (and have their content be higher up in my feed) without receiving notifications from them, so I can focus my attention on other notifications about my own content or community interaction.

BEFORE

m.notification_setting.new_post_notifications=true
image

image

AFTER

m.notification_setting.new_post_notifications=false
image

image

Status

  • ✅ proof-of-concept working
  • ✅ model user setting added notification_settings.new_post_notifications
  • ✅db migration for above setting
  • ✅ filter notifications controller , /notifications route hides new-post notifications
  • ✅ UI for toggling setting
  • ✅ avoid calling notification write path when setting is disabled.
  • ✅ fr translation
  • ❌ clean todos & debug logs
  • ❌test setting, controller, mentions are working

Related Tickets & Documents

QA Instructions, Screenshots, Recordings

Using rails console

$ bin/rails db:migrate
$ bin/rails console
# set your user id
m= User.where(:id=>13).first
 m.notification_setting.new_post_notifications=false;
 m.notification_setting.save()

Using UI

  1. visit settings/notifications
  2. toggle "send notifications when people I follow post new content"
  3. view notifications page

Visit visit http://localhost:3000/notifications and notice the new-post notifs are gone.

UI accessibility checklist

If your PR includes UI changes, please utilize this checklist:

  • Semantic HTML implemented?
  • Keyboard operability supported?
  • Checked with axe DevTools and addressed Critical and Serious issues?
  • Color contrast tested?

For more info, check out the
Forem Accessibility Docs.

Added/updated tests?

We encourage you to keep the code coverage percentage at 80% and above.

  • Yes
  • No, and this is why: please replace this line with details on why tests
    have not been included
  • I need help with writing tests

Are there any post deployment tasks we need to perform?

[optional] What gif best describes this PR or how it makes you feel?

alt_text

Copy link
Contributor

Thank you for opening this PR! We appreciate you!

For all pull requests coming from third-party forks we will need to
review the PR before we can process it through our CI pipelines.

A Forem Team member will review this contribution and get back to
you as soon as possible!

Copy link
Contributor

github-actions bot commented Jan 20, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@tonymet
Copy link
Author

tonymet commented Jan 20, 2024

@michael-tharrington FYI proof of concept seems to be working

@tonymet
Copy link
Author

tonymet commented Jan 20, 2024

I have read the CLA Document and I hereby sign the CLA

@tonymet
Copy link
Author

tonymet commented Jan 20, 2024

recheck

@tonymet tonymet force-pushed the new-post-notification-setting branch from 74f88c2 to 7f087d3 Compare January 21, 2024 00:44
@tonymet
Copy link
Author

tonymet commented Feb 4, 2024

@michael-tharrington could I ask your help finding a reviewer for initial feedback?

@tonymet
Copy link
Author

tonymet commented Feb 29, 2024

@lightalloy @maestromac could I ask your help finding a reviewer. there seems to be some moderate demand for this functionality and this PR is about 85% complete. just need feedback

Copy link
Contributor

@lightalloy lightalloy left a comment

Choose a reason for hiding this comment

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

Hey, @tonymet .
Thanks for your pr. There are a few things in the pr that need to be changed/improved:

The main change needed is where to put logic to avoid getting notifications when the setting is set to false (I added more details in one of the comments).

It's important to add specs:

  • most important: make sure that the notification is not created when the new notification setting is set to false (and is sent when it's set to true)
  • nice to have: request test to updating the notification settings

I have also left several smaller comments.

@notifications = if (params[:org_id].present? || params[:filter] == "org") && allowed_user?
organization_notifications
elsif params[:org_id].blank? && params[:filter].present?
filtered_notifications
else
elsif @user.notification_setting.new_post_notifications?
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of filtering notifications before displaying them, we should avoid creating notifications in the first place.
To do this we need to adjust finding article followers in Notifications::NotifiableAction::Send : exclude users with the corresponding notification setting set to false.

@@ -19,12 +19,15 @@ def index
num = @initial_page_size
end

logger.debug "notification setting: #{@user.notification_setting.inspect}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't forget to remove debug before the review.

@@ -3,6 +3,7 @@ class ReadsController < ApplicationController
def create
render plain: "" && return unless current_user

# TODO: notification controller read
Copy link
Contributor

Choose a reason for hiding this comment

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

I found TODOs on this pr not very informative, so it makes sense to remove them before the review (if you use them while developing).

@@ -63,6 +63,7 @@ en:
mobile_comment_notifications: Send me a push notification when someone replies to me in a comment thread
welcome_notifications: Send me occasional tips on how to enhance my %{community} experience
reaction_notifications: Send notifications when someone reacts to my content, such as comments or posts
new_post_notifications: Send notifications when people I follow post new content. When this is off, you can still see their content in your newsfeed
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't forget to add to the fr locale as well.

def change
add_column :users_notification_settings, :new_post_notifications, :boolean, default: true, null: false
end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing newline 👀

@tonymet
Copy link
Author

tonymet commented Mar 26, 2024

thanks for the code pointers i'll take a look . good advice to address the write side.

Could you point me to a good test case or api that could be used to cover the write side? I'd like to do an on-off test of the feature and confirm the notif is not written.

@tonymet tonymet force-pushed the new-post-notification-setting branch from 7f087d3 to 3b9d69a Compare March 27, 2024 20:50
@@ -89,6 +89,19 @@
end.to change(Notification, :count).by(2)
end

it "does not create a notification for each users with new-post-notification setting = false" do
Copy link
Author

Choose a reason for hiding this comment

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

@lightalloy can I ask your advice on a workable approach for this test? testing for :upsert_all or other Notifications:: methods doesn't seem to work.

Copy link
Contributor

github-actions bot commented Apr 1, 2024

Uffizzi Ephemeral Environment Deploying

☁️ https://app.uffizzi.com/github.com/forem/forem/pull/20545

⚙️ Updating now by workflow run 8513874376.

What is Uffizzi? Learn more!

@tonymet
Copy link
Author

tonymet commented May 2, 2024

anyone volunteer for a little support time to help me figure out the unit test and resolve the review? sometime over the next couple weeks. it would be good to put this one to use.

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.

Add an user setting that enables or disables notifications from accounts the user follows
2 participants