Merge pull request #735 from Steffo99/feature/paste-attach

Allow pasting attachments on Akkoma / Pleroma instances
This commit is contained in:
Chee Aun 2024-10-14 15:45:41 +08:00 committed by GitHub
commit 29822cbf2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 127 additions and 107 deletions

View file

@ -197,6 +197,7 @@ function highlightText(text, { maxCharacters = Infinity }) {
// const rtf = new Intl.RelativeTimeFormat(); // const rtf = new Intl.RelativeTimeFormat();
const RTF = mem((locale) => new Intl.RelativeTimeFormat(locale || undefined)); const RTF = mem((locale) => new Intl.RelativeTimeFormat(locale || undefined));
const LF = mem((locale) => new Intl.ListFormat(locale || undefined));
const CUSTOM_EMOJIS_COUNT = 100; const CUSTOM_EMOJIS_COUNT = 100;
@ -210,6 +211,7 @@ function Compose({
}) { }) {
const { i18n } = useLingui(); const { i18n } = useLingui();
const rtf = RTF(i18n.locale); const rtf = RTF(i18n.locale);
const lf = LF(i18n.locale);
console.warn('RENDER COMPOSER'); console.warn('RENDER COMPOSER');
const { masto, instance } = api(); const { masto, instance } = api();
@ -226,11 +228,11 @@ function Compose({
const { const {
statuses: { statuses: {
maxCharacters, maxCharacters,
maxMediaAttachments, maxMediaAttachments, // Beware: it can be undefined!
charactersReservedPerUrl, charactersReservedPerUrl,
} = {}, } = {},
mediaAttachments: { mediaAttachments: {
supportedMimeTypes = [], supportedMimeTypes,
imageSizeLimit, imageSizeLimit,
imageMatrixLimit, imageMatrixLimit,
videoSizeLimit, videoSizeLimit,
@ -600,15 +602,26 @@ function Compose({
const handleItems = (e) => { const handleItems = (e) => {
const { items } = e.clipboardData || e.dataTransfer; const { items } = e.clipboardData || e.dataTransfer;
const files = []; const files = [];
const unsupportedFiles = [];
for (let i = 0; i < items.length; i++) { for (let i = 0; i < items.length; i++) {
const item = items[i]; const item = items[i];
if (item.kind === 'file') { if (item.kind === 'file') {
const file = item.getAsFile(); const file = item.getAsFile();
if (file && supportedMimeTypes.includes(file.type)) { if (supportedMimeTypes !== undefined && !supportedMimeTypes.includes(file.type)) {
unsupportedFiles.push(file);
} else {
files.push(file); files.push(file);
} }
} }
} }
if (unsupportedFiles.length > 0) {
alert(
plural(unsupportedFiles.length, {
one: `File ${unsupportedFiles[0].name} is not supported.`,
other: `Files ${lf.format(unsupportedFiles.map(f => f.name))} are not supported.`,
}),
);
}
if (files.length > 0 && mediaAttachments.length >= maxMediaAttachments) { if (files.length > 0 && mediaAttachments.length >= maxMediaAttachments) {
alert( alert(
plural(maxMediaAttachments, { plural(maxMediaAttachments, {
@ -623,16 +636,19 @@ function Compose({
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
// Auto-cut-off files to avoid exceeding maxMediaAttachments // Auto-cut-off files to avoid exceeding maxMediaAttachments
const max = maxMediaAttachments - mediaAttachments.length; let allowedFiles = files;
const allowedFiles = files.slice(0, max); if(maxMediaAttachments !== undefined) {
if (allowedFiles.length <= 0) { const max = maxMediaAttachments - mediaAttachments.length;
alert( allowedFiles = allowedFiles.slice(0, max);
plural(maxMediaAttachments, { if(allowedFiles.length <= 0) {
one: 'You can only attach up to 1 file.', alert(
other: 'You can only attach up to # files.', plural(maxMediaAttachments, {
}), one: 'You can only attach up to 1 file.',
); other: 'You can only attach up to # files.',
return; }),
);
return;
}
} }
const mediaFiles = allowedFiles.map((file) => ({ const mediaFiles = allowedFiles.map((file) => ({
file, file,
@ -1307,8 +1323,8 @@ function Compose({
<label class="toolbar-button"> <label class="toolbar-button">
<input <input
type="file" type="file"
accept={supportedMimeTypes.join(',')} accept={supportedMimeTypes?.join(',')}
multiple={mediaAttachments.length < maxMediaAttachments - 1} multiple={(maxMediaAttachments === undefined) || (maxMediaAttachments - mediaAttachments >= 2)}
disabled={ disabled={
uiState === 'loading' || uiState === 'loading' ||
mediaAttachments.length >= maxMediaAttachments || mediaAttachments.length >= maxMediaAttachments ||
@ -1400,7 +1416,7 @@ function Compose({
class="toolbar-button gif-picker-button" class="toolbar-button gif-picker-button"
disabled={ disabled={
uiState === 'loading' || uiState === 'loading' ||
mediaAttachments.length >= maxMediaAttachments || (maxMediaAttachments !== undefined && mediaAttachments.length >= maxMediaAttachments) ||
!!poll !!poll
} }
onClick={() => { onClick={() => {

184
src/locales/en.po generated
View file

@ -105,7 +105,7 @@ msgstr ""
#: src/components/account-info.jsx:427 #: src/components/account-info.jsx:427
#: src/components/account-info.jsx:1115 #: src/components/account-info.jsx:1115
#: src/components/compose.jsx:2463 #: src/components/compose.jsx:2479
#: src/components/media-alt-modal.jsx:45 #: src/components/media-alt-modal.jsx:45
#: src/components/media-modal.jsx:283 #: src/components/media-modal.jsx:283
#: src/components/status.jsx:1703 #: src/components/status.jsx:1703
@ -400,11 +400,11 @@ msgstr ""
#: src/components/account-info.jsx:1989 #: src/components/account-info.jsx:1989
#: src/components/account-info.jsx:2089 #: src/components/account-info.jsx:2089
#: src/components/account-sheet.jsx:37 #: src/components/account-sheet.jsx:37
#: src/components/compose.jsx:797 #: src/components/compose.jsx:813
#: src/components/compose.jsx:2419 #: src/components/compose.jsx:2435
#: src/components/compose.jsx:2892 #: src/components/compose.jsx:2908
#: src/components/compose.jsx:3100 #: src/components/compose.jsx:3116
#: src/components/compose.jsx:3330 #: src/components/compose.jsx:3346
#: src/components/drafts.jsx:58 #: src/components/drafts.jsx:58
#: src/components/embed-modal.jsx:12 #: src/components/embed-modal.jsx:12
#: src/components/generic-accounts.jsx:142 #: src/components/generic-accounts.jsx:142
@ -541,135 +541,139 @@ msgstr ""
msgid "Compose" msgid "Compose"
msgstr "" msgstr ""
#: src/components/compose.jsx:392 #: src/components/compose.jsx:394
msgid "You have unsaved changes. Discard this post?" msgid "You have unsaved changes. Discard this post?"
msgstr "" msgstr ""
#: src/components/compose.jsx:614 #: src/components/compose.jsx:619
#: src/components/compose.jsx:630 msgid "{0, plural, one {File {1} is not supported.} other {Files {2} are not supported.}}"
#: src/components/compose.jsx:1337 msgstr "{0, plural, one {File {1} is not supported.} other {Files {2} are not supported.}}"
#: src/components/compose.jsx:1598
#: src/components/compose.jsx:627
#: src/components/compose.jsx:645
#: src/components/compose.jsx:1353
#: src/components/compose.jsx:1614
msgid "{maxMediaAttachments, plural, one {You can only attach up to 1 file.} other {You can only attach up to # files.}}" msgid "{maxMediaAttachments, plural, one {You can only attach up to 1 file.} other {You can only attach up to # files.}}"
msgstr "" msgstr ""
#: src/components/compose.jsx:778 #: src/components/compose.jsx:794
msgid "Pop out" msgid "Pop out"
msgstr "" msgstr ""
#: src/components/compose.jsx:785 #: src/components/compose.jsx:801
msgid "Minimize" msgid "Minimize"
msgstr "" msgstr ""
#: src/components/compose.jsx:821 #: src/components/compose.jsx:837
msgid "Looks like you closed the parent window." msgid "Looks like you closed the parent window."
msgstr "" msgstr ""
#: src/components/compose.jsx:828 #: src/components/compose.jsx:844
msgid "Looks like you already have a compose field open in the parent window and currently publishing. Please wait for it to be done and try again later." msgid "Looks like you already have a compose field open in the parent window and currently publishing. Please wait for it to be done and try again later."
msgstr "" msgstr ""
#: src/components/compose.jsx:833 #: src/components/compose.jsx:849
msgid "Looks like you already have a compose field open in the parent window. Popping in this window will discard the changes you made in the parent window. Continue?" msgid "Looks like you already have a compose field open in the parent window. Popping in this window will discard the changes you made in the parent window. Continue?"
msgstr "" msgstr ""
#: src/components/compose.jsx:875 #: src/components/compose.jsx:891
msgid "Pop in" msgid "Pop in"
msgstr "" msgstr ""
#: src/components/compose.jsx:885 #: src/components/compose.jsx:901
msgid "Replying to @{0}s post (<0>{1}</0>)" msgid "Replying to @{0}s post (<0>{1}</0>)"
msgstr "" msgstr ""
#: src/components/compose.jsx:895 #: src/components/compose.jsx:911
msgid "Replying to @{0}s post" msgid "Replying to @{0}s post"
msgstr "" msgstr ""
#: src/components/compose.jsx:908 #: src/components/compose.jsx:924
msgid "Editing source post" msgid "Editing source post"
msgstr "" msgstr ""
#: src/components/compose.jsx:955 #: src/components/compose.jsx:971
msgid "Poll must have at least 2 options" msgid "Poll must have at least 2 options"
msgstr "" msgstr ""
#: src/components/compose.jsx:959 #: src/components/compose.jsx:975
msgid "Some poll choices are empty" msgid "Some poll choices are empty"
msgstr "" msgstr ""
#: src/components/compose.jsx:972 #: src/components/compose.jsx:988
msgid "Some media have no descriptions. Continue?" msgid "Some media have no descriptions. Continue?"
msgstr "" msgstr ""
#: src/components/compose.jsx:1024 #: src/components/compose.jsx:1040
msgid "Attachment #{i} failed" msgid "Attachment #{i} failed"
msgstr "" msgstr ""
#: src/components/compose.jsx:1118 #: src/components/compose.jsx:1134
#: src/components/status.jsx:2029 #: src/components/status.jsx:2029
#: src/components/timeline.jsx:984 #: src/components/timeline.jsx:984
msgid "Content warning" msgid "Content warning"
msgstr "" msgstr ""
#: src/components/compose.jsx:1134 #: src/components/compose.jsx:1150
msgid "Content warning or sensitive media" msgid "Content warning or sensitive media"
msgstr "" msgstr ""
#: src/components/compose.jsx:1170 #: src/components/compose.jsx:1186
#: src/components/status.jsx:93 #: src/components/status.jsx:93
#: src/pages/settings.jsx:304 #: src/pages/settings.jsx:304
msgid "Public" msgid "Public"
msgstr "" msgstr ""
#: src/components/compose.jsx:1175 #: src/components/compose.jsx:1191
#: src/components/nav-menu.jsx:386 #: src/components/nav-menu.jsx:386
#: src/components/shortcuts-settings.jsx:162 #: src/components/shortcuts-settings.jsx:162
#: src/components/status.jsx:94 #: src/components/status.jsx:94
msgid "Local" msgid "Local"
msgstr "" msgstr ""
#: src/components/compose.jsx:1179 #: src/components/compose.jsx:1195
#: src/components/status.jsx:95 #: src/components/status.jsx:95
#: src/pages/settings.jsx:307 #: src/pages/settings.jsx:307
msgid "Unlisted" msgid "Unlisted"
msgstr "" msgstr ""
#: src/components/compose.jsx:1182 #: src/components/compose.jsx:1198
#: src/components/status.jsx:96 #: src/components/status.jsx:96
#: src/pages/settings.jsx:310 #: src/pages/settings.jsx:310
msgid "Followers only" msgid "Followers only"
msgstr "" msgstr ""
#: src/components/compose.jsx:1185 #: src/components/compose.jsx:1201
#: src/components/status.jsx:97 #: src/components/status.jsx:97
#: src/components/status.jsx:1907 #: src/components/status.jsx:1907
msgid "Private mention" msgid "Private mention"
msgstr "" msgstr ""
#: src/components/compose.jsx:1194 #: src/components/compose.jsx:1210
msgid "Post your reply" msgid "Post your reply"
msgstr "" msgstr ""
#: src/components/compose.jsx:1196 #: src/components/compose.jsx:1212
msgid "Edit your post" msgid "Edit your post"
msgstr "" msgstr ""
#: src/components/compose.jsx:1197 #: src/components/compose.jsx:1213
msgid "What are you doing?" msgid "What are you doing?"
msgstr "" msgstr ""
#: src/components/compose.jsx:1275 #: src/components/compose.jsx:1291
msgid "Mark media as sensitive" msgid "Mark media as sensitive"
msgstr "" msgstr ""
#: src/components/compose.jsx:1373 #: src/components/compose.jsx:1389
msgid "Add poll" msgid "Add poll"
msgstr "" msgstr ""
#: src/components/compose.jsx:1395 #: src/components/compose.jsx:1411
msgid "Add custom emoji" msgid "Add custom emoji"
msgstr "" msgstr ""
#: src/components/compose.jsx:1479 #: src/components/compose.jsx:1495
#: src/components/keyboard-shortcuts-help.jsx:143 #: src/components/keyboard-shortcuts-help.jsx:143
#: src/components/status.jsx:895 #: src/components/status.jsx:895
#: src/components/status.jsx:1683 #: src/components/status.jsx:1683
@ -678,195 +682,195 @@ msgstr ""
msgid "Reply" msgid "Reply"
msgstr "" msgstr ""
#: src/components/compose.jsx:1481 #: src/components/compose.jsx:1497
msgid "Update" msgid "Update"
msgstr "" msgstr ""
#: src/components/compose.jsx:1482 #: src/components/compose.jsx:1498
msgctxt "Submit button in composer" msgctxt "Submit button in composer"
msgid "Post" msgid "Post"
msgstr "" msgstr ""
#: src/components/compose.jsx:1610 #: src/components/compose.jsx:1626
msgid "Downloading GIF…" msgid "Downloading GIF…"
msgstr "" msgstr ""
#: src/components/compose.jsx:1638 #: src/components/compose.jsx:1654
msgid "Failed to download GIF" msgid "Failed to download GIF"
msgstr "" msgstr ""
#: src/components/compose.jsx:1750 #: src/components/compose.jsx:1766
#: src/components/compose.jsx:1827 #: src/components/compose.jsx:1843
#: src/components/nav-menu.jsx:287 #: src/components/nav-menu.jsx:287
msgid "More…" msgid "More…"
msgstr "" msgstr ""
#: src/components/compose.jsx:2232 #: src/components/compose.jsx:2248
msgid "Uploaded" msgid "Uploaded"
msgstr "" msgstr ""
#: src/components/compose.jsx:2245 #: src/components/compose.jsx:2261
msgid "Image description" msgid "Image description"
msgstr "" msgstr ""
#: src/components/compose.jsx:2246 #: src/components/compose.jsx:2262
msgid "Video description" msgid "Video description"
msgstr "" msgstr ""
#: src/components/compose.jsx:2247 #: src/components/compose.jsx:2263
msgid "Audio description" msgid "Audio description"
msgstr "" msgstr ""
#: src/components/compose.jsx:2283 #: src/components/compose.jsx:2299
#: src/components/compose.jsx:2303 #: src/components/compose.jsx:2319
msgid "File size too large. Uploading might encounter issues. Try reduce the file size from {0} to {1} or lower." msgid "File size too large. Uploading might encounter issues. Try reduce the file size from {0} to {1} or lower."
msgstr "" msgstr ""
#: src/components/compose.jsx:2295 #: src/components/compose.jsx:2311
#: src/components/compose.jsx:2315 #: src/components/compose.jsx:2331
msgid "Dimension too large. Uploading might encounter issues. Try reduce dimension from {0}×{1}px to {2}×{3}px." msgid "Dimension too large. Uploading might encounter issues. Try reduce dimension from {0}×{1}px to {2}×{3}px."
msgstr "" msgstr ""
#: src/components/compose.jsx:2323 #: src/components/compose.jsx:2339
msgid "Frame rate too high. Uploading might encounter issues." msgid "Frame rate too high. Uploading might encounter issues."
msgstr "" msgstr ""
#: src/components/compose.jsx:2383 #: src/components/compose.jsx:2399
#: src/components/compose.jsx:2633 #: src/components/compose.jsx:2649
#: src/components/shortcuts-settings.jsx:723 #: src/components/shortcuts-settings.jsx:723
#: src/pages/catchup.jsx:1074 #: src/pages/catchup.jsx:1074
#: src/pages/filters.jsx:412 #: src/pages/filters.jsx:412
msgid "Remove" msgid "Remove"
msgstr "" msgstr ""
#: src/components/compose.jsx:2400 #: src/components/compose.jsx:2416
#: src/compose.jsx:83 #: src/compose.jsx:83
msgid "Error" msgid "Error"
msgstr "" msgstr ""
#: src/components/compose.jsx:2425 #: src/components/compose.jsx:2441
msgid "Edit image description" msgid "Edit image description"
msgstr "" msgstr ""
#: src/components/compose.jsx:2426 #: src/components/compose.jsx:2442
msgid "Edit video description" msgid "Edit video description"
msgstr "" msgstr ""
#: src/components/compose.jsx:2427 #: src/components/compose.jsx:2443
msgid "Edit audio description" msgid "Edit audio description"
msgstr "" msgstr ""
#: src/components/compose.jsx:2472 #: src/components/compose.jsx:2488
#: src/components/compose.jsx:2521 #: src/components/compose.jsx:2537
msgid "Generating description. Please wait…" msgid "Generating description. Please wait…"
msgstr "" msgstr ""
#: src/components/compose.jsx:2492 #: src/components/compose.jsx:2508
msgid "Failed to generate description: {0}" msgid "Failed to generate description: {0}"
msgstr "" msgstr ""
#: src/components/compose.jsx:2493 #: src/components/compose.jsx:2509
msgid "Failed to generate description" msgid "Failed to generate description"
msgstr "" msgstr ""
#: src/components/compose.jsx:2505 #: src/components/compose.jsx:2521
#: src/components/compose.jsx:2511 #: src/components/compose.jsx:2527
#: src/components/compose.jsx:2557 #: src/components/compose.jsx:2573
msgid "Generate description…" msgid "Generate description…"
msgstr "" msgstr ""
#: src/components/compose.jsx:2544 #: src/components/compose.jsx:2560
msgid "Failed to generate description{0}" msgid "Failed to generate description{0}"
msgstr "" msgstr ""
#: src/components/compose.jsx:2559 #: src/components/compose.jsx:2575
msgid "({0}) <0>— experimental</0>" msgid "({0}) <0>— experimental</0>"
msgstr "" msgstr ""
#: src/components/compose.jsx:2578 #: src/components/compose.jsx:2594
msgid "Done" msgid "Done"
msgstr "" msgstr ""
#: src/components/compose.jsx:2614 #: src/components/compose.jsx:2630
msgid "Choice {0}" msgid "Choice {0}"
msgstr "" msgstr ""
#: src/components/compose.jsx:2661 #: src/components/compose.jsx:2677
msgid "Multiple choices" msgid "Multiple choices"
msgstr "" msgstr ""
#: src/components/compose.jsx:2664 #: src/components/compose.jsx:2680
msgid "Duration" msgid "Duration"
msgstr "" msgstr ""
#: src/components/compose.jsx:2695 #: src/components/compose.jsx:2711
msgid "Remove poll" msgid "Remove poll"
msgstr "" msgstr ""
#: src/components/compose.jsx:2909 #: src/components/compose.jsx:2925
msgid "Search accounts" msgid "Search accounts"
msgstr "" msgstr ""
#: src/components/compose.jsx:2950 #: src/components/compose.jsx:2966
#: src/components/shortcuts-settings.jsx:712 #: src/components/shortcuts-settings.jsx:712
#: src/pages/list.jsx:359 #: src/pages/list.jsx:359
msgid "Add" msgid "Add"
msgstr "" msgstr ""
#: src/components/compose.jsx:2963 #: src/components/compose.jsx:2979
#: src/components/generic-accounts.jsx:227 #: src/components/generic-accounts.jsx:227
msgid "Error loading accounts" msgid "Error loading accounts"
msgstr "" msgstr ""
#: src/components/compose.jsx:3106 #: src/components/compose.jsx:3122
msgid "Custom emojis" msgid "Custom emojis"
msgstr "" msgstr ""
#: src/components/compose.jsx:3126 #: src/components/compose.jsx:3142
msgid "Search emoji" msgid "Search emoji"
msgstr "" msgstr ""
#: src/components/compose.jsx:3157 #: src/components/compose.jsx:3173
msgid "Error loading custom emojis" msgid "Error loading custom emojis"
msgstr "" msgstr ""
#: src/components/compose.jsx:3168 #: src/components/compose.jsx:3184
msgid "Recently used" msgid "Recently used"
msgstr "" msgstr ""
#: src/components/compose.jsx:3169 #: src/components/compose.jsx:3185
msgid "Others" msgid "Others"
msgstr "" msgstr ""
#: src/components/compose.jsx:3207 #: src/components/compose.jsx:3223
msgid "{0} more…" msgid "{0} more…"
msgstr "" msgstr ""
#: src/components/compose.jsx:3345 #: src/components/compose.jsx:3361
msgid "Search GIFs" msgid "Search GIFs"
msgstr "" msgstr ""
#: src/components/compose.jsx:3360 #: src/components/compose.jsx:3376
msgid "Powered by GIPHY" msgid "Powered by GIPHY"
msgstr "" msgstr ""
#: src/components/compose.jsx:3368 #: src/components/compose.jsx:3384
msgid "Type to search GIFs" msgid "Type to search GIFs"
msgstr "" msgstr ""
#: src/components/compose.jsx:3466 #: src/components/compose.jsx:3482
#: src/components/media-modal.jsx:387 #: src/components/media-modal.jsx:387
#: src/components/timeline.jsx:889 #: src/components/timeline.jsx:889
msgid "Previous" msgid "Previous"
msgstr "" msgstr ""
#: src/components/compose.jsx:3484 #: src/components/compose.jsx:3500
#: src/components/media-modal.jsx:406 #: src/components/media-modal.jsx:406
#: src/components/timeline.jsx:906 #: src/components/timeline.jsx:906
msgid "Next" msgid "Next"
msgstr "" msgstr ""
#: src/components/compose.jsx:3501 #: src/components/compose.jsx:3517
msgid "Error loading GIFs" msgid "Error loading GIFs"
msgstr "" msgstr ""
@ -2013,11 +2017,11 @@ msgstr ""
#: src/components/status.jsx:756 #: src/components/status.jsx:756
msgid "Unliked @{0}'s post" msgid "Unliked @{0}'s post"
msgstr "Unliked @{0}'s post" msgstr ""
#: src/components/status.jsx:757 #: src/components/status.jsx:757
msgid "Liked @{0}'s post" msgid "Liked @{0}'s post"
msgstr "Liked @{0}'s post" msgstr ""
#: src/components/status.jsx:796 #: src/components/status.jsx:796
msgid "Unbookmarked @{0}'s post" msgid "Unbookmarked @{0}'s post"

View file

@ -122,7 +122,6 @@ function getInstanceConfiguration(instance) {
configuration, configuration,
maxMediaAttachments, maxMediaAttachments,
maxTootChars, maxTootChars,
pleroma,
pollLimits, pollLimits,
} = instance; } = instance;
@ -130,6 +129,7 @@ function getInstanceConfiguration(instance) {
if (maxMediaAttachments) { if (maxMediaAttachments) {
statuses.maxMediaAttachments ??= maxMediaAttachments; statuses.maxMediaAttachments ??= maxMediaAttachments;
} }
if (maxTootChars) { if (maxTootChars) {
statuses.maxCharacters ??= maxTootChars; statuses.maxCharacters ??= maxTootChars;
} }