Skip to content

Commit

Permalink
Merge branch 'main' into version-up-to-v4.2.13
Browse files Browse the repository at this point in the history
  • Loading branch information
claustra01 authored Oct 1, 2024
2 parents 7e47439 + bd79681 commit 6929897
Show file tree
Hide file tree
Showing 77 changed files with 1,653 additions and 199 deletions.
5 changes: 5 additions & 0 deletions .env.production.sample
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,8 @@ S3_ALIAS_HOST=files.example.com
# -----------------------
IP_RETENTION_PERIOD=31556952
SESSION_RETENTION_PERIOD=31556952

# C3 link
# -------
C3_OFFICIAL_SITE_URL=
C3_TOYBOX_URL=
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ GEM
redlock (~> 1.0)
strong_migrations (0.8.0)
activerecord (>= 5.2)
strscan (3.0.9)
swd (1.3.0)
activesupport (>= 3)
attr_required (>= 0.0.5)
Expand Down
71 changes: 71 additions & 0 deletions app/controllers/settings/request_custom_emojis_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# frozen_string_literal: true

class Settings::RequestCustomEmojisController < Settings::BaseController
include Authorization

def index
@is_admin = authorize?
@custom_emojis = RequestCustomEmoji.order(:state, :shortcode).page(params[:page])
@form = Form::RequestCustomEmojiBatch.new
end

def new
@custom_emoji = RequestCustomEmoji.new
end

def create
@custom_emoji = RequestCustomEmoji.new(resource_params)
@custom_emoji.account_id = current_account.id
if CustomEmoji.find_by(shortcode: @custom_emoji.shortcode, domain: nil)
@custom_emoji.errors.add(:shortcode, I18n.t('settings.request_custom_emoji.errors.already_exists'))
render :new
return
end

if @custom_emoji.save
redirect_to settings_request_custom_emojis_path, notice: I18n.t('settings.request_custom_emoji.created_msg')
else
render :new
end
end

def batch
@form = Form::RequestCustomEmojiBatch.new(form_custom_emoji_batch_params.merge(current_account: current_account, action: action_from_button))
@form.save
rescue ActionController::ParameterMissing
flash[:alert] = I18n.t('admin.accounts.no_account_selected')
rescue Mastodon::NotPermittedError
flash[:alert] = I18n.t('admin.custom_emojis.not_permitted')
ensure
redirect_to settings_request_custom_emojis_path
end

private

def resource_params
params.require(:request_custom_emoji).permit(:shortcode, :image)
end

def form_custom_emoji_batch_params
params.require(:form_request_custom_emoji_batch).permit(:action, request_custom_emoji_ids: [])

Check failure on line 50 in app/controllers/settings/request_custom_emojis_controller.rb

View workflow job for this annotation

GitHub Actions / lint

