Skip to content

Commit

Permalink
update: コンフリクトしたカスタマイズ要素の復活
Browse files Browse the repository at this point in the history
  • Loading branch information
t3mp-0xCC committed Oct 21, 2023
1 parent 2c9cb90 commit 0eef6f2
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 16 deletions.
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

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';

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
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

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 @@ -107,6 +110,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
15 changes: 15 additions & 0 deletions app/javascript/styles/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,18 @@
@import 'mastodon/rtl';
@import 'mastodon/accessibility';
@import 'mastodon/rich_text';


// 非上級者向けUIのマスコット配置
.drawer__inner__mastodon.navigation_icon {
background: none;
}
// 絵文字単体を大きく
.emojione.custom-emoji.big_icon {
width: 40px;
height: 40px;
}
.detailed-status .emojione.custom-emoji.big_icon {
width: 50px;
height: 50px;
}
6 changes: 6 additions & 0 deletions config/routes/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,10 @@
resources :sessions, only: [:destroy]
resources :featured_tags, only: [:index, :create, :destroy]
resources :login_activities, only: [:index]

resources :request_custom_emojis, only: [:index, :new, :create] do
collection do
post :batch
end
end
end

0 comments on commit 0eef6f2

Please sign in to comment.