From aed8caccf2deb4da1bea32356ea91a4208bdc52e Mon Sep 17 00:00:00 2001 From: Jesse Tomchak Date: Fri, 17 Nov 2023 18:04:52 -0700 Subject: [PATCH] check mammoth user versus is personalized (#214) * Checking user status as a valid mammoth user, rather than specifically a 'personalized' mammoth user --- .../api/v3/timelines/for_you_controller.rb | 13 ++++++++----- app/lib/personal_for_you.rb | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/v3/timelines/for_you_controller.rb b/app/controllers/api/v3/timelines/for_you_controller.rb index 0c8e90e7a..91cbe79b0 100644 --- a/app/controllers/api/v3/timelines/for_you_controller.rb +++ b/app/controllers/api/v3/timelines/for_you_controller.rb @@ -8,7 +8,7 @@ class Api::V3::Timelines::ForYouController < Api::BaseController after_action :insert_pagination_headers, only: [:show], unless: -> { @statuses.empty? } def index - result = PersonalForYou.new.mammoth_user(acct_param) + result = PersonalForYou.new.mammoth_user_profile(acct_param) render json: result end @@ -40,11 +40,14 @@ def set_for_you_default @is_beta_program = beta_param end + # Check and see if they're a Mammoth User + # If they are get their foryou feed + # Otherwise send them MammothPicks def set_for_you_feed should_personalize = validate_mammoth_account if should_personalize # Getting personalized - fufill_personalized_statuses + fufill_foryou_statuses else # Getting the public feed enroll_beta @@ -53,12 +56,12 @@ def set_for_you_feed end # Check account_from_acct finds an account - # Check the For You Beta Personal List + # Check AccountRelay that they are a Mammoth 2.0 User # @return [Boolean] def validate_mammoth_account return false if @account.nil? - PersonalForYou.new.personalized_mammoth_user?(acct_param) + PersonalForYou.new.mammoth_user?(acct_param) end # Only checking for beta parameter @@ -75,7 +78,7 @@ def enroll_beta # Will not return an empty list # If no statuses are found for the user, # but they are on the beta list then we return the default Public Feed - def fufill_personalized_statuses + def fufill_foryou_statuses statuses = cached_personalized_statuses if statuses.empty? cached_list_statuses diff --git a/app/lib/personal_for_you.rb b/app/lib/personal_for_you.rb index 9e94bdfdf..a4a5369f1 100644 --- a/app/lib/personal_for_you.rb +++ b/app/lib/personal_for_you.rb @@ -55,7 +55,7 @@ def acct_relay_users # If the for_you setting is public, get waitlist feature # and check for enrollment. # for_you_setting type can be 'public' | 'personal' | 'waitlist' - def mammoth_user(acct) + def mammoth_user_profile(acct) user = user(acct) return user unless user[:for_you_settings][:type] == 'public' @@ -65,6 +65,15 @@ def mammoth_user(acct) user end + # Check AcctRelay if the user is a Mammoth User + # Could be personalized or not. either way. + def fetch_mammoth_user?(acct) + response = HTTP.headers({ Authorization: ACCOUNT_RELAY_AUTH, 'Content-Type': 'application/json' }).get( + "https://#{ACCOUNT_RELAY_HOST}/api/v1/foryou/users/#{acct}/mammoth" + ) + JSON.parse(response.body, symbolize_names: true) + end + # Get Mammoth user details # Includes any settings/preferences/configurations for feeds # Not caching user. If it becomes an issue cache it at the source. AcctRelay @@ -91,6 +100,10 @@ def personalized_mammoth_user?(acct) user(acct).dig(:for_you_settings, :type) == 'personal' end + def mammoth_user?(acct) + fetch_mammoth_user?(acct)[:mammoth_user] + end + # PUT Mammoth user for you settings / preferences / status # Bust User cache when updating user settings def update_user(acct, payload)