Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change interaction modal in web UI #26075

Merged
merged 16 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
3a187d8
Change interaction modal in web UI
Gargron May 4, 2023
bba22bf
Perform webfinger queries from a specific iframe with its own CSP
ClearlyClaire Jul 19, 2023
d2b1239
Add instance search autocompletion without ElasticSearch
ClearlyClaire Jul 19, 2023
741da42
Always add input at the top of the suggestions and make it feel more …
ClearlyClaire Jul 19, 2023
2a11d1e
Use post/account URI rather than URL in interaction modals
ClearlyClaire Jul 19, 2023
ffb6c06
Do not auto-complete on inputs that are not domains
ClearlyClaire Jul 19, 2023
36034a2
Change wording of interaction modal
ClearlyClaire Jul 19, 2023
60ad770
Add support for serving instance actor JRD for webfinger queries to a…
ClearlyClaire Jul 20, 2023
27b3a7a
Fix resource URI in bare domain webfinger request
ClearlyClaire Jul 20, 2023
39a75ce
Change interaction modal and interaction helper frame to handle as:pr…
ClearlyClaire Jul 20, 2023
34551a0
[WiP] Expose and add support for https://www.w3.org/ns/activitystream…
ClearlyClaire Jul 20, 2023
30c7091
Revert "[WiP] Expose and add support for https://www.w3.org/ns/activi…
ClearlyClaire Jul 20, 2023
b9ea6b9
Revert "Change interaction modal and interaction helper frame to hand…
ClearlyClaire Jul 20, 2023
c8269da
Rewrite the remote interaction helper script in TypeScript
ClearlyClaire Jul 20, 2023
3ab95ea
Fix unnecessary access to session in RemoteInteractionHelperController
ClearlyClaire Jul 20, 2023
7ce1c15
Redesign and reword the modal slightly
ClearlyClaire Jul 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/chewy/instances_index.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class InstancesIndex < Chewy::Index
settings index: { refresh_interval: '30s' }

index_scope ::Instance.searchable

root date_detection: false do
field :domain, type: 'text', index_prefixes: { min_chars: 1 }
field :accounts_count, type: 'long'
end
end
2 changes: 1 addition & 1 deletion app/controllers/api/v1/instances/peers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def current_user

def index
cache_even_if_authenticated!
render_with_cache(expires_in: 1.day) { Instance.where.not(domain: DomainBlock.select(:domain)).pluck(:domain) }
render_with_cache(expires_in: 1.day) { Instance.searchable.pluck(:domain) }
end

private
Expand Down
45 changes: 45 additions & 0 deletions app/controllers/api/v1/peers/search_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

class Api::V1::Peers::SearchController < Api::BaseController
before_action :require_enabled_api!
before_action :set_domains

skip_before_action :require_authenticated_user!, unless: :whitelist_mode?
skip_around_action :set_locale

vary_by ''

def index
cache_even_if_authenticated!
render json: @domains
end

private

def require_enabled_api!
head 404 unless Setting.peers_api_enabled && !whitelist_mode?
ClearlyClaire marked this conversation as resolved.
Show resolved Hide resolved
end

def set_domains
return if params[:q].blank?

if Chewy.enabled?
@domains = InstancesIndex.query(function_score: {
query: {
prefix: {
domain: params[:q],
},
},

field_value_factor: {
field: 'accounts_count',
modifier: 'log2p',
},
}).limit(10).pluck(:domain)
else
domain = params[:q].strip
domain = TagManager.instance.normalize_domain(domain)
@domains = Instance.searchable.where(Instance.arel_table[:domain].matches("#{Instance.sanitize_sql_like(domain)}%", false, true)).limit(10).pluck(:domain)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish we didn't have to do this every time. The sorting logic is going to be slightly different here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, but requiring Elasticsearch is a significant ask :/

end
end
end
21 changes: 2 additions & 19 deletions app/controllers/authorize_interactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,19 @@
class AuthorizeInteractionsController < ApplicationController
include Authorization

layout 'modal'

before_action :authenticate_user!
before_action :set_body_classes
before_action :set_resource

def show
if @resource.is_a?(Account)
render :show
redirect_to web_url("@#{@resource.pretty_acct}")
elsif @resource.is_a?(Status)
redirect_to web_url("@#{@resource.account.pretty_acct}/#{@resource.id}")
else
render :error
not_found
end
end

def create
if @resource.is_a?(Account) && FollowService.new.call(current_account, @resource, with_rate_limit: true)
render :success
else
render :error
end
rescue ActiveRecord::RecordNotFound
render :error
end

private

def set_resource
Expand Down Expand Up @@ -61,8 +48,4 @@ def parsed_uri
def uri_param
params[:uri] || params.fetch(:acct, '').delete_prefix('acct:')
end

def set_body_classes
@body_classes = 'modal-layout'
end
end
43 changes: 43 additions & 0 deletions app/controllers/remote_interaction_helper_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

class RemoteInteractionHelperController < ApplicationController
vary_by ''

skip_before_action :require_functional!
skip_around_action :set_locale
skip_before_action :update_user_sign_in

content_security_policy do |p|
# We inherit the normal `script-src`

# Set every directive that does not have a fallback
p.default_src :none
p.form_action :none
p.base_uri :none

# Disable every directive with a fallback to cut on response size
p.base_uri false
p.font_src false
p.img_src false
p.style_src false
p.media_src false
p.frame_src false
p.manifest_src false
p.connect_src false
p.child_src false
p.worker_src false

# Widen the directives that we do need
p.frame_ancestors :self
p.connect_src :https
end

def index
expires_in(5.minutes, public: true, stale_while_revalidate: 30.seconds, stale_if_error: 1.day)

response.headers['X-Frame-Options'] = 'SAMEORIGIN'
response.headers['Referrer-Policy'] = 'no-referrer'

render layout: 'helper_frame'
end
end
1 change: 1 addition & 0 deletions app/controllers/well_known/webfinger_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def show

def set_account
username = username_from_resource

@account = begin
if username == Rails.configuration.x.local_domain
Account.representative
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/mastodon/containers/status_container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ const mapDispatchToProps = (dispatch, { intl, contextType }) => ({
modalProps: {
type,
accountId: status.getIn(['account', 'id']),
url: status.get('url'),
url: status.get('uri'),
},
}));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
modalProps: {
type: 'follow',
accountId: account.get('id'),
url: account.get('url'),
url: account.get('uri'),
},
}));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ class Search extends PureComponent {
this.setState({ expanded: false, selectedOption: -1 });
};

findTarget = () => {
return this.searchForm;
};

handleHashtagClick = () => {
const { router } = this.context;
const { value, onClickSearchResult } = this.props;
Expand Down
Loading