FIX: Base topic details message on current category and tag tracking state (#12937)

The user may have changed their category or tag tracking settings since a topic was tracked/watched based on those settings in the past. In that case we need to alter the reason message we show them otherwise it is very confusing for the end user to be told they are tracking a topic because of a category, when they are no longer tracking that category.

For example: "You will see a count of new replies because you are tracking this category." becomes: "You will see a count of new replies because you were tracking this category in the past."

To do this, it was necessary to add tag and category tracking info to current user serializer. I improved the serializer code so it only does 3 SQL queries instead of 9 to get the tracking information for tags and categories for the current user.
This commit is contained in:
Martin Brennan
2021-05-06 09:14:07 +10:00
committed by GitHub
parent c792c2b5fe
commit 72648dd576
14 changed files with 530 additions and 64 deletions

View File

@ -207,39 +207,39 @@ class UserSerializer < UserCardSerializer
### PRIVATE ATTRIBUTES
###
def muted_tags
TagUser.lookup(object, :muted).joins(:tag).pluck('tags.name')
tags_with_notification_level(:muted)
end
def tracked_tags
TagUser.lookup(object, :tracking).joins(:tag).pluck('tags.name')
tags_with_notification_level(:tracked)
end
def watching_first_post_tags
TagUser.lookup(object, :watching_first_post).joins(:tag).pluck('tags.name')
tags_with_notification_level(:watching_first_post)
end
def watched_tags
TagUser.lookup(object, :watching).joins(:tag).pluck('tags.name')
tags_with_notification_level(:watching)
end
def muted_category_ids
CategoryUser.lookup(object, :muted).pluck(:category_id)
categories_with_notification_level(:muted)
end
def regular_category_ids
CategoryUser.lookup(object, :regular).pluck(:category_id)
categories_with_notification_level(:regular)
end
def tracked_category_ids
CategoryUser.lookup(object, :tracking).pluck(:category_id)
categories_with_notification_level(:tracking)
end
def watched_category_ids
CategoryUser.lookup(object, :watching).pluck(:category_id)
categories_with_notification_level(:watching)
end
def watched_first_post_category_ids
CategoryUser.lookup(object, :watching_first_post).pluck(:category_id)
categories_with_notification_level(:watching_first_post)
end
def muted_usernames