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

Use native upload when relaying from discord #1977

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

yousefmansy1
Copy link
Contributor

Add option for using a native upload when relaying from discord.
Resolves #1965

[discord]
	[discord.maps]
		Server="xxxxxxxxxxxxxxxxxxxxxxxxxx"
		Token="xxxxxxxxxxxxxxxxxxxxxxxxxx"
		RemoteNickFormat="{NICK}\n"
		AutoWebhooks=true
		UseLocalAvatar=["telegram.bot"]
		PreserveThreading=true
		UseNativeUpload=true # ! new

image

@@ -166,6 +166,7 @@ type Protocol struct {
URL string // mattermost, slack // DEPRECATED
UseAPI bool // mattermost, slack
UseLocalAvatar []string // discord
UseNativeUpload bool // discord
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this behaviour should be non-configurable (i.e. just the default behaviour) for any bridges where it's possible. I can't think of a good use-cases for some people wanting external links, and others not wanting external links.

Copy link
Collaborator

Choose a reason for hiding this comment

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

(We can always add a setting later on if someone really wants it. Otherwise I don't think it's worth supporting an extra code path here.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason why I had it configurable is because according to the documentation in the wiki a public link is preferable (referenced in the my issue #1965).

For most platforms this actually isn't possible (without using the media server)
Discord is unique in this regard.

So we'd be betraying that "standard" by making it non configurable.

Personally, I'm fine with making it the default discord behavior but it's up to the maintainers/community if that's the route we take.

Copy link
Collaborator

Choose a reason for hiding this comment

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

my bad, i missed that part of the documentation. i will post a comment on your issue to help inform the spec for this pull request

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I updated the CR to not make it an option, should drop the commit for that change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I updated the CR to not make it an option, should drop the commit for that change?

@42wim what do you think?

@yousefmansy1 yousefmansy1 force-pushed the discord-naitive-upload branch from b038158 to e4e520e Compare February 22, 2023 01:35
@yousefmansy1 yousefmansy1 requested a review from qaisjp February 22, 2023 01:36
@yousefmansy1 yousefmansy1 changed the title Add option for using a naitive upload when relaying from discord Use native upload when relaying from discord Feb 22, 2023
@yousefmansy1 yousefmansy1 force-pushed the discord-naitive-upload branch from 1a56f60 to 3ffd96a Compare March 15, 2023 05:20
@codeclimate
Copy link

codeclimate bot commented Mar 15, 2023

Code Climate has analyzed commit e68ddcf and detected 0 issues on this pull request.

View more on Code Climate.

@yousefmansy1
Copy link
Contributor Author

@42wim I think I fixed the golangci-lint issues, also squashed the commits into 1.

I removed the error return from the handle download because in reality there isn't really much we can do about it other than log it.

@oizyumov
Copy link

oizyumov commented Apr 8, 2023

@42wim could you please look into this PR?

Seems like a little lines of code, yet a worthy update to a matterbridge :)

@jtrees
Copy link

jtrees commented Jul 29, 2023

Thanks! This is really cool. I've applied the patch and it seems to work... kind of.

The image gets rendered correctly in Element Web and Element Android but not in Cinny. There it just looks like a regular downloadable attachment.

I presume the issue is a missing mimetype field. A working image looks like this for me:

{
  "content": {
    "body": "foo.jpeg",
    "info": {
      "h": 512,
      "mimetype": "image/jpeg",
      "size": 1337,
      "w": 512,
      "xyz.amorgan.blurhash": "..."
    },
    "msgtype": "m.image",
    "url": "mxc://matrix.org/blablabla"
  },
  // ...
}

The message from Matterbridge looks like this though:

{
  "content": {
    "body": "foo.jpeg",
    "info": {
      "thumbnail_info": {}
    },
    "msgtype": "m.image",
    "url": "mxc://matrix.org/blablabla"
  },
  // ...
}

if err != nil {
b.Log.Errorf("download %s failed %#v", attach.URL, err)
}

Choose a reason for hiding this comment

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

I tested the pull request and had the issue that images were not being displayed on Element web. The image name still contained the parameters of the image url. I'd maybe add code to remove the parameters from an url before using it as filename.

		urlClean, _, _ := strings.Cut(attach.URL, "?")

		helper.HandleDownloadData(b.Log, rmsg, path.Base(urlClean), rmsg.Text, attach.URL, data, b.General)

Copy link

Choose a reason for hiding this comment

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

I can confirm that this works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setting to toggle native uploads from discord
5 participants