Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.

Conversation

@Ponjimon
Copy link
Contributor

Status

  • WIP
  • Ready for review
  • Needs testing

Deploy after merge (delete what needn't be deployed)

  • api
  • hyperion (frontend)

Release notes for users (delete if codebase-only change)

  • Messages now also support syntax highlighting for code blocks

Related issues (delete if you don't know of any)
Closes #4677

@spectrum-bot
Copy link

spectrum-bot bot commented Feb 28, 2019

Warnings
⚠️

These modified files do not have Flow enabled:

  • shared/notification-to-text.js

Generated by 🚫 dangerJS

@brianlovin brianlovin requested a review from mxstbr February 28, 2019 13:19
Copy link
Contributor

@mxstbr mxstbr left a comment

Choose a reason for hiding this comment

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

This is super great, thank you!! 🙏

I have one tiny code nitpick inline, but overall the extraction of the common methods makes total sense, perfectly done 👍 Once that is cleaned up we can ship this!

import { convertFromRaw, convertToRaw, EditorState } from 'draft-js';
import { addEmbedsToEditorState } from './add-embeds-to-draft-js';

export default (type: 'TEXT' | 'DRAFTJS', body: string): string => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The type argument here should be lower case to match the input message.messageType.

That way, you do not have to have a conditional outside of this method and can simply do

message.content.body = processMessageContent(message.messageType, message.content.body);
message.messageType = 'draftjs'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be honest, I just copied most of this file from here: https://github.com/withspectrum/spectrum/blob/alpha/shared/draft-utils/process-thread-content.js#L6 and removed one property that was irrelevant for messages. Could have done this refactor better probably, but I just didn't want to change the already existing naming of the stuff. If I change this here, it should be changed everywhere else too.

The type argument / property for thread-related stuff is uppercase in the code. Is it lowercase like this anywhere else? Otherwise I'd suggest just uppercasing it here for the sake of consistency.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is inconsistent in the database, but it should be consistent with that. Threads have a type property that is either TEXT or DRAFTJS, but messages have a messageType property that is either text or draftjs.

That is inconsistent with each other, which is bad, but this method shiuld be consistent with the database, if that makes sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I was not aware of that, I guess. Will change it then.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep I figured, that's why I left that review comment. Sorry for not giving the full context in the initial comment!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I committed some changes to fix it. While on it, I also noticed that those strings ('text' and 'draftjs') and so on, are all over the code, so I made some sort of "enum" for it and replaced all occurencies I could find using that. Strings are prone to typos, this should avoid it for future use. I can revert that and just fix the above, if that's required, but I think it's a good addition.

mxstbr
mxstbr previously approved these changes Mar 1, 2019
Copy link
Contributor

@mxstbr mxstbr left a comment

Choose a reason for hiding this comment

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

This is great, thanks for making that more consistent! 💯 I think we can ship this, will defer to @brianlovin for a final review

@brianlovin
Copy link
Contributor

@lookapanda this is really good, but is it possible for us to preserve the language selection when editing a message? If I type a message with a js-highlighted code block, then edit it and save the edit, the js highlighting goes away.

@Ponjimon
Copy link
Contributor Author

Ponjimon commented Mar 1, 2019

Let me check

@Ponjimon
Copy link
Contributor Author

Ponjimon commented Mar 2, 2019

Okay, I figured out how it works. I needed to modify the stateToMarkdown function a bit, so I needed to duplicate it into the code base. It's not really a nice solution, but I think it would be an overkill to create a seperate fork / package just for that file. What do you think?

@brianlovin brianlovin requested a review from mxstbr March 2, 2019 18:47
@brianlovin
Copy link
Contributor

brianlovin commented Mar 2, 2019

What do you think?

Will let Max weigh in on this!

@mxstbr
Copy link
Contributor

mxstbr commented Mar 4, 2019

Rather than forking it submit the change as a PR to draft-js-export-markdown? https://github.com/sstur/draft-js-utils @sstur is very quick to merge PRs.

Also, that fix really has nothing to do with this PR, it should be done regardless!

Let's submit the patch as an upstream PR, revert the commit here and upgrade the dep in a spearate PR once the change is merged and published.

@Ponjimon
Copy link
Contributor Author

Ponjimon commented Mar 4, 2019

So, I should do a PR at that project?

@mxstbr
Copy link
Contributor

mxstbr commented Mar 4, 2019

Yes, that one is perfect!

e2e test failure is unrelated, something to do with the new composer (cc @brianlovin), so I am going to ship this. Thanks so much for the great contribution @lookapanda!

@mxstbr mxstbr merged commit 80fad2c into withspectrum:alpha Mar 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants