Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Add basic support for attachments (as per MSC2881) #6683

Closed
wants to merge 6 commits into from

Conversation

chayleaf
Copy link

@chayleaf chayleaf commented Aug 25, 2021

Type: enhancement

See matrix-org/matrix-spec-proposals#2881

Ideally, m.relates_to needs to be an array for multiple attachments to work, and to implement file/image replies properly, but that would require way more changes (including in Synapse) to make all relations code work with arrays. Currently, I just show "In reply to" without the message actually being a reply.

In this implementation, if any text is already in the composer during upload, files get sent as an attachment (and after they finish uploading, text gets sent immediately). Naturally, a better UI will be needed.


Here's what your changelog entry will look like:

✨ Features

Preview: https://612723cb1e11b2602d882f7e--matrix-react-sdk.netlify.app
⚠️ Do you trust the author of this PR? Maybe this build will steal your keys or give you malware. Exercise caution. Use test accounts.

Signed-off-by: Ivan Pavluk <chayleaf@protonmail.com>
@chayleaf chayleaf requested a review from a team as a code owner August 25, 2021 23:05
@github-actions github-actions bot added the T-Enhancement New features, changes in functionality, performance boosts, user-facing improvements label Aug 25, 2021
Copy link
Contributor

@SimonBrandner SimonBrandner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this! It's looking great! Just a couple of readability comments


Few other things:

Comment on lines +152 to +157
const promAfter = (SettingsStore.getValue("feature_message_attachments") && this.props.composer
&& ev.target.files.length === 1
&& (!this.props.composer.state.isComposerEmpty || this.props.composer.props.replyToEvent)) ?
(event: ISendEventResponse) => {
return this.props.composer.sendMessage(event.event_id);
} : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be much more readable if it were split into variables

Comment on lines +555 to +559
const promAfter = (SettingsStore.getValue("feature_message_attachments")
&& clipboardData.files.length === 1 && (!this.model.isEmpty || this.props.replyToEvent)) ?
(event: ISendEventResponse) => {
return this.sendMessage(event.event_id);
} : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be more readable if it were split into variables

Comment on lines +436 to +439
async sendContentListToRoom(
files: File[], roomId: string, matrixClient: MatrixClient,
attachToMessage?: (ISendEventResponse) => Promise<any>,
) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to avoid the callback here? It would be more readable, imo

@@ -203,6 +204,7 @@ export default class RoomView extends React.Component<IProps, IState> {
private roomView = createRef<HTMLElement>();
private searchResultsPanel = createRef<ScrollPanel>();
private messagePanel: TimelinePanel;
private messageComposer: MessageComposer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that createRef() should be sufficient in this case

Copy link
Member

@turt2live turt2live left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woo! Attachments!

Screenshots/gifs of this in action would be appreciated to make design/product review a bit easier.

The code overall is a bit stringy, but I think that's because the composer code is a bit stringy from having to do so many things. The outstanding comments from Simon I think will at least help with readability and thus make it easier to follow.

I've not done a super in-depth review on this just yet as it'll need to go through product and design review, which will probably end up changing how the thing works and thus changing the code we end up with :)

): void {
const attachContent = {
'm.relates_to': {
'rel_type': 'org.matrix.msc2881.m.attachment',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throughout we generally prefer to use UnstableValue from the js-sdk for identifiers like this. It makes for transitioning a bit easier, particularly when/if the MSC becomes stable.

There should be some example usages in the code somewhere: look for new UnstableValue

@turt2live turt2live requested review from a team September 3, 2021 04:32
@chayleaf
Copy link
Author

chayleaf commented Sep 3, 2021

I think of implementing matrix-org/matrix-spec-proposals#3051 support first, as it's necessary for supporting image replies/multiple attachments. Single relation is pretty limiting here. Hence, I'll convert this into a draft PR for now.

@chayleaf chayleaf marked this pull request as draft September 3, 2021 05:49
@kittykat
Copy link
Contributor

I'm going to unassign from Design and Product for now until there are some screenshots/gifs to review

@kittykat kittykat removed request for a team February 22, 2022 15:35
@MadLittleMods MadLittleMods added the Z-Community-PR Issue is solved by a community member's PR label Jun 1, 2022
@langleyd langleyd closed this Sep 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Enhancement New features, changes in functionality, performance boosts, user-facing improvements Z-Community-PR Issue is solved by a community member's PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants