Skip to content

Commit

Permalink
Merge branch 'main' into verup-to-4.2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
claustra01 committed Jun 24, 2024
2 parents c93aaca + bc3c942 commit e6f8541
Show file tree
Hide file tree
Showing 38 changed files with 1,594 additions and 17 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=
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
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);
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 @@ -7,7 +7,7 @@ import { Link } from 'react-router-dom';

import { WordmarkLogo } from 'mastodon/components/logo';
import NavigationPortal from 'mastodon/components/navigation_portal';
import { timelinePreview, trendsEnabled } from 'mastodon/initial_state';
import { timelinePreview, trendsEnabled, c3_official_site_url, c3_toybox_url } from 'mastodon/initial_state';
import { transientSingleColumn } from 'mastodon/is_mobile';

import ColumnLink from './column_link';
Expand All @@ -32,6 +32,9 @@ const messages = defineMessages({
search: { id: 'navigation_bar.search', defaultMessage: 'Search' },
advancedInterface: { id: 'navigation_bar.advanced_interface', defaultMessage: 'Open in advanced web interface' },
openedInClassicInterface: { id: 'navigation_bar.opened_in_classic_interface', defaultMessage: 'Posts, accounts, and other specific pages are opened by default in the classic web interface.' },

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

class NavigationPanel extends Component {
Expand Down Expand Up @@ -113,6 +116,16 @@ class NavigationPanel extends Component {

<hr />

{
(c3_official_site_url || c3_toybox_url) && (
<>
{ c3_official_site_url && <ColumnLink transparent as='a' href={c3_official_site_url} target='_blank' icon='laptop' text={intl.formatMessage(messages.officialSite)} /> }
{ c3_toybox_url && <ColumnLink transparent as='a' href={c3_toybox_url} target='_blank' icon='archive' text={intl.formatMessage(messages.toybox)} /> }
<hr />
</>
)
}

<ColumnLink transparent href='/settings/preferences' icon='cog' text={intl.formatMessage(messages.preferences)} />
</>
)}
Expand Down
6 changes: 6 additions & 0 deletions app/javascript/mastodon/initial_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
* @property {boolean=} use_pending_items
* @property {string} version
* @property {string} sso_redirect
* @property {string | null} c3_official_site_url
* @property {string | null} c3_toybox_url
*/

/**
Expand Down Expand Up @@ -140,6 +142,10 @@ export const unfollowModal = getMeta('unfollow_modal');
export const useBlurhash = getMeta('use_blurhash');
export const usePendingItems = getMeta('use_pending_items');
export const version = getMeta('version');

export const c3_official_site_url = getMeta('c3_official_site_url');
export const c3_toybox_url = getMeta('c3_toybox_url');

export const languages = initialState?.languages;
export const criticalUpdatesPending = initialState?.critical_updates_pending;
// @ts-expect-error
Expand Down
3 changes: 3 additions & 0 deletions app/javascript/mastodon/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@
"error.unexpected_crash.next_steps_addons": "Try disabling them and refreshing the page. If that does not help, you may still be able to use Mastodon through a different browser or native app.",
"errors.unexpected_crash.copy_stacktrace": "Copy stacktrace to clipboard",
"errors.unexpected_crash.report_issue": "Report issue",
"external_url.official_site": "C3 Official Site",
"external_url.toybox": "ToyBox",
"explore.search_results": "Search results",
"explore.suggested_follows": "People",
"explore.title": "Explore",
Expand Down Expand Up @@ -399,6 +401,7 @@
"navigation_bar.advanced_interface": "Open in advanced web interface",
"navigation_bar.blocks": "Blocked users",
"navigation_bar.bookmarks": "Bookmarks",
"navigation_bar.c3": "c3",
"navigation_bar.community_timeline": "Local timeline",
"navigation_bar.compose": "Compose new post",
"navigation_bar.direct": "Private mentions",
Expand Down
6 changes: 5 additions & 1 deletion app/javascript/mastodon/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@
"error.unexpected_crash.next_steps_addons": "それらを無効化してからリロードをお試しください。それでも解決しない場合、他のブラウザやアプリで Mastodon をお試しください。",
"errors.unexpected_crash.copy_stacktrace": "スタックトレースをクリップボードにコピー",
"errors.unexpected_crash.report_issue": "問題を報告",
"external_url.official_site": "C3 公式サイト",
"external_url.toybox": "ToyBox",
"explore.search_results": "検索結果",
"explore.suggested_follows": "ユーザー",
"explore.title": "エクスプローラー",
Expand Down Expand Up @@ -399,6 +401,7 @@
"navigation_bar.advanced_interface": "上級者向けUIに戻る",
"navigation_bar.blocks": "ブロックしたユーザー",
"navigation_bar.bookmarks": "ブックマーク",
"navigation_bar.c3": "c3",
"navigation_bar.community_timeline": "ローカルタイムライン",
"navigation_bar.compose": "投稿の新規作成",
"navigation_bar.direct": "非公開の返信",
Expand Down Expand Up @@ -725,5 +728,6 @@
"video.mute": "ミュート",
"video.pause": "一時停止",
"video.play": "再生",
"video.unmute": "ミュートを解除する"
"video.unmute": "ミュートを解除する",
"custom.caution_message": "このMastodonに公開、未収載でトゥートされた内容はすべてインターネット上の誰でも閲覧することができます。\n個人情報、著作権等のネットリテラシーには十分注意してトゥートしましょう。"
}
Loading

0 comments on commit e6f8541

Please sign in to comment.