bug fix where errors weren't being sent

This commit is contained in:
Cadence Ember 2023-08-18 16:58:46 +12:00
commit e08262388b
7 changed files with 24 additions and 24 deletions

View file

@ -2,8 +2,6 @@
const passthrough = require("../../passthrough")
const { sync, db } = passthrough
/** @type {import("../converters/edit-to-changes")} */
const editToChanges = sync.require("../converters/edit-to-changes")
/** @type {import("../../matrix/api")} */
const api = sync.require("../../matrix/api")
@ -12,7 +10,7 @@ const api = sync.require("../../matrix/api")
*/
async function deleteMessage(data) {
/** @type {string?} */
const roomID = db.prepare("SELECT channel_id FROM channel_room WHERE channel_id = ?").pluck().get(data.channel_id)
const roomID = db.prepare("SELECT room_id FROM channel_room WHERE channel_id = ?").pluck().get(data.channel_id)
if (!roomID) return
/** @type {string[]} */
@ -22,7 +20,6 @@ async function deleteMessage(data) {
// Unfortuately, we can't specify a sender to do the redaction as, unless we find out that info via the audit logs
await api.redactEvent(roomID, eventID)
db.prepare("DELETE from event_message WHERE event_id = ?").run(eventID)
// TODO: Consider whether this code could be reused between edited messages and deleted messages.
}
}

View file

@ -35,11 +35,8 @@ async function editMessage(message, guild) {
// Not redacting as the last action because the last action is likely to be shown in the room preview in clients, and we don't want it to look like somebody actually deleted a message.
for (const eventID of eventsToRedact) {
await api.redactEvent(roomID, eventID, senderMxid)
// TODO: Reconsider whether it's the right thing to do to delete it from our database? I mean, it's literally not there any more... you can't do anything else with it...
// and you definitely want to mark it in *some* way to prevent duplicate redactions...
db.prepare("DELETE from event_message WHERE event_id = ?").run(eventID)
// TODO: If I just redacted part = 0, I should update one of the other events to make it the new part = 0, right?
// TODO: Consider whether this code could be reused between edited messages and deleted messages.
}
// 3. Send all the things.

View file

@ -115,8 +115,14 @@ function calculateProfileEventContentHash(content) {
}
/**
* Sync profile data for a sim user. This function follows the following process:
* 1. Join the sim to the room if needed
* 2. Make an object of what the new room member state content would be, including uploading the profile picture if it hasn't been done before
* 3. Compare against the previously known state content, which is helpfully stored in the database
* 4. If the state content has changes, send it to Matrix and update it in the database for next time
* @param {import("discord-api-types/v10").APIUser} user
* @param {Omit<import("discord-api-types/v10").APIGuildMember, "user">} member
* @returns {Promise<string>} mxid of the updated sim
*/
async function syncUser(user, member, guildID, roomID) {
const mxid = await ensureSimJoined(user, roomID)
@ -128,6 +134,7 @@ async function syncUser(user, member, guildID, roomID) {
await api.sendState(roomID, "m.room.member", mxid, content, mxid)
db.prepare("UPDATE sim_member SET profile_event_content_hash = ? WHERE room_id = ? AND mxid = ?").run(profileEventContentHash, roomID, mxid)
}
return mxid
}
async function syncAllUsersInRoom(roomID) {

View file

@ -23,8 +23,7 @@ async function sendMessage(message, guild) {
let senderMxid = null
if (!message.webhook_id) {
assert(message.member)
senderMxid = await registerUser.ensureSimJoined(message.author, roomID)
await registerUser.syncUser(message.author, message.member, message.guild_id, roomID)
senderMxid = await registerUser.syncUser(message.author, message.member, message.guild_id, roomID)
}
const events = await messageToEvent.messageToEvent(message, guild, {}, {api})