Skip to content

Commit

Permalink
Merge pull request #2843 from ClearlyClaire/glitch-soc/merge-upstream
Browse files Browse the repository at this point in the history
Merge upstream changes up to 0226bbe
  • Loading branch information
ClearlyClaire authored Sep 13, 2024
2 parents cb91629 + 427ed60 commit 065abf2
Show file tree
Hide file tree
Showing 359 changed files with 3,333 additions and 3,662 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ module.exports = defineConfig({
],

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

Expand Down
16 changes: 8 additions & 8 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 @@ -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
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 hide_followers_count?(account)
Setting.hide_followers_count || account.user&.settings&.[]('hide_followers_count')
end
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
20 changes: 9 additions & 11 deletions app/helpers/statuses_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ module StatusesHelper
EMBEDDED_CONTROLLER = 'statuses'
EMBEDDED_ACTION = 'embed'

VISIBLITY_ICONS = {
public: 'globe',
unlisted: 'lock_open',
private: 'lock',
direct: 'alternate_email',
}.freeze

def nothing_here(extra_classes = '')
content_tag(:div, class: "nothing-here #{extra_classes}") do
t('accounts.nothing_here')
Expand Down Expand Up @@ -57,17 +64,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 'private'
material_symbol 'lock'
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,
},
'*',
);
});
});
37 changes: 0 additions & 37 deletions app/javascript/entrypoints/public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,43 +37,6 @@ const messages = defineMessages({
},
});

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;

ready(() => {
window.parent.postMessage(
{
type: 'setHeight',
id: data.id,
height: document.getElementsByTagName('html')[0]?.scrollHeight,
},
'*',
);
}).catch((e: unknown) => {
console.error('Error in setHeightMessage postMessage', e);
});
});

function loaded() {
const { messages: localeData } = getLocale();

Expand Down
2 changes: 1 addition & 1 deletion app/javascript/flavours/glitch/actions/markers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const synchronouslySubmitMarkers = createAppAsyncThunk(
client.setRequestHeader('Content-Type', 'application/json');
client.setRequestHeader('Authorization', `Bearer ${accessToken}`);
client.send(JSON.stringify(params));
} catch (e) {
} catch {
// Do not make the BeforeUnload handler error out
}
},
Expand Down
6 changes: 4 additions & 2 deletions app/javascript/flavours/glitch/actions/statuses.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ export function fetchStatusRequest(id, skipLoading) {
};
}

export function fetchStatus(id, forceFetch = false) {
export function fetchStatus(id, forceFetch = false, alsoFetchContext = true) {
return (dispatch, getState) => {
const skipLoading = !forceFetch && getState().getIn(['statuses', id], null) !== null;

dispatch(fetchContext(id));
if (alsoFetchContext) {
dispatch(fetchContext(id));
}

if (skipLoading) {
return;
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/flavours/glitch/actions/streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async function refreshHomeTimelineAndNotification(dispatch, getState) {
// TODO: polling for merged notifications
try {
await dispatch(pollRecentGroupNotifications());
} catch (error) {
} catch {
// TODO
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/flavours/glitch/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function start() {

try {
Rails.start();
} catch (e) {
} catch {
// If called twice
}
}
Loading

0 comments on commit 065abf2

Please sign in to comment.