mstickereditor icon indicating copy to clipboard operation
mstickereditor copied to clipboard

Fix: update to work with authentificated media feature of synapse (thumbnails are not displaying, not saved into `thumbnails` directory)

Open VityaSchel opened this issue 1 year ago • 7 comments

Only stickers are saved, thumbnails are not saved to the "thumbnails" directory which results in 404 error

VityaSchel avatar May 29 '25 02:05 VityaSchel

Yes I tried mstickereditor set-widget but it does not work — it simply resets the stickers widget to default and when I click "add stickers" it displays "Failed to load extension" What am I doing wrong? widgeturl is stickerpicker url right? it's on subpath

VityaSchel avatar May 29 '25 05:05 VityaSchel

I do see thumbnails referenced in thumbnail_url in my local_thumbnails media storage on server, so they are actually saved correctly However stickerpicker's widget expects thumbnails to be in "thumbnails" subdirectory in the "web" folder

VityaSchel avatar May 29 '25 05:05 VityaSchel

Looks like you made a type in set-widget command It writes stype in the event content instead of type https://github.com/LuckyTurtleDev/mstickereditor/blob/c84aa147ef72e1c05a74daf6346f04140b26496b/mstickerlib/src/matrix/stickerpicker.rs#L15

Which causes this error in integrations webview: Failed to get sticker picker: TypeError: Cannot read properties of undefined (reading 'type')

But that's unrelated to this issue, just was wondering how your set-widget command is different from this guide

VityaSchel avatar May 29 '25 05:05 VityaSchel

Ok looks like it's related to this:

As of March 2025, maunium-stickerpicker works around Matrix's authenticated media requirements by hosting thumbnails of stickers next to the sticker pack metadata. To update old packs, you can run sticker-download-thumbnails path/to/pack.json, which will download all the media using your access token and store thumbnails in the thumbnails directory next to the pack JSON. The thumbnails should then be served along with the JSON files (if using GitHub pages, just commit the images).

I confirmed this by running sticker-download-thumbnails. So the order of commands is as following:

  1. build mstickereditor and add its bin from local .cargo directory to $PATH, create config file for mstickereditor
  2. cd into the stickerpicker directory
  3. source .venv/bin/activate
  4. cd web/packs
  5. mstickereditor import t.me/addstickers/my-stickerpack
  6. mstickereditor create-index
  7. sticker-download-thumbnails ./my-stickerpack.json

Also apparently if you use delegation you are still supposed to write your actual matrix domain and not the part in username when asked for "Homeserver URL"

Would be nice if you make this project store thumbnails this way too! Especially if you can make it put scaled version of the image (32x32 px) because currently pulled thumbnails from these packs are in max res, 512x512 which really slows down downloading

VityaSchel avatar May 29 '25 05:05 VityaSchel

maunium's sticker-download-thumbnails script unfortunanely does not work with animated gifs and transparent images, I'm wondering if it'd be easier to modify this project's code especially because thumbnail generator is already present, just not configured to write into current directory. I did sent a PR into their repository but now I'll look what I can do there

VityaSchel avatar May 29 '25 06:05 VityaSchel

For anyone coming here in future I fixed the thumbnails problem and added stickers resizing to 64x64 in preview window and to 256x256 in the dialogue. I also made all previews playable by using sticker converted data in thumbnail, not telegram's provided sticker thumbnail. I'm not a rust developer so I won't make a PR but as a dirty quick fix you can use my git commits patch files. Keep in mind that for 0001-Resize-stickers-before-upload-to-.-thumbnails-direct.patch you will need to run cargo add photon-rs in mstickerlib directory

0001-Fix-set-widget-command.patch 0001-Resize-stickers-before-upload-to-.-thumbnails-direct.patch

Also you need to modify stickerpicker/web/src/index.js file: Modify line 380 by replacing img src with:

 <img src=${makeThumbnailURL(pack.stickers[0].info?.thumbnail_url || pack.stickers[0].url)} alt=${pack.stickers[0].body} class="visible" />

VityaSchel avatar May 30 '25 03:05 VityaSchel

@VityaSchel Thanks for your patch, it works for me

watermelon0339 avatar Dec 19 '25 16:12 watermelon0339