Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow pasting attachments on Akkoma / Pleroma instances #735

Merged
merged 30 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
bf693ab
Show error if attachment is rejected for having invalid mime type
Steffo99 Sep 4, 2024
35ef1b5
Accept any file if supportedMediaTypes is undefined
Steffo99 Sep 4, 2024
5479f91
Set maxMediaAttachments to 1000 if Pleroma extensions are detected
Steffo99 Sep 4, 2024
9e600ce
Merge branch 'cheeaun:main' into feature/paste-attach
Steffo99 Sep 4, 2024
78036d0
Autogenerated change to the .po file
Steffo99 Sep 5, 2024
8df2f55
Apply suggested changes to alert strings
Steffo99 Sep 5, 2024
9a60078
Remove pleroma maxMediaAttachments override
Steffo99 Sep 5, 2024
53f7c39
Remove unused pleroma variable
Steffo99 Sep 5, 2024
c277cbc
Move unsupported files alert to outside the loop
Steffo99 Sep 5, 2024
f7d7833
Handle `maxMediaAttachments` being undefined during file cutoff
Steffo99 Sep 5, 2024
143b389
Handle `maxMediaAttachments` being undefined while creating the file …
Steffo99 Sep 5, 2024
61946a8
Handle `maxMediaAttachments` being undefined while creating the gif p…
Steffo99 Sep 5, 2024
3fa9796
Shorten expressions using the always-false property of undefined comp…
Steffo99 Sep 5, 2024
ab5865c
Line changed in `.po` file
Steffo99 Sep 5, 2024
e472bc2
Contract comment to not mention Akkoma instances
Steffo99 Sep 7, 2024
28f87e2
Remove "by your instance" part of the error message
Steffo99 Sep 7, 2024
e77219c
Move unattachable files outside of the loop
Steffo99 Sep 7, 2024
475fe22
Improve error messages
Steffo99 Sep 7, 2024
774605d
Fix basic math and logic error, possibly
Steffo99 Sep 8, 2024
1abbe33
Remove `unattachableFiles`
Steffo99 Sep 10, 2024
f82e721
Make "multiple" condition more readable
Steffo99 Sep 10, 2024
2fbef61
Merge remote-tracking branch 'upstream/main' into feature/paste-attach
Steffo99 Sep 10, 2024
e1e3081
Update po files
Steffo99 Sep 10, 2024
906d601
Fix brace not being in the same line as else
Steffo99 Sep 23, 2024
88c52e4
Make explicit the undefined check to disable the attachment button
Steffo99 Sep 23, 2024
78dcff4
Update po files
Steffo99 Sep 23, 2024
aa33274
Merge branch 'main' into feature/paste-attach
Steffo99 Sep 23, 2024
58144a5
Update po files
Steffo99 Sep 23, 2024
6bd3ad0
Merge remote-tracking branch 'cheeaun/main' into feature/paste-attach
Steffo99 Oct 11, 2024
f49074a
Merge .po file
Steffo99 Oct 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 32 additions & 16 deletions src/components/compose.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ function highlightText(text, { maxCharacters = Infinity }) {

// const rtf = new Intl.RelativeTimeFormat();
const RTF = mem((locale) => new Intl.RelativeTimeFormat(locale || undefined));
const LF = mem((locale) => new Intl.ListFormat(locale || undefined));

const CUSTOM_EMOJIS_COUNT = 100;

Expand All @@ -210,6 +211,7 @@ function Compose({
}) {
const { i18n } = useLingui();
const rtf = RTF(i18n.locale);
const lf = LF(i18n.locale);

console.warn('RENDER COMPOSER');
const { masto, instance } = api();
Expand All @@ -226,11 +228,11 @@ function Compose({
const {
statuses: {
maxCharacters,
maxMediaAttachments,
maxMediaAttachments, // Beware: it can be undefined!
charactersReservedPerUrl,
} = {},
mediaAttachments: {
supportedMimeTypes = [],
supportedMimeTypes,
imageSizeLimit,
imageMatrixLimit,
videoSizeLimit,
Expand Down Expand Up @@ -600,15 +602,26 @@ function Compose({
const handleItems = (e) => {
const { items } = e.clipboardData || e.dataTransfer;
const files = [];
const unsupportedFiles = [];
for (let i = 0; i < items.length; i++) {
const item = items[i];
if (item.kind === 'file') {
const file = item.getAsFile();
if (file && supportedMimeTypes.includes(file.type)) {
if (supportedMimeTypes !== undefined && !supportedMimeTypes.includes(file.type)) {
unsupportedFiles.push(file);
} else {
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) {
alert(
plural(maxMediaAttachments, {
Expand All @@ -623,16 +636,19 @@ function Compose({
e.preventDefault();
e.stopPropagation();
// Auto-cut-off files to avoid exceeding maxMediaAttachments
const max = maxMediaAttachments - mediaAttachments.length;
const allowedFiles = files.slice(0, max);
if (allowedFiles.length <= 0) {
alert(
plural(maxMediaAttachments, {
one: 'You can only attach up to 1 file.',
other: 'You can only attach up to # files.',
}),
);
return;
let allowedFiles = files;
if(maxMediaAttachments !== undefined) {
const max = maxMediaAttachments - mediaAttachments.length;
allowedFiles = allowedFiles.slice(0, max);
if(allowedFiles.length <= 0) {
alert(
plural(maxMediaAttachments, {
one: 'You can only attach up to 1 file.',
other: 'You can only attach up to # files.',
}),
);
return;
}
}
const mediaFiles = allowedFiles.map((file) => ({
file,
Expand Down Expand Up @@ -1307,8 +1323,8 @@ function Compose({
<label class="toolbar-button">
<input
type="file"
accept={supportedMimeTypes.join(',')}
multiple={mediaAttachments.length < maxMediaAttachments - 1}
accept={supportedMimeTypes?.join(',')}
multiple={(maxMediaAttachments === undefined) || (maxMediaAttachments - mediaAttachments >= 2)}
disabled={
uiState === 'loading' ||
mediaAttachments.length >= maxMediaAttachments ||
Expand Down Expand Up @@ -1400,7 +1416,7 @@ function Compose({
class="toolbar-button gif-picker-button"
disabled={
uiState === 'loading' ||
mediaAttachments.length >= maxMediaAttachments ||
(maxMediaAttachments !== undefined && mediaAttachments.length >= maxMediaAttachments) ||
!!poll
}
onClick={() => {
Expand Down
Loading
Loading