Fix timestamp resolution bug
This commit is contained in:
parent
8277cc4a17
commit
f011cac3c5
2 changed files with 56 additions and 2 deletions
|
@ -349,8 +349,13 @@ async function messageToEvent(message, guild, options = {}, di) {
|
||||||
result = `https://matrix.to/#/${roomID}/${eventID}?${via}`
|
result = `https://matrix.to/#/${roomID}/${eventID}?${via}`
|
||||||
} else {
|
} else {
|
||||||
const ts = dUtils.snowflakeToTimestampExact(messageID)
|
const ts = dUtils.snowflakeToTimestampExact(messageID)
|
||||||
const {event_id} = await di.api.getEventForTimestamp(roomID, ts)
|
try {
|
||||||
result = `https://matrix.to/#/${roomID}/${event_id}?${via}`
|
const {event_id} = await di.api.getEventForTimestamp(roomID, ts)
|
||||||
|
result = `https://matrix.to/#/${roomID}/${event_id}?${via}`
|
||||||
|
} catch (e) {
|
||||||
|
// M_NOT_FOUND: Unable to find event from <ts> in direction Direction.FORWARDS
|
||||||
|
result = `[unknown event, timestamp resolution failed, in room: https://matrix.to/#/${roomID}?${via}]`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result = `${match[0]} [event is from another server]`
|
result = `${match[0]} [event is from another server]`
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
const {test} = require("supertape")
|
const {test} = require("supertape")
|
||||||
const {messageToEvent} = require("./message-to-event")
|
const {messageToEvent} = require("./message-to-event")
|
||||||
|
const {MatrixServerError} = require("../../matrix/mreq")
|
||||||
const data = require("../../../test/data")
|
const data = require("../../../test/data")
|
||||||
const Ty = require("../../types")
|
const Ty = require("../../types")
|
||||||
|
|
||||||
|
@ -267,6 +268,54 @@ test("message2event: message link that OOYE doesn't know about", async t => {
|
||||||
t.equal(called, 3, "getEventForTimestamp, getStateEvent, and getJoinedMembers should be called once each")
|
t.equal(called, 3, "getEventForTimestamp, getStateEvent, and getJoinedMembers should be called once each")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("message2event: message timestamp failed to fetch", async t => {
|
||||||
|
let called = 0
|
||||||
|
const events = await messageToEvent(data.message.message_link_to_before_ooye, data.guild.general, {}, {
|
||||||
|
api: {
|
||||||
|
async getEventForTimestamp(roomID, ts) {
|
||||||
|
called++
|
||||||
|
t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe")
|
||||||
|
throw new MatrixServerError({
|
||||||
|
errcode: "M_NOT_FOUND",
|
||||||
|
error: "Unable to find event from 1726762095974 in direction Direction.FORWARDS"
|
||||||
|
}, {})
|
||||||
|
},
|
||||||
|
async getStateEvent(roomID, type, key) { // for ?via calculation
|
||||||
|
called++
|
||||||
|
t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe")
|
||||||
|
t.equal(type, "m.room.power_levels")
|
||||||
|
t.equal(key, "")
|
||||||
|
return {
|
||||||
|
users: {
|
||||||
|
"@_ooye_bot:cadence.moe": 100
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async getJoinedMembers(roomID) { // for ?via calculation
|
||||||
|
called++
|
||||||
|
t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe")
|
||||||
|
return {
|
||||||
|
joined: {
|
||||||
|
"@_ooye_bot:cadence.moe": {display_name: null, avatar_url: null},
|
||||||
|
"@user:matrix.org": {display_name: null, avatar_url: null}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.deepEqual(events, [{
|
||||||
|
$type: "m.room.message",
|
||||||
|
"m.mentions": {},
|
||||||
|
msgtype: "m.text",
|
||||||
|
body: "Me: I'll scroll up to find a certain message I'll send\n_scrolls up and clicks message links for god knows how long_\n_completely forgets what they were looking for and simply begins scrolling up to find some fun moments_\n_stumbles upon:_ "
|
||||||
|
+ "[unknown event, timestamp resolution failed, in room: https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe?via=cadence.moe&via=matrix.org]",
|
||||||
|
format: "org.matrix.custom.html",
|
||||||
|
formatted_body: "Me: I'll scroll up to find a certain message I'll send<br><em>scrolls up and clicks message links for god knows how long</em><br><em>completely forgets what they were looking for and simply begins scrolling up to find some fun moments</em><br><em>stumbles upon:</em> "
|
||||||
|
+ '[unknown event, timestamp resolution failed, in room: <a href="https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe?via=cadence.moe&via=matrix.org">https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe?via=cadence.moe&via=matrix.org</a>]'
|
||||||
|
}])
|
||||||
|
t.equal(called, 3, "getEventForTimestamp, getStateEvent, and getJoinedMembers should be called once each")
|
||||||
|
})
|
||||||
|
|
||||||
test("message2event: message link from another server", async t => {
|
test("message2event: message link from another server", async t => {
|
||||||
const events = await messageToEvent(data.message.message_link_from_another_server, data.guild.general)
|
const events = await messageToEvent(data.message.message_link_from_another_server, data.guild.general)
|
||||||
t.deepEqual(events, [{
|
t.deepEqual(events, [{
|
||||||
|
|
Loading…
Reference in a new issue