From ae640a8fde8f38c3d5bd7f4242fca4c4f4b7cd38 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Mon, 15 May 2023 17:25:05 +1200 Subject: [PATCH] continue on stickers --- d2m/converters/message-to-event.test.js | 8 +++++++- db/ooye.db | Bin 94208 -> 94208 bytes matrix/file.js | 16 ++++++++++++++++ notes.md | 16 ++++++++++++++++ test/data.js | 13 ++++++++++++- 5 files changed, 51 insertions(+), 2 deletions(-) diff --git a/d2m/converters/message-to-event.test.js b/d2m/converters/message-to-event.test.js index 07a45f7..323dc78 100644 --- a/d2m/converters/message-to-event.test.js +++ b/d2m/converters/message-to-event.test.js @@ -23,6 +23,12 @@ test("message2event: stickers", async t => { }, }, { $type: "m.sticker", - todo: "todo" + body: "pomu puff - damn that tiny lil bitch really chuffing. puffing that fat ass dart", + info: { + mimetype: "image/png" + // thumbnail_url + // thumbnail_info + }, + url: "mxc://" }]) }) diff --git a/db/ooye.db b/db/ooye.db index 924e5995e795ae11ae409e01ad15cfcfed6e76d8..e62e0afe3a346783156dfc1c0677d063c496ed73 100644 GIT binary patch delta 399 zcmZp8z}oPDb%HeGwuv&%jN3LQEZNU2!%;Gs{eUS8$4-ut%^MX=IO?5cSW=BSR4fC6 z9YZ6`b23sA)4f6s)4eR?BYizQeGQE>e9~OflZ#5+yfTVYoGgo64Gj&>4b6<4rNM?6mzzgegeN;&<~SNTnPyg$nj89f2Il$}=D7Jfc?6_Y<|g@j8RrxP z_(wtwG3GWgF)%kUHa9o1G}`>{1RJ}E4A)WyzDnL;ep{|up%<2sClNbDup1kcz1?z%{cGFv1A4{>TOg5E=^y01kN# zQx8237Yr>7z_S?8jS7*lX0r#|{saOCQTv==5tBdrBeP8Fw1h=1IFkSX diff --git a/matrix/file.js b/matrix/file.js index 62a4550..a373676 100644 --- a/matrix/file.js +++ b/matrix/file.js @@ -80,8 +80,24 @@ function emoji(emojiID, animated) { else return base + ".png" } +const stickerFormat = new Map([ + [1, {label: "PNG", ext: "png", mime: "image/png"}], + [2, {label: "APNG", ext: "png", mime: "image/apng"}], + [3, {label: "LOTTIE", ext: "json", mime: "application/json"}], + [4, {label: "GIF", ext: "gif", mime: "image/gif"}] +]) + +function sticker(sticker) { + const format = stickerFormat.get(sticker.format_type) + if (!format) throw new Error(`No such format ${sticker.format_type} for sticker ${JSON.stringify(sticker)}`) + const ext = format.ext + return `/stickers/${sticker.id}.${ext}` +} + module.exports.guildIcon = guildIcon module.exports.userAvatar = userAvatar module.exports.memberAvatar = memberAvatar module.exports.emoji = emoji +module.exports.stickerFormat = stickerFormat +module.exports.sticker = sticker module.exports.uploadDiscordFileToMxc = uploadDiscordFileToMxc diff --git a/notes.md b/notes.md index e63d9e5..3491682 100644 --- a/notes.md +++ b/notes.md @@ -60,6 +60,22 @@ The context-sensitive /invite command will invite Matrix users to the correspond # d2m events +## Login - backfill + +Need to backfill any messages that were missed while offline. + +After logging in, check last_message_id on each channel and compare against database to see if anything has been missed. However, mustn't interpret old channels from before the bridge was created as being "new". So, something has been missed if: + +- The last_message_id is not in the table of bridged messages +- The channel is already set up with a bridged room +- A message has been bridged in that channel before + +(If either of the last two conditions is false, that means the channel predates the bridge and we haven't actually missed anything there.) + +For channels that have missed messages, use the getChannelMessages function, and bridge each in turn. + +Can use custom transaction ID (?) to send the original timestamps to Matrix. See appservice docs for details. + ## Message sent 1. Transform content. diff --git a/test/data.js b/test/data.js index c94d132..9704c8d 100644 --- a/test/data.js +++ b/test/data.js @@ -47,7 +47,18 @@ module.exports = { general: { owner_id: "112760500130975744", premium_tier: 3, - stickers: [], + stickers: [{ + version: 1683838696974, + type: 2, + tags: "sunglasses", + name: "pomu puff", + id: "1106323941183717586", + guild_id: "112760669178241024", + format_type: 1, + description: "damn that tiny lil bitch really chuffing. puffing that fat ass dart", + available: true, + asset: "" + }], max_members: 500000, splash: "86a34ed02524b972918bef810087f8e7", explicit_content_filter: 0,