diff --git a/app/controllers/api/v1/groups/relationships_controller.rb b/app/controllers/api/v1/groups/relationships_controller.rb index 27781dd4..884c5916 100644 --- a/app/controllers/api/v1/groups/relationships_controller.rb +++ b/app/controllers/api/v1/groups/relationships_controller.rb @@ -7,7 +7,7 @@ class Api::V1::Groups::RelationshipsController < Api::BaseController respond_to :json def index - groups = Group.where(id: group_ids).select('id') + groups = Group.where(id: group_ids, is_archived: false).select('id') # .where doesn't guarantee that our results are in the same order # we requested them, so return the "right" order to the requestor. @groups = groups.index_by(&:id).values_at(*group_ids).compact diff --git a/app/controllers/api/v1/groups_controller.rb b/app/controllers/api/v1/groups_controller.rb index 99b6546d..3b3f5868 100644 --- a/app/controllers/api/v1/groups_controller.rb +++ b/app/controllers/api/v1/groups_controller.rb @@ -3,10 +3,10 @@ class Api::V1::GroupsController < Api::BaseController include Authorization - before_action -> { doorkeeper_authorize! :read, :'read:groups' }, only: [:index, :show] + # before_action -> { doorkeeper_authorize! :read, :'read:groups' }, only: [:index, :show] before_action -> { doorkeeper_authorize! :write, :'write:groups' }, except: [:index, :show] - before_action :require_user! + before_action :require_user!, except: [:index, :show] before_action :set_group, except: [:index, :create] def index @@ -14,10 +14,19 @@ class Api::V1::GroupsController < Api::BaseController when 'featured' @groups = Group.where(is_featured: true, is_archived: false).limit(100).all when 'new' + if !current_user + render json: { error: 'This method requires an authenticated user' }, status: 422 + end @groups = Group.where(is_archived: false).limit(24).order('created_at DESC').all when 'member' + if !current_user + render json: { error: 'This method requires an authenticated user' }, status: 422 + end @groups = Group.joins(:group_accounts).where(is_archived: false, group_accounts: { account: current_account }).order('group_accounts.id DESC').all when 'admin' + if !current_user + render json: { error: 'This method requires an authenticated user' }, status: 422 + end @groups = Group.joins(:group_accounts).where(is_archived: false, group_accounts: { account: current_account, role: :admin }).all end @@ -75,7 +84,7 @@ class Api::V1::GroupsController < Api::BaseController private def set_group - @group = Group.find(params[:id]) + @group = Group.where(id: params[:id], is_archived: false).first end def group_params diff --git a/app/controllers/api/v1/timelines/group_controller.rb b/app/controllers/api/v1/timelines/group_controller.rb index 6ef63ef1..150ae398 100644 --- a/app/controllers/api/v1/timelines/group_controller.rb +++ b/app/controllers/api/v1/timelines/group_controller.rb @@ -1,23 +1,25 @@ # frozen_string_literal: true class Api::V1::Timelines::GroupController < Api::BaseController - before_action -> { doorkeeper_authorize! :read, :'read:groups' } - before_action :require_user! before_action :set_group before_action :set_statuses after_action :insert_pagination_headers, unless: -> { @statuses.empty? } def show - render json: @statuses, - each_serializer: REST::StatusSerializer, - relationships: StatusRelationshipsPresenter.new(@statuses, current_user.account_id) + if current_user + render json: @statuses, + each_serializer: REST::StatusSerializer, + relationships: StatusRelationshipsPresenter.new(@statuses, current_user.account_id) + else + render json: @statuses, each_serializer: REST::StatusSerializer + end end private def set_group - @group = Group.find(params[:id]) + @group = Group.where(id: params[:id], is_archived: false).first end def set_statuses @@ -29,10 +31,18 @@ class Api::V1::Timelines::GroupController < Api::BaseController end def group_statuses - statuses = group_timeline_statuses.without_replies.paginate_by_id( - limit_param(DEFAULT_STATUSES_LIMIT), - params_slice(:max_id, :since_id, :min_id) - ).reject { |status| FeedManager.instance.filter?(:home, status, current_account.id) } + statuses = nil + if current_account + statuses = group_timeline_statuses.without_replies.paginate_by_id( + limit_param(DEFAULT_STATUSES_LIMIT), + params_slice(:max_id, :since_id, :min_id) + ).reject { |status| FeedManager.instance.filter?(:home, status, current_account.id) } + else + statuses = group_timeline_statuses.without_replies.paginate_by_id( + limit_param(DEFAULT_STATUSES_LIMIT), + params_slice(:max_id, :since_id, :min_id) + ) + end if truthy_param?(:only_media) # `SELECT DISTINCT id, updated_at` is too slow, so pluck ids at first, and then select id, updated_at with ids. diff --git a/app/controllers/react_controller.rb b/app/controllers/react_controller.rb index c5e0ffcb..d4642a6c 100644 --- a/app/controllers/react_controller.rb +++ b/app/controllers/react_controller.rb @@ -5,6 +5,7 @@ class ReactController < ApplicationController before_action :set_referrer_policy_header, only: :react before_action :set_initial_state_json, only: :react before_action :set_data_for_meta, only: :react + before_action :set_instance_presenter def react # @@ -13,9 +14,12 @@ class ReactController < ApplicationController private def set_data_for_meta - return if find_route_matches + return if find_route_matches && current_account - if find_public_route_matches + if request.path.include?("/groups/") + groupIdFromPath = request.path.sub("/groups", "").gsub("/", "") + @group = Group.where(id: groupIdFromPath, is_archived: false).first + elsif find_public_route_matches return elsif request.path.count("/") == 1 && !request.path.include?("@") acctFromPath = request.path.sub("/", "") @@ -40,7 +44,7 @@ class ReactController < ApplicationController end def find_public_route_matches - request.path.match(/\A\/(about|search|explore)/) + request.path.match(/\A\/(about|search|groups|explore)/) end def set_initial_state_json @@ -67,4 +71,8 @@ class ReactController < ApplicationController def set_referrer_policy_header response.headers['Referrer-Policy'] = 'origin' end + + def set_instance_presenter + @instance_presenter = InstancePresenter.new + end end diff --git a/app/helpers/stream_entries_helper.rb b/app/helpers/stream_entries_helper.rb index f3964d9f..d1700151 100644 --- a/app/helpers/stream_entries_helper.rb +++ b/app/helpers/stream_entries_helper.rb @@ -68,6 +68,10 @@ module StreamEntriesHelper return "The latest Gabs from #{display_name(account)} (@#{account.username}). #{account.note}" end + def group_description(group) + return "#{group.title} on Gab. #{group.description}" + end + def media_summary(status) attachments = { image: 0, video: 0 } diff --git a/app/javascript/gabsocial/features/group_timeline.js b/app/javascript/gabsocial/features/group_timeline.js index 4a9190ee..6458fb72 100644 --- a/app/javascript/gabsocial/features/group_timeline.js +++ b/app/javascript/gabsocial/features/group_timeline.js @@ -78,7 +78,7 @@ class GroupTimeline extends ImmutablePureComponent { const { collapsed } = this.state const { id } = this.props.params - if (typeof group === 'undefined' || !relationships) { + if (typeof group === 'undefined') { return } else if (group === false) { return diff --git a/app/javascript/gabsocial/features/ui/ui.js b/app/javascript/gabsocial/features/ui/ui.js index bf3153c9..3fbc3c69 100644 --- a/app/javascript/gabsocial/features/ui/ui.js +++ b/app/javascript/gabsocial/features/ui/ui.js @@ -175,7 +175,7 @@ class SwitchingArea extends PureComponent { - + @@ -184,7 +184,7 @@ class SwitchingArea extends PureComponent { { /* */} - + diff --git a/app/views/groups/_meta.html.haml b/app/views/groups/_meta.html.haml new file mode 100644 index 00000000..8b5f40f5 --- /dev/null +++ b/app/views/groups/_meta.html.haml @@ -0,0 +1,6 @@ +- content_for :page_title do + = "#{group.title} / Group • #{site_hostname}" + +- content_for :header_tags do + = opengraph 'og:type', 'website' + = render 'groups/og', group: group, url: "https://gab.com/groups/#{group.id}" \ No newline at end of file diff --git a/app/views/groups/_og.html.haml b/app/views/groups/_og.html.haml new file mode 100644 index 00000000..e0e11b0c --- /dev/null +++ b/app/views/groups/_og.html.haml @@ -0,0 +1,12 @@ +- description = group_description(group) + +%meta{ name: 'description', content: description }/ + += opengraph 'og:url', url += opengraph 'og:site_name', site_title += opengraph 'og:title', "#{group.title} / Group • #{site_hostname}" += opengraph 'og:description', description += opengraph 'og:image', full_asset_url(group.cover_image.url(:original)) += opengraph 'og:image:width', '120' += opengraph 'og:image:height', '120' += opengraph 'twitter:card', 'summary'