logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

home_controller.rb (1823B)


  1. # frozen_string_literal: true
  2. class HomeController < ApplicationController
  3. before_action :authenticate_user!
  4. before_action :set_initial_state_json
  5. def index
  6. @body_classes = 'app-body'
  7. end
  8. private
  9. def authenticate_user!
  10. return if user_signed_in?
  11. matches = request.path.match(/\A\/web\/(statuses|accounts)\/([\d]+)\z/)
  12. if matches
  13. case matches[1]
  14. when 'statuses'
  15. status = Status.find_by(id: matches[2])
  16. if status && (status.public_visibility? || status.unlisted_visibility?)
  17. redirect_to(ActivityPub::TagManager.instance.url_for(status))
  18. return
  19. end
  20. when 'accounts'
  21. account = Account.find_by(id: matches[2])
  22. if account
  23. redirect_to(ActivityPub::TagManager.instance.url_for(account))
  24. return
  25. end
  26. end
  27. end
  28. matches = request.path.match(%r{\A/web/timelines/tag/(?<tag>.+)\z})
  29. redirect_to(matches ? tag_path(CGI.unescape(matches[:tag])) : default_redirect_path)
  30. end
  31. def set_initial_state_json
  32. serializable_resource = ActiveModelSerializers::SerializableResource.new(InitialStatePresenter.new(initial_state_params), serializer: InitialStateSerializer)
  33. @initial_state_json = serializable_resource.to_json
  34. end
  35. def initial_state_params
  36. {
  37. settings: Web::Setting.find_by(user: current_user)&.data || {},
  38. push_subscription: current_account.user.web_push_subscription(current_session),
  39. current_account: current_account,
  40. token: current_session.token,
  41. admin: Account.find_local(Setting.site_contact_username),
  42. }
  43. end
  44. def default_redirect_path
  45. if request.path.start_with?('/web')
  46. new_user_session_path
  47. elsif single_user_mode?
  48. short_account_path(Account.first)
  49. else
  50. about_path
  51. end
  52. end
  53. end