Fix duplicated data appearing on Matrix
This commit is contained in:
@@ -118,14 +118,20 @@ async function editToChanges(message, guild, api) {
|
|||||||
eventsToRedact = oldEventRows.map(e => ({old: e}))
|
eventsToRedact = oldEventRows.map(e => ({old: e}))
|
||||||
|
|
||||||
// If this is a generated embed update, only allow the embeds to be updated, since the system only sends data about events. Ignore changes to other things.
|
// If this is a generated embed update, only allow the embeds to be updated, since the system only sends data about events. Ignore changes to other things.
|
||||||
|
// This also prevents Matrix events that were re-subtyped during conversion (e.g. large image -> text link) from being mistakenly included.
|
||||||
if (isGeneratedEmbed) {
|
if (isGeneratedEmbed) {
|
||||||
unchangedEvents.push(...eventsToRedact.filter(e => e.old.event_subtype !== "m.notice")) // Move them from eventsToRedact to unchangedEvents.
|
unchangedEvents.push(...eventsToRedact.filter(e => e.old.event_subtype !== "m.notice")) // Move them from eventsToRedact to unchangedEvents.
|
||||||
eventsToRedact = eventsToRedact.filter(e => e.old.event_subtype === "m.notice")
|
eventsToRedact = eventsToRedact.filter(e => e.old.event_subtype === "m.notice")
|
||||||
unchangedEvents.push(...eventsToReplace.filter(e => e.old.event_subtype !== "m.notice")) // Move them from eventsToReplace to unchangedEvents.
|
unchangedEvents.push(...eventsToReplace.filter(e => e.old.event_subtype !== "m.notice")) // Move them from eventsToReplace to unchangedEvents.
|
||||||
eventsToReplace = eventsToReplace.filter(e => e.old.event_subtype === "m.notice")
|
eventsToReplace = eventsToReplace.filter(e => e.old.event_subtype === "m.notice")
|
||||||
|
unchangedEvents.push(...eventsToSend.filter(e => e.msgtype !== "m.notice")) // Move them from eventsToSend to unchangedEvents.
|
||||||
|
eventsToSend = eventsToSend.filter(e => e.msgtype === "m.notice")
|
||||||
|
|
||||||
// Don't post new generated embeds for messages if it's been a while since the message was sent. Detached embeds look weird.
|
// Don't post new generated embeds for messages if it's been a while since the message was sent. Detached embeds look weird.
|
||||||
if (message.timestamp && new Date(message.timestamp).getTime() < Date.now() - 120 * 1000) { // older than 2 minutes ago
|
const messageTooOld = message.timestamp && new Date(message.timestamp).getTime() < Date.now() - 120 * 1000 // older than 2 minutes ago
|
||||||
|
// Don't post new generated embeds for messages if the setting was disabled.
|
||||||
|
const embedsEnabled = select("guild_space", "url_preview", {guild_id: guild?.id}).pluck().get() ?? 1
|
||||||
|
if (messageTooOld || !embedsEnabled) {
|
||||||
eventsToSend = eventsToSend.filter(e => e.msgtype !== "m.notice")
|
eventsToSend = eventsToSend.filter(e => e.msgtype !== "m.notice")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -369,3 +369,12 @@ test("edit2changes: don't generate embed if it's been too long since the message
|
|||||||
t.deepEqual(promotions, [])
|
t.deepEqual(promotions, [])
|
||||||
t.equal(senderMxid, null)
|
t.equal(senderMxid, null)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("edit2changes: don't generate new data in situations where m->d(->m) subtypes don't match, like large files", async t => {
|
||||||
|
const {senderMxid, eventsToRedact, eventsToReplace, eventsToSend, promotions} = await editToChanges(data.message.large_file_from_matrix)
|
||||||
|
t.deepEqual(eventsToRedact, [])
|
||||||
|
t.deepEqual(eventsToReplace, [])
|
||||||
|
t.deepEqual(eventsToSend, [])
|
||||||
|
t.deepEqual(promotions, [])
|
||||||
|
t.equal(senderMxid, null)
|
||||||
|
})
|
||||||
|
|||||||
@@ -2657,6 +2657,47 @@ module.exports = {
|
|||||||
flags: 0,
|
flags: 0,
|
||||||
components: []
|
components: []
|
||||||
},
|
},
|
||||||
|
large_file_from_matrix: {
|
||||||
|
type: 0,
|
||||||
|
content: "",
|
||||||
|
attachments: [
|
||||||
|
{
|
||||||
|
id: "1439351589474140290",
|
||||||
|
filename: "image.png",
|
||||||
|
size: 5112701,
|
||||||
|
url: "https://cdn.discordapp.com/attachments/1438284564815548418/1439351589474140290/image.png?ex=691cd720&is=691b85a0&hm=671d32324ce17acb9708057f9a532a3184d02343747b32b2ad8d330a277d8f65&",
|
||||||
|
proxy_url: "https://media.discordapp.net/attachments/1438284564815548418/1439351589474140290/image.png?ex=691cd720&is=691b85a0&hm=671d32324ce17acb9708057f9a532a3184d02343747b32b2ad8d330a277d8f65&",
|
||||||
|
width: 1930,
|
||||||
|
height: 2522,
|
||||||
|
content_type: "image/png",
|
||||||
|
flags: 16,
|
||||||
|
content_scan_version: 2,
|
||||||
|
placeholder: "ZhgKDQJ6pIp2B5hmhndoZ0lgiwTJ",
|
||||||
|
placeholder_version: 1,
|
||||||
|
spoiler: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
embeds: [],
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
edited_timestamp: null,
|
||||||
|
flags: 0,
|
||||||
|
components: [],
|
||||||
|
id: "1439351590262800565",
|
||||||
|
channel_id: "1438284564815548418",
|
||||||
|
author: {
|
||||||
|
id: "1438286167706701958",
|
||||||
|
username: "cibo",
|
||||||
|
discriminator: "0000",
|
||||||
|
avatar: "9c9e1d63ce093e76b9cdb99328c91201",
|
||||||
|
bot: true
|
||||||
|
},
|
||||||
|
pinned: false,
|
||||||
|
mentions: [],
|
||||||
|
mention_roles: [],
|
||||||
|
mention_everyone: false,
|
||||||
|
tts: false,
|
||||||
|
webhook_id: "1438286167706701958"
|
||||||
|
},
|
||||||
simple_reply_to_reply_in_thread: {
|
simple_reply_to_reply_in_thread: {
|
||||||
type: 19,
|
type: 19,
|
||||||
tts: false,
|
tts: false,
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ INSERT INTO channel_room (channel_id, room_id, name, nick, thread_parent, custom
|
|||||||
('176333891320283136', '!qzDBLKlildpzrrOnFZ:cadence.moe', '🌈丨davids-horse_she-took-the-kids', 'wonderland', NULL, 'mxc://cadence.moe/EVvrSkKIRONHjtRJsMLmHWLS'),
|
('176333891320283136', '!qzDBLKlildpzrrOnFZ:cadence.moe', '🌈丨davids-horse_she-took-the-kids', 'wonderland', NULL, 'mxc://cadence.moe/EVvrSkKIRONHjtRJsMLmHWLS'),
|
||||||
('489237891895768942', '!tnedrGVYKFNUdnegvf:tchncs.de', 'ex-room-doesnt-exist-any-more', NULL, NULL, NULL),
|
('489237891895768942', '!tnedrGVYKFNUdnegvf:tchncs.de', 'ex-room-doesnt-exist-any-more', NULL, NULL, NULL),
|
||||||
('1160894080998461480', '!TqlyQmifxGUggEmdBN:cadence.moe', 'ooyexperiment', NULL, NULL, NULL),
|
('1160894080998461480', '!TqlyQmifxGUggEmdBN:cadence.moe', 'ooyexperiment', NULL, NULL, NULL),
|
||||||
('1161864271370666075', '!mHmhQQPwXNananMUqq:cadence.moe', 'updates', NULL, NULL, NULL);
|
('1161864271370666075', '!mHmhQQPwXNananMUqq:cadence.moe', 'updates', NULL, NULL, NULL),
|
||||||
|
('1438284564815548418', '!MHxNpwtgVqWOrmyoTn:cadence.moe', 'sin-cave', NULL, NULL, NULL);
|
||||||
|
|
||||||
INSERT INTO sim (user_id, username, sim_name, mxid) VALUES
|
INSERT INTO sim (user_id, username, sim_name, mxid) VALUES
|
||||||
('0', 'Matrix Bridge', 'bot', '@_ooye_bot:cadence.moe'),
|
('0', 'Matrix Bridge', 'bot', '@_ooye_bot:cadence.moe'),
|
||||||
@@ -73,7 +74,8 @@ INSERT INTO message_channel (message_id, channel_id) VALUES
|
|||||||
('1144874214311067708', '687028734322147344'),
|
('1144874214311067708', '687028734322147344'),
|
||||||
('1339000288144658482', '176333891320283136'),
|
('1339000288144658482', '176333891320283136'),
|
||||||
('1381212840957972480', '112760669178241024'),
|
('1381212840957972480', '112760669178241024'),
|
||||||
('1401760355339862066', '112760669178241024');
|
('1401760355339862066', '112760669178241024'),
|
||||||
|
('1439351590262800565', '1438284564815548418');
|
||||||
|
|
||||||
INSERT INTO event_message (event_id, event_type, event_subtype, message_id, part, reaction_part, source) VALUES
|
INSERT INTO event_message (event_id, event_type, event_subtype, message_id, part, reaction_part, source) VALUES
|
||||||
('$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg', 'm.room.message', 'm.text', '1126786462646550579', 0, 0, 1),
|
('$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg', 'm.room.message', 'm.text', '1126786462646550579', 0, 0, 1),
|
||||||
@@ -117,7 +119,8 @@ INSERT INTO event_message (event_id, event_type, event_subtype, message_id, part
|
|||||||
('$51gH61p_eJc2RylOdE2lAr4-ogP7dS0WJI62lCFzBvk', 'm.room.message', 'm.text', '1339000288144658482', 0, 0, 0),
|
('$51gH61p_eJc2RylOdE2lAr4-ogP7dS0WJI62lCFzBvk', 'm.room.message', 'm.text', '1339000288144658482', 0, 0, 0),
|
||||||
('$AfrB8hzXkDMvuoWjSZkDdFYomjInWH7jMBPkwQMN8AI', 'm.room.message', 'm.text', '1381212840957972480', 0, 1, 1),
|
('$AfrB8hzXkDMvuoWjSZkDdFYomjInWH7jMBPkwQMN8AI', 'm.room.message', 'm.text', '1381212840957972480', 0, 1, 1),
|
||||||
('$43baKEhJfD-RlsFQi0LB16Zxd8yMqp0HSVL00TDQOqM', 'm.room.message', 'm.image', '1381212840957972480', 1, 0, 1),
|
('$43baKEhJfD-RlsFQi0LB16Zxd8yMqp0HSVL00TDQOqM', 'm.room.message', 'm.image', '1381212840957972480', 1, 0, 1),
|
||||||
('$7P2O_VTQNHvavX5zNJ35DV-dbJB1Ag80tGQP_JzGdhk', 'm.room.message', 'm.text', '1401760355339862066', 0, 0, 0);
|
('$7P2O_VTQNHvavX5zNJ35DV-dbJB1Ag80tGQP_JzGdhk', 'm.room.message', 'm.text', '1401760355339862066', 0, 0, 0),
|
||||||
|
('$ielAnR6geu0P1Tl5UXfrbxlIf-SV9jrNprxrGXP3v7M', 'm.room.message', 'm.image', '1439351590262800565', 0, 0, 0);
|
||||||
|
|
||||||
INSERT INTO file (discord_url, mxc_url) VALUES
|
INSERT INTO file (discord_url, mxc_url) VALUES
|
||||||
('https://cdn.discordapp.com/attachments/497161332244742154/1124628646431297546/image.png', 'mxc://cadence.moe/qXoZktDqNtEGuOCZEADAMvhM'),
|
('https://cdn.discordapp.com/attachments/497161332244742154/1124628646431297546/image.png', 'mxc://cadence.moe/qXoZktDqNtEGuOCZEADAMvhM'),
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ reg.namespaces = {
|
|||||||
}
|
}
|
||||||
reg.ooye.bridge_origin = "https://bridge.example.org"
|
reg.ooye.bridge_origin = "https://bridge.example.org"
|
||||||
reg.ooye.time_zone = "Pacific/Auckland"
|
reg.ooye.time_zone = "Pacific/Auckland"
|
||||||
|
reg.ooye.max_file_size = 5000000
|
||||||
|
|
||||||
const sync = new HeatSync({watchFS: false})
|
const sync = new HeatSync({watchFS: false})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user