[Correctable] Layout/IndentationWidth: Use 2 (not 0) spaces for indentation. (https://rubystyle.guide#spaces-indentation)

Check failure on line 50 in app/controllers/settings/request_custom_emojis_controller.rb

View workflow job for this annotation

GitHub Actions / lint

[Correctable] Layout/IndentationWidth: Use 2 (not 0) spaces for indentation. (https://rubystyle.guide#spaces-indentation)
end

def action_from_button
if params[:approve]
'approve'
elsif params[:reject]
'reject'
elsif params[:delete]
'delete'
end
end

def authorize?
begin
authorize(:custom_emoji, :index?)
rescue Mastodon::NotPermittedError
return false
end
return true

Check failure on line 69 in app/controllers/settings/request_custom_emojis_controller.rb

View workflow job for this annotation

GitHub Actions / lint

[Correctable] Style/RedundantReturn: Redundant return detected. (https://rubystyle.guide#no-explicit-return)

Check failure on line 69 in app/controllers/settings/request_custom_emojis_controller.rb

View workflow job for this annotation

GitHub Actions / lint

[Correctable] Style/RedundantReturn: Redundant return detected. (https://rubystyle.guide#no-explicit-return)
end
end
15 changes: 14 additions & 1 deletion app/javascript/mastodon/actions/importer/normalizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ const makeEmojiMap = emojis => emojis.reduce((obj, emoji) => {
return obj;
}, {});

const rewrite = txt => {
let edit_txt = txt.replaceAll('</p><p>', ' ').replaceAll('<br />', ' ')
const e = document.createElement('div');
e.innerHTML = edit_txt;
return e.innerText;
}

const checkOnlyIconStatus = content => {
const trimContent = rewrite(content).trim();
return trimContent.match("^:[0-9a-zA-Z_]+:([  \r\t\s\n]+:[0-9a-zA-Z_]+:)*$");

Check failure on line 23 in app/javascript/mastodon/actions/importer/normalizer.js

View workflow job for this annotation

GitHub Actions / lint

Unnecessary escape character: \s
};

export function searchTextFromRawStatus (status) {
const spoilerText = status.spoiler_text || '';
const searchContent = ([spoilerText, status.content].concat((status.poll && status.poll.options) ? status.poll.options.map(option => option.title) : [])).concat(status.media_attachments.map(att => att.description)).join('\n\n').replace(/<br\s*\/?>/g, '\n').replace(/<\/p><p>/g, '\n\n');
Expand Down Expand Up @@ -91,9 +103,10 @@ export function normalizeStatus(status, normalOldStatus) {
const spoilerText = normalStatus.spoiler_text || '';
const searchContent = ([spoilerText, status.content].concat((status.poll && status.poll.options) ? status.poll.options.map(option => option.title) : [])).concat(status.media_attachments.map(att => att.description)).join('\n\n').replace(/<br\s*\/?>/g, '\n').replace(/<\/p><p>/g, '\n\n');
const emojiMap = makeEmojiMap(normalStatus.emojis);
const toBigIcon = checkOnlyIconStatus(normalStatus.content);

normalStatus.search_index = domParser.parseFromString(searchContent, 'text/html').documentElement.textContent;
normalStatus.contentHtml = emojify(normalStatus.content, emojiMap);
normalStatus.contentHtml = emojify(normalStatus.content, emojiMap, toBigIcon);
normalStatus.spoilerHtml = emojify(escapeTextContentForBrowser(spoilerText), emojiMap);
normalStatus.hidden = expandSpoilers ? false : spoilerText.length > 0 || normalStatus.sensitive;
}
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/mastodon/actions/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function changeSetting(path, value) {
}

const debouncedSave = debounce((dispatch, getState) => {
if (getState().getIn(['settings', 'saved']) || !getState().getIn(['meta', 'me'])) {
if (getState().getIn(['settings', 'saved'])) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class ReportReasonSelector extends PureComponent {

api().put(`/api/v1/admin/reports/${id}`, {
category,
rule_ids: category === 'violation' ? rule_ids : [],
rule_ids,
}).catch(err => {
console.error(err);
});
Expand Down
1 change: 0 additions & 1 deletion app/javascript/mastodon/components/dropdown_menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class DropdownMenu extends PureComponent {
if (this.node && !this.node.contains(e.target)) {
this.props.onClose();
e.stopPropagation();
e.preventDefault();
}
};

Expand Down
20 changes: 13 additions & 7 deletions app/javascript/mastodon/components/navigation_portal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ import { Switch, Route, withRouter } from 'react-router-dom';

import AccountNavigation from 'mastodon/features/account/navigation';
import Trends from 'mastodon/features/getting_started/containers/trends_container';
import { showTrends } from 'mastodon/initial_state';
import { showTrends, mascot } from 'mastodon/initial_state';

import elephantUIPlane from 'images/elephant_ui_plane.svg';

Check failure on line 9 in app/javascript/mastodon/components/navigation_portal.jsx

View workflow job for this annotation

GitHub Actions / lint

`images/elephant_ui_plane.svg` import should occur before import of `mastodon/features/account/navigation`

Check failure on line 9 in app/javascript/mastodon/components/navigation_portal.jsx

View workflow job for this annotation

GitHub Actions / lint

Unable to resolve path to module 'images/elephant_ui_plane.svg'

const DefaultNavigation = () => (
showTrends ? (
<>
<div className='flex-spacer' />
<Trends />
</>
) : null
<>
<div className='drawer__inner__mastodon navigation_icon'>
<img alt='' draggable='false' src={mascot || elephantUIPlane} />
</div>
{
showTrends ? (
<Trends />
) : null
}
</>
);

class NavigationPortal extends PureComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import { countableText } from '../util/counter';

import CharacterCounter from './character_counter';

Check failure on line 29 in app/javascript/mastodon/features/compose/components/compose_form.jsx

View workflow job for this annotation

GitHub Actions / lint

There should be no empty line within import group

import LiteracyCautionComponent from './literacy_caution'

const allowedAroundShortCode = '><\u0085\u0020\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029\u0009\u000a\u000b\u000c\u000d';

const messages = defineMessages({
Expand Down Expand Up @@ -312,6 +314,7 @@ class ComposeForm extends ImmutablePureComponent {
/>
</div>
</div>
<LiteracyCautionComponent intl={intl}/>

Check failure on line 317 in app/javascript/mastodon/features/compose/components/compose_form.jsx

View workflow job for this annotation

GitHub Actions / lint

A space is required before closing bracket
</form>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import PropTypes from 'prop-types';

Check failure on line 2 in app/javascript/mastodon/features/compose/components/literacy_caution.jsx

View workflow job for this annotation

GitHub Actions / lint

There should be at least one empty line between import groups

Check failure on line 2 in app/javascript/mastodon/features/compose/components/literacy_caution.jsx

View workflow job for this annotation

GitHub Actions / lint

`prop-types` import should occur before import of `react`
import ImmutablePureComponent from 'react-immutable-pure-component';

Check failure on line 3 in app/javascript/mastodon/features/compose/components/literacy_caution.jsx

View workflow job for this annotation

GitHub Actions / lint

There should be at least one empty line between import groups
import { defineMessages, injectIntl } from 'react-intl';

Check failure on line 4 in app/javascript/mastodon/features/compose/components/literacy_caution.jsx

View workflow job for this annotation

GitHub Actions / lint

`react-intl` import should occur before import of `react-immutable-pure-component`

const messages = defineMessages({
cautionMessage: { id: 'custom.caution_message', defaultMessage: 'CAUTION' },
});

class LiteracyCaution extends ImmutablePureComponent {
static propTypes = {
intl: PropTypes.object.isRequired,
}

render() {
const { intl } = this.props;
return (
<div className="literacy-caution">

Check failure on line 18 in app/javascript/mastodon/features/compose/components/literacy_caution.jsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected usage of doublequote
<a href="https://onlineguide.isc.kyutech.ac.jp/guide2020/index.php/home/2020-02-04-02-50-29/2020-03-03-01-40-44">
<p>
{ intl.formatMessage(messages.cautionMessage) }
</p>
</a>
</div>
)
}
}

export default injectIntl(LiteracyCaution);
11 changes: 3 additions & 8 deletions app/javascript/mastodon/features/compose/components/search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ class Search extends PureComponent {
}

_calculateOptions (value) {
const { signedIn } = this.context.identity;
const trimmedValue = value.trim();
const options = [];

Expand All @@ -299,7 +298,7 @@ class Search extends PureComponent {

const couldBeStatusSearch = searchEnabled;

if (couldBeStatusSearch && signedIn) {
if (couldBeStatusSearch) {
options.push({ key: 'status-search', label: <FormattedMessage id='search.quick_action.status_search' defaultMessage='Posts matching {x}' values={{ x: <mark>{trimmedValue}</mark> }} />, action: this.handleStatusSearch });
}

Expand Down Expand Up @@ -376,7 +375,7 @@ class Search extends PureComponent {

<h4><FormattedMessage id='search_popout.options' defaultMessage='Search options' /></h4>

{searchEnabled && signedIn ? (
{searchEnabled ? (
<div className='search__popout__menu'>
{this.defaultOptions.map(({ key, label, action }, i) => (
<button key={key} onMouseDown={action} className={classNames('search__popout__menu__item', { selected: selectedOption === ((options.length || recent.size) + i) })}>
Expand All @@ -386,11 +385,7 @@ class Search extends PureComponent {
</div>
) : (
<div className='search__popout__menu__message'>
{searchEnabled ? (
<FormattedMessage id='search_popout.full_text_search_logged_out_message' defaultMessage='Only available when logged in.' />
) : (
<FormattedMessage id='search_popout.full_text_search_disabled_message' defaultMessage='Not available on {domain}.' values={{ domain }} />
)}
<FormattedMessage id='search_popout.full_text_search_disabled_message' defaultMessage='Not available on {domain}.' values={{ domain }} />
</div>
)}
</div>
Expand Down
15 changes: 8 additions & 7 deletions app/javascript/mastodon/features/emoji/emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const emojiFilename = (filename) => {
return borderedEmoji.includes(filename) ? (filename + '_border') : filename;
};

const emojifyTextNode = (node, customEmojis) => {
const emojifyTextNode = (node, customEmojis, bigIcon) => {
const VS15 = 0xFE0E;
const VS16 = 0xFE0F;

Expand Down Expand Up @@ -72,9 +72,10 @@ const emojifyTextNode = (node, customEmojis) => {
// now got a replacee as ':shortcode:'
// if you want additional emoji handler, add statements below which set replacement and return true.
const filename = autoPlayGif ? custom_emoji.url : custom_emoji.static_url;
const bigIconClass = bigIcon ? " big_icon" : "" ;
replacement = document.createElement('img');
replacement.setAttribute('draggable', 'false');
replacement.setAttribute('class', 'emojione custom-emoji');
replacement.setAttribute('class', `emojione custom-emoji${bigIconClass}`);
replacement.setAttribute('alt', shortcode);
replacement.setAttribute('title', shortcode);
replacement.setAttribute('src', filename);
Expand Down Expand Up @@ -111,28 +112,28 @@ const emojifyTextNode = (node, customEmojis) => {
node.parentElement.replaceChild(fragment, node);
};

const emojifyNode = (node, customEmojis) => {
const emojifyNode = (node, customEmojis, bigIcon) => {
for (const child of node.childNodes) {
switch(child.nodeType) {
case Node.TEXT_NODE:
emojifyTextNode(child, customEmojis);
emojifyTextNode(child, customEmojis, bigIcon);
break;
case Node.ELEMENT_NODE:
if (!child.classList.contains('invisible'))
emojifyNode(child, customEmojis);
emojifyNode(child, customEmojis, bigIcon);
break;
}
}
};

const emojify = (str, customEmojis = {}) => {
const emojify = (str, customEmojis = {}, bigIcon = null) => {
const wrapper = document.createElement('div');
wrapper.innerHTML = str;

if (!Object.keys(customEmojis).length)
customEmojis = null;

emojifyNode(wrapper, customEmojis);
emojifyNode(wrapper, customEmojis, bigIcon);

return wrapper.innerHTML;
};
Expand Down
22 changes: 22 additions & 0 deletions app/javascript/mastodon/features/getting_started/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import ColumnSubheading from '../ui/components/column_subheading';

import TrendsContainer from './containers/trends_container';

import { c3_official_site_url, c3_toybox_url } from 'mastodon/initial_state';

Check warning on line 24 in app/javascript/mastodon/features/getting_started/index.jsx

View workflow job for this annotation

GitHub Actions / lint

'/home/runner/work/mastodon/mastodon/app/javascript/mastodon/initial_state.js' imported multiple times

const messages = defineMessages({
home_timeline: { id: 'tabs_bar.home', defaultMessage: 'Home' },
notifications: { id: 'tabs_bar.notifications', defaultMessage: 'Notifications' },
Expand All @@ -42,6 +44,10 @@ const messages = defineMessages({
personal: { id: 'navigation_bar.personal', defaultMessage: 'Personal' },
security: { id: 'navigation_bar.security', defaultMessage: 'Security' },
menu: { id: 'getting_started.heading', defaultMessage: 'Getting started' },

officialSite: {id: 'external_url.official_site', defaultMessage: 'C3 Official Site'},
toybox: {id: 'external_url.toybox', defaultMessage: 'ToyBox'},
c3: { id: 'navigation_bar.c3', defaultMessage: 'C3' },
});

const mapStateToProps = state => ({
Expand Down Expand Up @@ -125,6 +131,22 @@ class GettingStarted extends ImmutablePureComponent {
navItems.push(<ColumnLink key='follow_requests' icon='user-plus' text={intl.formatMessage(messages.follow_requests)} badge={badgeDisplay(unreadFollowRequests, 40)} to='/follow_requests' />);
}

if (c3_official_site_url || c3_toybox_url) {
navItems.push(
<ColumnSubheading key='header-c3' text={intl.formatMessage(messages.c3)} />,
)
if(c3_official_site_url) {
navItems.push(
<ColumnLink key='official-site' icon='laptop' text={intl.formatMessage(messages.officialSite)} as='a' href={c3_official_site_url} target='_blank' />,
)
}
if(c3_toybox_url) {
navItems.push(
<ColumnLink key='toybox' icon='archive' text={intl.formatMessage(messages.toybox)} as='a' href={c3_toybox_url} target='_blank' />
)
}
}

navItems.push(
<ColumnSubheading key='header-settings' text={intl.formatMessage(messages.settings_subheading)} />,
<ColumnLink key='preferences' icon='gears' text={intl.formatMessage(messages.preferences)} href='/settings/preferences' />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class FocalPointModal extends ImmutablePureComponent {
const worker = createWorker({
workerPath: tesseractWorkerPath,
corePath: tesseractCorePath,
langPath: `${assetHost}/ocr/lang-data`,
langPath: `${assetHost}/ocr/lang-data/`,
logger: ({ status, progress }) => {
if (status === 'recognizing text') {
this.setState({ ocrStatus: 'detecting', progress });
Expand Down
Loading

0 comments on commit 6929897

Please sign in to comment.