SwiftcordApp / Swiftcord

A fully native Discord client for macOS built 100% in Swift!
https://swiftcordapp.github.io/Swiftcord/
GNU General Public License v3.0
1.85k stars 86 forks source link

Rich Embeds Markdown not working #37

Closed selimgr closed 2 years ago

selimgr commented 2 years ago

Describe the bug

It seems that RichEmbeds containing markdown text are not properly rendering.

To Reproduce

  1. Go to a channel with RichEmbed messages including markdown text inside.

Expected behavior

See screenshots

Screenshots

First one is SwiftCord, the other one is Discord https://imgur.com/a/rBOkGFO

Additional context

I'm not sure if this is a problem or not as I saw that "Rich message rendering" should work fine on the roadmap. So just in case 🤷‍♂️ ALSO the "author" field does not appear in the Rich Embed either (see the top part of it in the screenshots)

By the way, I really appreciate your work!! The UI looks soo good and Discord should defintively make a native version instead of electron... Can't wait to see Voice channels haha

cryptoAlgorithm commented 2 years ago

I should create a pinned issue for embeds. Basically, I added embed support over a few days and just left it to develop other features. This meant embeds were kinda half done, usable but not complete. I should've came back to them sooner but basically was caught up making bugfixes/implementing other features so embeds were basically left alone. I will fix all these issues soon, after fixing DMs :D

Thanks for the support!

selimgr commented 2 years ago

After installing XCode and learning a bit of Swift & SwiftUI (thanks to the Discord server haha), I found that the markdown is not rendered if the passed string is not a LocalizedStringKey.

By adding LocalizedStringKey() around the embeds string variables in the EmbedView, markdown is correctly rendered on Rich Embeds.

A screenshot of the final result: image (I also added the missing author field + URL support on the title 😄 )

The code should look like this: (example for the description)

if let description = embed.description {
    // old: Text(description)
    Text(LocalizedStringKey(description))
        .textSelection(.enabled)
        .opacity(0.9)
        .frame(maxWidth: .infinity, alignment: .leading)
}
cryptoAlgorithm commented 2 years ago

@selimgr In fact, as you can probably find elsewhere, wrapping the string with .init(str) will work too. i.e.: Text(.init(theMessageStr))

cryptoAlgorithm commented 2 years ago

This is also, yet another silly SwiftUI bug

cryptoAlgorithm commented 2 years ago

The PR, also by @selimgr, resolves this and has been merged. Thanks for your contribution!