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

Modify "notify_tag_added" mailer to include tag variants like "questions:____" #3868

Closed
jywarren opened this issue Oct 31, 2018 · 3 comments · Fixed by #6407
Closed

Modify "notify_tag_added" mailer to include tag variants like "questions:____" #3868

jywarren opened this issue Oct 31, 2018 · 3 comments · Fixed by #6407
Labels
help wanted requires help by anyone willing to contribute Ruby testing issues are usually for adding unit tests, integration tests or any other tests for a feature

Comments

@jywarren
Copy link
Member

This section triggers email notifications for tags, like wetlands, if you follow that tag (https://publiclab.org/tags)

def notify_tag_added(node, tag, tagging_user)
@tag = tag
@node = node
@tagging_user = tagging_user
given_tags = node.tags.reject { |t| t == tag }
users_to_email = tag.followers_who_dont_follow_tags(given_tags)
users_with_everything_tag = Tag.followers('everything')
final_users_ids = nil
if !users_to_email.nil? && !users_with_everything_tag.nil?
final_users_ids = users_to_email.collect(&:id) - users_with_everything_tag.collect(&:uid)
elsif !users_to_email.nil?
final_users_ids = users_to_email.collect(&:id)
end
final_users_to_email = User.find(final_users_ids)
recipients = []
final_users_to_email.each do |user|
unless user.id == tagging_user.id
recipients << user.email
end
end
@footer = feature('email-footer')
mail(
to: "notifications@#{ActionMailer::Base.default_url_options[:host]}",
bcc: recipients,
subject: "#{node.title} (##{node.id})"
)
end

however, @steviepubliclab and I think it'd be great if it ALSO triggered for some variants of the initial tag. So for wetlands subscribers, these should also trigger a notification:

  • question:wetlands
  • activity:wetlands
  • anything ending in ____:wetlands

We could add these notifications by searching for a colon; this will be a bit complex:

given_tags = node.tags.reject { |t| t == tag } # this collects tags already on the node, except the current tag
users_to_email = tag.followers_who_dont_follow_tags(given_tags) # who is NOT already notified
# add normal tag version too if it exists:
simple_tag = tag.name.split(':').second
if tag.name.includes?(':') && Tag.find_by(name: simple_tag)
  # now add followers of the normal tag who are NOT already notified
  users_to_email += Tag.find_by(name: simple_tag).followers_who_dont_follow_tags(given_tags)
end

I think the ideal is to create a test in https://github.com/publiclab/plots2/blob/master/test/unit/subscription_mailer_test.rb where we subscribe a user to the simple tag like simpletag, then check that they get a notification when a post goes up for question:simpletag.

This is a bit complex, but we would love some help with it!

@jywarren jywarren added testing issues are usually for adding unit tests, integration tests or any other tests for a feature help wanted requires help by anyone willing to contribute Ruby labels Oct 31, 2018
@jywarren jywarren added this to the Tagging and topics milestone Oct 31, 2018
@faithngetich
Copy link
Contributor

@jywarren I'd like to help work on this issue.

@jywarren
Copy link
Member Author

jywarren commented Nov 7, 2018 via email

@jywarren
Copy link
Member Author

jywarren commented Oct 1, 2019

This could be implemented with a similar system to #6367, actually!

@jywarren jywarren changed the title Modify "notify_tag_added" mailer to include tag variants Modify "notify_tag_added" mailer to include tag variants like "questions:____" Oct 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted requires help by anyone willing to contribute Ruby testing issues are usually for adding unit tests, integration tests or any other tests for a feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants