1
0
Fork 0

don't send "" for attachments without content

This commit is contained in:
Cadence Ember 2023-07-02 01:41:31 +12:00
parent 1591bfc578
commit d592a3c82e
5 changed files with 104 additions and 42 deletions

View file

@ -16,6 +16,7 @@ async function messageToEvent(message, guild) {
const events = []
// Text content appears first
if (message.content) {
const body = message.content
const html = markdown.toHTML(body, {
discordCallback: {
@ -59,6 +60,7 @@ async function messageToEvent(message, guild) {
formatted_body: html
})
}
}
// Then attachments
const attachmentEvents = await Promise.all(message.attachments.map(async attachment => {

View file

@ -3,6 +3,23 @@ const assert = require("assert")
const {messageToEvent} = require("./message-to-event")
const data = require("../../test/data")
test("message2event: attachment with no content", async t => {
const events = await messageToEvent(data.message.attachment_no_content, data.guild.general)
t.deepEqual(events, [{
$type: "m.room.message",
msgtype: "m.image",
url: "mxc://cadence.moe/qXoZktDqNtEGuOCZEADAMvhM",
body: "image.png",
external_url: "https://cdn.discordapp.com/attachments/497161332244742154/1124628646431297546/image.png",
info: {
mimetype: "image/png",
w: 466,
h: 85,
size: 12919,
},
}])
})
test("message2event: stickers", async t => {
const events = await messageToEvent(data.message.sticker, data.guild.general)
t.deepEqual(events, [{

View file

@ -60,6 +60,10 @@ async function inviteToRoom(roomID, mxidToInvite, mxid) {
})
}
async function leaveRoom(roomID, mxid) {
await mreq.mreq("POST", path(`/client/v3/rooms/${roomID}/leave`, mxid), {})
}
/**
* @param {string} roomID
* @returns {Promise<import("../types").Event.BaseStateEvent[]>}
@ -108,6 +112,7 @@ module.exports.register = register
module.exports.createRoom = createRoom
module.exports.joinRoom = joinRoom
module.exports.inviteToRoom = inviteToRoom
module.exports.leaveRoom = leaveRoom
module.exports.getAllState = getAllState
module.exports.sendState = sendState
module.exports.sendEvent = sendEvent

View file

@ -11,6 +11,7 @@ const createRoom = sync.require("./d2m/actions/create-room")
const registerUser = sync.require("./d2m/actions/register-user")
const mreq = sync.require("./matrix/mreq")
const api = sync.require("./matrix/api")
const sendMessage = sync.require("./m2d/actions/send-message")
const guildID = "112760669178241024"
const extraContext = {}

View file

@ -140,6 +140,43 @@ module.exports = {
},
message: {
// Display order is text content, attachments, then stickers
attachment_no_content: {
id: "1124628646670389348",
type: 0,
content: "",
channel_id: "497161332244742154",
author: {
id: "320067006521147393",
username: "papiophidian",
global_name: "PapiOphidian",
avatar: "fb2b4535f7a108619e3edae12fcb16c5",
discriminator: "0",
public_flags: 4194880,
avatar_decoration: null
},
attachments: [
{
id: "1124628646431297546",
filename: "image.png",
size: 12919,
url: "https://cdn.discordapp.com/attachments/497161332244742154/1124628646431297546/image.png",
proxy_url: "https://media.discordapp.net/attachments/497161332244742154/1124628646431297546/image.png",
width: 466,
height: 85,
content_type: "image/png"
}
],
embeds: [],
mentions: [],
mention_roles: [],
pinned: false,
mention_everyone: false,
tts: false,
timestamp: "2023-07-01T09:12:43.956000+00:00",
edited_timestamp: null,
flags: 0,
components: []
},
sticker: {
id: "1106366167788044450",
type: 0,