Skip to content

Commit

Permalink
Merge pull request #847 from kmycode/upstream-20240913
Browse files Browse the repository at this point in the history
Upstream 20240913
  • Loading branch information
kmycode committed Sep 13, 2024
2 parents 3277819 + fc9d27f commit fe051aa
Show file tree
Hide file tree
Showing 392 changed files with 3,757 additions and 3,233 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ module.exports = defineConfig({
],

parserOptions: {
project: true,
projectService: true,
tsconfigRootDir: __dirname,
},

Expand Down
3 changes: 2 additions & 1 deletion .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
annotations: false
comment: false # Do not leave PR comments
coverage:
status:
Expand All @@ -10,3 +9,5 @@ coverage:
default:
# GitHub status check is not blocking
informational: true
github_checks:
annotations: false
20 changes: 10 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,17 @@ GEM
attr_required (1.0.2)
awrence (1.2.1)
aws-eventstream (1.3.0)
aws-partitions (1.970.0)
aws-sdk-core (3.203.0)
aws-partitions (1.974.0)
aws-sdk-core (3.205.0)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.9)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.89.0)
aws-sdk-core (~> 3, >= 3.203.0)
aws-sdk-kms (1.91.0)
aws-sdk-core (~> 3, >= 3.205.0)
aws-sigv4 (~> 1.5)
aws-sdk-s3 (1.160.0)
aws-sdk-core (~> 3, >= 3.203.0)
aws-sdk-s3 (1.162.0)
aws-sdk-core (~> 3, >= 3.205.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.5)
aws-sigv4 (1.9.1)
Expand Down Expand Up @@ -458,7 +458,7 @@ GEM
nokogiri (1.16.7)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
oj (3.16.5)
oj (3.16.6)
bigdecimal (>= 3.0)
ostruct (>= 0.2)
omniauth (2.1.2)
Expand Down Expand Up @@ -590,7 +590,7 @@ GEM
parslet (2.0.0)
pastel (0.8.0)
tty-color (~> 0.5)
pg (1.5.7)
pg (1.5.8)
pghero (3.6.0)
activerecord (>= 6.1)
premailer (1.27.0)
Expand All @@ -601,7 +601,7 @@ GEM
actionmailer (>= 3)
net-smtp
premailer (~> 1.7, >= 1.7.9)
propshaft (0.9.1)
propshaft (1.0.0)
actionpack (>= 7.0.0)
activesupport (>= 7.0.0)
rack
Expand Down Expand Up @@ -691,7 +691,7 @@ GEM
redlock (1.3.2)
redis (>= 3.0.0, < 6.0)
regexp_parser (2.9.2)
reline (0.5.9)
reline (0.5.10)
io-console (~> 0.5)
request_store (1.6.0)
rack (>= 1.4)
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/concerns/web_app_controller_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ module WebAppControllerConcern

before_action :redirect_unauthenticated_to_permalinks!
before_action :set_app_body_class

content_security_policy do |p|
policy = ContentSecurityPolicy.new

if policy.sso_host.present?
p.form_action policy.sso_host
else
p.form_action :none
end
end
end

def skip_csrf_meta_tags?
Expand Down
5 changes: 0 additions & 5 deletions app/controllers/redirect/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class Redirect::BaseController < ApplicationController
vary_by 'Accept-Language'

before_action :set_resource
before_action :set_app_body_class

def show
@redirect_path = ActivityPub::TagManager.instance.url_for(@resource)
Expand All @@ -14,10 +13,6 @@ def show

private

def set_app_body_class
@body_classes = 'app-body'
end

def set_resource
raise NotImplementedError
end
Expand Down
20 changes: 18 additions & 2 deletions app/controllers/settings/verifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,30 @@

class Settings::VerificationsController < Settings::BaseController
before_action :set_account
before_action :set_verified_links

def show
@verified_links = @account.fields.select(&:verified?)
def show; end

def update
if UpdateAccountService.new.call(@account, account_params)
ActivityPub::UpdateDistributionWorker.perform_async(@account.id)
redirect_to settings_verification_path, notice: I18n.t('generic.changes_saved_msg')
else
render :show
end
end

private

def account_params
params.require(:account).permit(:attribution_domains_as_text)
end

def set_account
@account = current_account
end

def set_verified_links
@verified_links = @account.fields.select(&:verified?)
end
end
5 changes: 0 additions & 5 deletions app/controllers/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class StatusesController < ApplicationController
before_action :require_account_signature!, only: [:show, :activity], if: -> { request.format == :json && authorized_fetch_mode? }
before_action :set_status
before_action :redirect_to_original, only: :show
before_action :set_body_classes, only: :embed

after_action :set_link_headers

Expand Down Expand Up @@ -51,10 +50,6 @@ def embed

private

def set_body_classes
@body_classes = 'with-modals'
end

