favorites: remove is_favorited attribute from post API.

* Remove the data-is-favorited attribute from post thumbnails.
* Remove the is_favorited attribute from the /posts.json API.
* Remove the fav_string attribute from the /posts.json API (only visible
  to moderators).
* Change `Post#favorited_by?` to not use the fav_string.

Further addresses #4652 by eliminating the last places where fav_string
was used.
This commit is contained in:
evazion
2021-01-03 19:53:11 -06:00
parent 98ee6c31c1
commit de16d31135
7 changed files with 9 additions and 16 deletions

View File

@@ -762,12 +762,11 @@ class Post < ApplicationRecord
update_column(:fav_count, fav_count)
end
def favorited_by?(user_id = CurrentUser.id)
fav_string.match?(/(?:\A| )fav:#{user_id}(?:\Z| )/)
def favorited_by?(user)
return false if user.is_anonymous?
Favorite.exists?(post: self, user: user)
end
alias is_favorited? favorited_by?
def append_user_to_fav_string(user_id)
update_column(:fav_string, (fav_string + " fav:#{user_id}").strip)
clean_fav_string! if clean_fav_string?