don't send "" for attachments without content
This commit is contained in:
parent
1591bfc578
commit
d592a3c82e
5 changed files with 104 additions and 42 deletions
|
@ -16,6 +16,7 @@ async function messageToEvent(message, guild) {
|
||||||
const events = []
|
const events = []
|
||||||
|
|
||||||
// Text content appears first
|
// Text content appears first
|
||||||
|
if (message.content) {
|
||||||
const body = message.content
|
const body = message.content
|
||||||
const html = markdown.toHTML(body, {
|
const html = markdown.toHTML(body, {
|
||||||
discordCallback: {
|
discordCallback: {
|
||||||
|
@ -59,6 +60,7 @@ async function messageToEvent(message, guild) {
|
||||||
formatted_body: html
|
formatted_body: html
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Then attachments
|
// Then attachments
|
||||||
const attachmentEvents = await Promise.all(message.attachments.map(async attachment => {
|
const attachmentEvents = await Promise.all(message.attachments.map(async attachment => {
|
||||||
|
|
|
@ -3,6 +3,23 @@ const assert = require("assert")
|
||||||
const {messageToEvent} = require("./message-to-event")
|
const {messageToEvent} = require("./message-to-event")
|
||||||
const data = require("../../test/data")
|
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 => {
|
test("message2event: stickers", async t => {
|
||||||
const events = await messageToEvent(data.message.sticker, data.guild.general)
|
const events = await messageToEvent(data.message.sticker, data.guild.general)
|
||||||
t.deepEqual(events, [{
|
t.deepEqual(events, [{
|
||||||
|
|
|
@ -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
|
* @param {string} roomID
|
||||||
* @returns {Promise<import("../types").Event.BaseStateEvent[]>}
|
* @returns {Promise<import("../types").Event.BaseStateEvent[]>}
|
||||||
|
@ -108,6 +112,7 @@ module.exports.register = register
|
||||||
module.exports.createRoom = createRoom
|
module.exports.createRoom = createRoom
|
||||||
module.exports.joinRoom = joinRoom
|
module.exports.joinRoom = joinRoom
|
||||||
module.exports.inviteToRoom = inviteToRoom
|
module.exports.inviteToRoom = inviteToRoom
|
||||||
|
module.exports.leaveRoom = leaveRoom
|
||||||
module.exports.getAllState = getAllState
|
module.exports.getAllState = getAllState
|
||||||
module.exports.sendState = sendState
|
module.exports.sendState = sendState
|
||||||
module.exports.sendEvent = sendEvent
|
module.exports.sendEvent = sendEvent
|
||||||
|
|
1
stdin.js
1
stdin.js
|
@ -11,6 +11,7 @@ const createRoom = sync.require("./d2m/actions/create-room")
|
||||||
const registerUser = sync.require("./d2m/actions/register-user")
|
const registerUser = sync.require("./d2m/actions/register-user")
|
||||||
const mreq = sync.require("./matrix/mreq")
|
const mreq = sync.require("./matrix/mreq")
|
||||||
const api = sync.require("./matrix/api")
|
const api = sync.require("./matrix/api")
|
||||||
|
const sendMessage = sync.require("./m2d/actions/send-message")
|
||||||
const guildID = "112760669178241024"
|
const guildID = "112760669178241024"
|
||||||
|
|
||||||
const extraContext = {}
|
const extraContext = {}
|
||||||
|
|
37
test/data.js
37
test/data.js
|
@ -140,6 +140,43 @@ module.exports = {
|
||||||
},
|
},
|
||||||
message: {
|
message: {
|
||||||
// Display order is text content, attachments, then stickers
|
// 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: {
|
sticker: {
|
||||||
id: "1106366167788044450",
|
id: "1106366167788044450",
|
||||||
type: 0,
|
type: 0,
|
||||||
|
|
Loading…
Reference in a new issue