def set_link_headers
response.headers['Link'] = LinkHeader.new(
[[ActivityPub::TagManager.instance.uri_for(@status), [%w(rel alternate), %w(type application/activity+json)]]]
Expand Down
8 changes: 0 additions & 8 deletions app/helpers/accounts_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ def acct(account)
end
end

def account_action_button(account)
return if account.memorial? || account.moved?

link_to ActivityPub::TagManager.instance.url_for(account), class: 'button logo-button', target: '_new' do
safe_join([logo_as_symbol, t('accounts.follow')])
end
end

def account_formatted_stat(value)
number_to_human(value, precision: 3, strip_insignificant_zeros: true)
end
Expand Down
4 changes: 0 additions & 4 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,6 @@ def prerender_custom_emojis(html, custom_emojis, other_options = {})
EmojiFormatter.new(html, custom_emojis, other_options.merge(animate: prefers_autoplay?)).to_s
end

def prerender_custom_emojis_from_hash(html, custom_emojis_hash)
prerender_custom_emojis(html, JSON.parse([custom_emojis_hash].to_json, object_class: OpenStruct)) # rubocop:disable Style/OpenStructUse
end

def mascot_url
full_asset_url(instance_presenter.mascot&.file&.url || frontend_asset_path('images/elephant_ui_plane.svg'))
end
Expand Down
1 change: 1 addition & 0 deletions app/helpers/context_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module ContextHelper
'cipherText' => 'toot:cipherText',
},
suspended: { 'toot' => 'http://joinmastodon.org/ns#', 'suspended' => 'toot:suspended' },
attribution_domains: { 'toot' => 'http://joinmastodon.org/ns#', 'attributionDomains' => { '@id' => 'toot:attributionDomains', '@type' => '@id' } },
}.freeze

def full_context
Expand Down
36 changes: 0 additions & 36 deletions app/helpers/media_component_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,6 @@ def render_media_gallery_component(status, **options)
end
end

def render_card_component(status, **options)
component_params = {
sensitive: sensitive_viewer?(status, current_account),
card: serialize_status_card(status).as_json,
}.merge(**options)

react_component :card, component_params
end

def render_poll_component(status, **options)
component_params = {
disabled: true,
poll: serialize_status_poll(status).as_json,
}.merge(**options)

react_component :poll, component_params do
render partial: 'statuses/poll', locals: { status: status, poll: status.preloadable_poll, autoplay: prefers_autoplay? }
end
end

private

def serialize_media_attachment(attachment)
Expand All @@ -86,22 +66,6 @@ def serialize_media_attachment(attachment)
)
end

def serialize_status_card(status)
ActiveModelSerializers::SerializableResource.new(
status.preview_card,
serializer: REST::PreviewCardSerializer
)
end

def serialize_status_poll(status)
ActiveModelSerializers::SerializableResource.new(
status.preloadable_poll,
serializer: REST::PollSerializer,
scope: current_user,
scope_name: :current_user
)
end

def sensitive_viewer?(status, account)
if !account.nil? && account.id == status.account_id
status.sensitive
Expand Down
29 changes: 12 additions & 17 deletions app/helpers/statuses_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ module StatusesHelper
EMBEDDED_CONTROLLER = 'statuses'
EMBEDDED_ACTION = 'embed'

VISIBLITY_ICONS = {
public: 'globe',
unlisted: 'lock_open',
private: 'lock',
direct: 'alternate_email',
public_unlisted: 'cloud',
login: 'key',
limited: 'shield',
}.freeze

def nothing_here(extra_classes = '')
content_tag(:div, class: "nothing-here #{extra_classes}") do
t('accounts.nothing_here')
Expand Down Expand Up @@ -57,23 +67,8 @@ def stream_link_target
embedded_view? ? '_blank' : nil
end

def fa_visibility_icon(status)
case status.visibility
when 'public'
material_symbol 'globe'
when 'unlisted'
material_symbol 'lock_open'
when 'public_unlisted'
material_symbol 'cloud'
when 'login'
material_symbol 'key'
when 'private'
material_symbol 'lock'
when 'limited'
material_symbol 'shield'
when 'direct'
material_symbol 'alternate_email'
end
def visibility_icon(status)
VISIBLITY_ICONS[status.visibility.to_sym]
end

def embedded_view?
Expand Down
74 changes: 74 additions & 0 deletions app/javascript/entrypoints/embed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import './public-path';
import { createRoot } from 'react-dom/client';

import { afterInitialRender } from 'mastodon/../hooks/useRenderSignal';

import { start } from '../mastodon/common';
import { Status } from '../mastodon/features/standalone/status';
import { loadPolyfills } from '../mastodon/polyfills';
import ready from '../mastodon/ready';

start();

function loaded() {
const mountNode = document.getElementById('mastodon-status');

if (mountNode) {
const attr = mountNode.getAttribute('data-props');

if (!attr) return;

const props = JSON.parse(attr) as { id: string; locale: string };
const root = createRoot(mountNode);

root.render(<Status {...props} />);
}
}

function main() {
ready(loaded).catch((error: unknown) => {
console.error(error);
});
}

loadPolyfills()
.then(main)
.catch((error: unknown) => {
console.error(error);
});

interface SetHeightMessage {
type: 'setHeight';
id: string;
height: number;
}

function isSetHeightMessage(data: unknown): data is SetHeightMessage {
if (
data &&
typeof data === 'object' &&
'type' in data &&
data.type === 'setHeight'
)
return true;
else return false;
}

window.addEventListener('message', (e) => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- typings are not correct, it can be null in very rare cases
if (!e.data || !isSetHeightMessage(e.data) || !window.parent) return;

const data = e.data;

// We use a timeout to allow for the React page to render before calculating the height
afterInitialRender(() => {
window.parent.postMessage(
{
type: 'setHeight',
id: data.id,
height: document.getElementsByTagName('html')[0]?.scrollHeight,
},
'*',
);
});
});
Loading

0 comments on commit fe051aa

Please sign in to comment.