2023-10-07 09:47:31 +00:00
const assert = require ( "assert" ) . strict
2023-07-02 13:06:05 +00:00
const { test } = require ( "supertape" )
const { eventToMessage } = require ( "./event-to-message" )
const data = require ( "../../test/data" )
2023-08-30 01:29:16 +00:00
const { MatrixServerError } = require ( "../../matrix/mreq" )
2023-09-18 10:51:59 +00:00
const { db , select } = require ( "../../passthrough" )
2023-07-02 13:06:05 +00:00
2023-10-07 09:47:31 +00:00
/* c8 ignore next 7 */
2023-09-23 13:55:47 +00:00
function slow ( ) {
if ( process . argv . includes ( "--slow" ) ) {
return test
} else {
return test . skip
}
}
2023-08-26 08:30:22 +00:00
/ * *
* @ param { string } roomID
* @ param { string } eventID
* @ returns { ( roomID : string , eventID : string ) => Promise < Ty . Event . Outer < Ty . Event . M _Room _Message >> }
* /
function mockGetEvent ( t , roomID _in , eventID _in , outer ) {
return async function ( roomID , eventID ) {
t . equal ( roomID , roomID _in )
t . equal ( eventID , eventID _in )
return new Promise ( resolve => {
setTimeout ( ( ) => {
resolve ( {
event _id : eventID _in ,
room _id : roomID _in ,
origin _server _ts : 1680000000000 ,
unsigned : {
age : 2245 ,
transaction _id : "$local.whatever"
} ,
... outer
} )
} )
} )
}
}
2023-08-25 13:43:17 +00:00
function sameFirstContentAndWhitespace ( t , a , b ) {
2023-08-28 11:36:03 +00:00
const a2 = JSON . stringify ( a . messagesToSend [ 0 ] . content )
const b2 = JSON . stringify ( b . messagesToSend [ 0 ] . content )
2023-08-25 13:43:17 +00:00
t . equal ( a2 , b2 )
}
2023-08-26 08:30:22 +00:00
test ( "event2message: body is used when there is no formatted_body" , async t => {
2023-07-02 13:06:05 +00:00
t . deepEqual (
2023-08-26 08:30:22 +00:00
await eventToMessage ( {
2023-07-02 13:06:05 +00:00
content : {
2023-08-25 14:04:49 +00:00
body : "testing plaintext" ,
2023-07-02 13:06:05 +00:00
msgtype : "m.text"
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
origin _server _ts : 1688301929913 ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe" ,
sender : "@cadence:cadence.moe" ,
type : "m.room.message" ,
unsigned : {
age : 405299
2023-07-03 12:39:42 +00:00
}
2023-07-02 13:06:05 +00:00
} ) ,
2023-08-28 11:36:03 +00:00
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "testing plaintext" ,
avatar _url : undefined
} ]
}
2023-08-25 14:04:49 +00:00
)
} )
2023-09-03 13:37:33 +00:00
test ( "event2message: any markdown in body is escaped, except strikethrough" , async t => {
2023-08-25 14:04:49 +00:00
t . deepEqual (
2023-08-26 08:30:22 +00:00
await eventToMessage ( {
2023-08-25 14:04:49 +00:00
content : {
2023-09-03 13:37:33 +00:00
body : "testing **special** ~~things~~ which _should_ *not* `trigger` @any <effects>, except strikethrough" ,
2023-08-25 14:04:49 +00:00
msgtype : "m.text"
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
origin _server _ts : 1688301929913 ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe" ,
sender : "@cadence:cadence.moe" ,
type : "m.room.message" ,
unsigned : {
age : 405299
}
} ) ,
2023-08-28 11:36:03 +00:00
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
2023-09-03 13:37:33 +00:00
content : "testing \\*\\*special\\*\\* ~~things~~ which \\_should\\_ \\*not\\* \\`trigger\\` @any <effects>, except strikethrough" ,
avatar _url : undefined
} ]
}
)
} )
test ( "event2message: links in formatted body are not broken" , async t => {
t . deepEqual (
await eventToMessage ( {
type : "m.room.message" ,
sender : "@cadence:cadence.moe" ,
content : {
msgtype : "m.text" ,
body : "kyuugryphon I wonder what the midjourney text description of this photo is https://upload.wikimedia.org/wikipedia/commons/f/f3/After_gay_pride%2C_rainbow_flags_flying_along_Beach_Street_%2814853144744%29.jpg" ,
format : "org.matrix.custom.html" ,
formatted _body : "<a href=\"https://matrix.to/#/@_ooye_kyuugryphon:cadence.moe\">kyuugryphon</a> I wonder what the midjourney text description of this photo is https://upload.wikimedia.org/wikipedia/commons/f/f3/After_gay_pride%2C_rainbow_flags_flying_along_Beach_Street_%2814853144744%29.jpg"
} ,
origin _server _ts : 1693739630700 ,
unsigned : {
age : 39 ,
transaction _id : "m1693739630587.160"
} ,
event _id : "$zANQGOdnHKZj48lrajojsejH86KNYST26imgb2Sw1Jg" ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe"
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "<@111604486476181504> I wonder what the midjourney text description of this photo is https://upload.wikimedia.org/wikipedia/commons/f/f3/After_gay_pride%2C_rainbow_flags_flying_along_Beach_Street_%2814853144744%29.jpg" ,
avatar _url : undefined
} ]
}
)
} )
test ( "event2message: links in plaintext body are not broken" , async t => {
t . deepEqual (
await eventToMessage ( {
type : "m.room.message" ,
sender : "@cadence:cadence.moe" ,
content : {
msgtype : "m.text" ,
body : "I wonder what the midjourney text description of this photo is https://upload.wikimedia.org/wikipedia/commons/f/f3/After_gay_pride%2C_rainbow_flags_flying_along_Beach_Street_%2814853144744%29.jpg" ,
} ,
origin _server _ts : 1693739630700 ,
unsigned : {
age : 39 ,
transaction _id : "m1693739630587.160"
} ,
event _id : "$zANQGOdnHKZj48lrajojsejH86KNYST26imgb2Sw1Jg" ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe"
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "I wonder what the midjourney text description of this photo is https://upload.wikimedia.org/wikipedia/commons/f/f3/After_gay_pride%2C_rainbow_flags_flying_along_Beach_Street_%2814853144744%29.jpg" ,
2023-08-28 11:36:03 +00:00
avatar _url : undefined
} ]
}
2023-07-02 13:06:05 +00:00
)
} )
2023-08-23 12:35:35 +00:00
2023-08-26 08:30:22 +00:00
test ( "event2message: basic html is converted to markdown" , async t => {
2023-08-25 13:43:17 +00:00
t . deepEqual (
2023-08-26 08:30:22 +00:00
await eventToMessage ( {
2023-08-25 13:43:17 +00:00
content : {
msgtype : "m.text" ,
body : "wrong body" ,
format : "org.matrix.custom.html" ,
2023-09-03 13:37:33 +00:00
formatted _body : "this <strong>is</strong> a <em><strong>test</strong> <u>of</u></em> <del><em>formatting</em></del>"
2023-08-25 13:43:17 +00:00
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
origin _server _ts : 1688301929913 ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe" ,
sender : "@cadence:cadence.moe" ,
type : "m.room.message" ,
unsigned : {
age : 405299
}
} ) ,
2023-08-28 11:36:03 +00:00
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
2023-09-03 13:37:33 +00:00
content : "this **is** a _**test** __of___ ~~_formatting_~~" ,
2023-08-28 11:36:03 +00:00
avatar _url : undefined
} ]
}
2023-08-25 13:43:17 +00:00
)
} )
2023-08-28 13:36:15 +00:00
test ( "event2message: spoilers work" , async t => {
t . deepEqual (
await eventToMessage ( {
content : {
msgtype : "m.text" ,
body : "wrong body" ,
format : "org.matrix.custom.html" ,
formatted _body : ` this <strong>is</strong> a <span data-mx-spoiler><em>test</em></span> of <span data-mx-spoiler="">spoilers</span> `
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
origin _server _ts : 1688301929913 ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe" ,
sender : "@cadence:cadence.moe" ,
type : "m.room.message" ,
unsigned : {
age : 405299
}
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "this **is** a ||_test_|| of ||spoilers||" ,
avatar _url : undefined
} ]
}
)
} )
2023-08-26 08:30:22 +00:00
test ( "event2message: markdown syntax is escaped" , async t => {
2023-08-25 13:43:17 +00:00
t . deepEqual (
2023-08-26 08:30:22 +00:00
await eventToMessage ( {
2023-08-25 13:43:17 +00:00
content : {
msgtype : "m.text" ,
body : "wrong body" ,
format : "org.matrix.custom.html" ,
formatted _body : "this **is** an <strong><em>extreme</em></strong> \\*test\\* of"
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
origin _server _ts : 1688301929913 ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe" ,
sender : "@cadence:cadence.moe" ,
type : "m.room.message" ,
unsigned : {
age : 405299
}
} ) ,
2023-08-28 11:36:03 +00:00
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "this \\*\\*is\\*\\* an **_extreme_** \\\\\\*test\\\\\\* of" ,
avatar _url : undefined
} ]
}
2023-08-25 13:43:17 +00:00
)
} )
2023-08-26 08:30:22 +00:00
test ( "event2message: html lines are bridged correctly" , async t => {
2023-08-25 13:43:17 +00:00
t . deepEqual (
2023-08-26 08:30:22 +00:00
await eventToMessage ( {
2023-08-25 13:43:17 +00:00
content : {
msgtype : "m.text" ,
body : "wrong body" ,
format : "org.matrix.custom.html" ,
formatted _body : "<p>paragraph one<br>line <em>two</em><br>line three<br><br>paragraph two\nline <em>two</em>\nline three\n\nparagraph three</p><p>paragraph four\nline two<br>line three\nline four</p>paragraph five"
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
origin _server _ts : 1688301929913 ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe" ,
sender : "@cadence:cadence.moe" ,
type : "m.room.message" ,
unsigned : {
age : 405299
}
} ) ,
2023-08-28 11:36:03 +00:00
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "paragraph one\nline _two_\nline three\n\nparagraph two\nline _two_\nline three\n\nparagraph three\n\nparagraph four\nline two\nline three\nline four\n\nparagraph five" ,
avatar _url : undefined
} ]
}
2023-08-25 13:43:17 +00:00
)
} )
2023-08-26 08:30:22 +00:00
/ * t e s t ( " e v e n t 2 m e s s a g e : w h i t e s p a c e i s r e t a i n e d " , a s y n c t = > {
2023-08-25 13:43:17 +00:00
t . deepEqual (
2023-08-26 08:30:22 +00:00
await eventToMessage ( {
2023-08-25 13:43:17 +00:00
content : {
msgtype : "m.text" ,
body : "wrong body" ,
format : "org.matrix.custom.html" ,
formatted _body : "line one: test test<br>line two: <strong>test</strong> <strong>test</strong><br>line three: <strong>test test</strong><br>line four: test<strong> </strong>test<br> line five"
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
origin _server _ts : 1688301929913 ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe" ,
sender : "@cadence:cadence.moe" ,
type : "m.room.message" ,
unsigned : {
age : 405299
}
} ) ,
2023-08-28 11:36:03 +00:00
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "line one: test test\nline two: **test** **test**\nline three: **test test**\nline four: test test\n line five" ,
avatar _url : undefined
} ]
}
2023-08-25 13:43:17 +00:00
)
} ) * /
2023-08-26 08:30:22 +00:00
test ( "event2message: whitespace is collapsed" , async t => {
2023-08-25 13:43:17 +00:00
sameFirstContentAndWhitespace (
t ,
2023-08-26 08:30:22 +00:00
await eventToMessage ( {
2023-08-25 13:43:17 +00:00
content : {
msgtype : "m.text" ,
body : "wrong body" ,
format : "org.matrix.custom.html" ,
formatted _body : "line one: test test<br>line two: <strong>test</strong> <strong>test</strong><br>line three: <strong>test test</strong><br>line four: test<strong> </strong>test<br> line five"
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
origin _server _ts : 1688301929913 ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe" ,
sender : "@cadence:cadence.moe" ,
type : "m.room.message" ,
unsigned : {
age : 405299
}
} ) ,
2023-08-28 11:36:03 +00:00
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "line one: test test\nline two: **test** **test**\nline three: **test test**\nline four: test test\nline five" ,
avatar _url : undefined
} ]
}
2023-08-25 13:43:17 +00:00
)
} )
2023-08-26 08:30:22 +00:00
test ( "event2message: lists are bridged correctly" , async t => {
2023-08-25 13:43:17 +00:00
sameFirstContentAndWhitespace (
t ,
2023-08-26 08:30:22 +00:00
await eventToMessage ( {
2023-08-25 13:43:17 +00:00
"type" : "m.room.message" ,
"sender" : "@cadence:cadence.moe" ,
"content" : {
"msgtype" : "m.text" ,
"body" : "* line one\n* line two\n* line three\n * nested one\n * nested two\n* line four" ,
"format" : "org.matrix.custom.html" ,
"formatted_body" : "<ul>\n<li>line one</li>\n<li>line two</li>\n<li>line three\n<ul>\n<li>nested one</li>\n<li>nested two</li>\n</ul>\n</li>\n<li>line four</li>\n</ul>\n"
} ,
"origin_server_ts" : 1692967314062 ,
"unsigned" : {
"age" : 112 ,
"transaction_id" : "m1692967313951.441"
} ,
"event_id" : "$l-xQPY5vNJo3SNxU9d8aOWNVD1glMslMyrp4M_JEF70" ,
"room_id" : "!BpMdOUkWWhFxmTrENV:cadence.moe"
} ) ,
2023-08-28 11:36:03 +00:00
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "* line one\n* line two\n* line three\n * nested one\n * nested two\n* line four" ,
avatar _url : undefined
} ]
}
2023-08-25 13:43:17 +00:00
)
} )
2023-08-26 08:30:22 +00:00
test ( "event2message: long messages are split" , async t => {
2023-08-23 12:35:35 +00:00
t . deepEqual (
2023-08-26 08:30:22 +00:00
await eventToMessage ( {
2023-08-23 12:35:35 +00:00
content : {
body : ( "a" . repeat ( 130 ) + " " ) . repeat ( 19 ) ,
msgtype : "m.text"
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
origin _server _ts : 1688301929913 ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe" ,
sender : "@cadence:cadence.moe" ,
type : "m.room.message" ,
unsigned : {
age : 405299
}
} ) ,
2023-08-28 11:36:03 +00:00
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : ( ( "a" . repeat ( 130 ) + " " ) . repeat ( 15 ) ) . slice ( 0 , - 1 ) ,
avatar _url : undefined
} , {
username : "cadence [they]" ,
content : ( ( "a" . repeat ( 130 ) + " " ) . repeat ( 4 ) ) . slice ( 0 , - 1 ) ,
avatar _url : undefined
} ]
}
2023-08-23 12:35:35 +00:00
)
} )
2023-08-25 13:43:17 +00:00
2023-08-26 08:30:22 +00:00
test ( "event2message: code blocks work" , async t => {
2023-08-25 14:04:49 +00:00
t . deepEqual (
2023-08-26 08:30:22 +00:00
await eventToMessage ( {
2023-08-25 14:04:49 +00:00
content : {
msgtype : "m.text" ,
body : "wrong body" ,
format : "org.matrix.custom.html" ,
formatted _body : "<p>preceding</p>\n<pre><code>code block\n</code></pre>\n<p>following <code>code</code> is inline</p>\n"
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
origin _server _ts : 1688301929913 ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe" ,
sender : "@cadence:cadence.moe" ,
type : "m.room.message" ,
unsigned : {
age : 405299
}
} ) ,
2023-08-28 11:36:03 +00:00
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "preceding\n\n```\ncode block\n```\n\nfollowing `code` is inline" ,
avatar _url : undefined
} ]
}
2023-08-25 14:04:49 +00:00
)
} )
2023-08-26 08:30:22 +00:00
test ( "event2message: code block contents are formatted correctly and not escaped" , async t => {
2023-08-26 07:07:19 +00:00
t . deepEqual (
2023-08-26 08:30:22 +00:00
await eventToMessage ( {
2023-08-26 07:07:19 +00:00
"type" : "m.room.message" ,
"sender" : "@cadence:cadence.moe" ,
"content" : {
"msgtype" : "m.text" ,
"body" : "wrong body" ,
"format" : "org.matrix.custom.html" ,
"formatted_body" : "<pre><code>input = input.replace(/(<\\/?([^ >]+)[^>]*>)?\\n(<\\/?([^ >]+)[^>]*>)?/g,\n_input_ = input = input.replace(/(<\\/?([^ >]+)[^>]*>)?\\n(<\\/?([^ >]+)[^>]*>)?/g,\n</code></pre>\n<p><code>input = input.replace(/(<\\/?([^ >]+)[^>]*>)?\\n(<\\/?([^ >]+)[^>]*>)?/g,</code></p>\n"
} ,
"origin_server_ts" : 1693031482275 ,
"unsigned" : {
"age" : 99 ,
"transaction_id" : "m1693031482146.511"
} ,
"event_id" : "$pGkWQuGVmrPNByrFELxhzI6MCBgJecr5I2J3z88Gc2s" ,
"room_id" : "!BpMdOUkWWhFxmTrENV:cadence.moe"
} ) ,
2023-08-28 11:36:03 +00:00
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "```\ninput = input.replace(/(<\\/?([^ >]+)[^>]*>)?\\n(<\\/?([^ >]+)[^>]*>)?/g,\n_input_ = input = input.replace(/(<\\/?([^ >]+)[^>]*>)?\\n(<\\/?([^ >]+)[^>]*>)?/g,\n```\n\n`input = input.replace(/(<\\/?([^ >]+)[^>]*>)?\\n(<\\/?([^ >]+)[^>]*>)?/g,`" ,
avatar _url : undefined
} ]
}
2023-08-26 07:07:19 +00:00
)
} )
2023-08-26 08:30:22 +00:00
test ( "event2message: quotes have an appropriate amount of whitespace" , async t => {
2023-08-26 07:07:19 +00:00
t . deepEqual (
2023-08-26 08:30:22 +00:00
await eventToMessage ( {
2023-08-26 07:07:19 +00:00
content : {
msgtype : "m.text" ,
body : "wrong body" ,
format : "org.matrix.custom.html" ,
formatted _body : "<blockquote>Chancellor of Germany Angela Merkel, on March 17, 2017: they did not shake hands<br><br><br></blockquote><br>🤨"
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
origin _server _ts : 1688301929913 ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe" ,
sender : "@cadence:cadence.moe" ,
type : "m.room.message" ,
unsigned : {
age : 405299
}
} ) ,
2023-08-28 11:36:03 +00:00
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "> Chancellor of Germany Angela Merkel, on March 17, 2017: they did not shake hands\n🤨" ,
avatar _url : undefined
} ]
}
2023-08-26 07:07:19 +00:00
)
} )
2023-08-25 14:04:49 +00:00
2023-08-30 01:29:16 +00:00
test ( "event2message: m.emote plaintext works" , async t => {
t . deepEqual (
await eventToMessage ( {
content : {
msgtype : "m.emote" ,
body : "tests an m.emote message"
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
origin _server _ts : 1688301929913 ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe" ,
sender : "@cadence:cadence.moe" ,
type : "m.room.message" ,
unsigned : {
age : 405299
}
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
2023-09-03 13:37:33 +00:00
content : "\\* cadence \\[they\\] tests an m.emote message" ,
2023-08-30 01:29:16 +00:00
avatar _url : undefined
} ]
}
)
} )
2023-08-26 08:30:22 +00:00
test ( "event2message: m.emote markdown syntax is escaped" , async t => {
2023-08-25 13:43:17 +00:00
t . deepEqual (
2023-08-26 08:30:22 +00:00
await eventToMessage ( {
2023-08-25 13:43:17 +00:00
content : {
msgtype : "m.emote" ,
body : "wrong body" ,
format : "org.matrix.custom.html" ,
formatted _body : "shows you **her** <strong><em>extreme</em></strong> \\*test\\* of"
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
origin _server _ts : 1688301929913 ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe" ,
sender : "@cadence:cadence.moe" ,
type : "m.room.message" ,
unsigned : {
age : 405299
}
} ) ,
2023-08-28 11:36:03 +00:00
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "\\* cadence \\[they\\] shows you \\*\\*her\\*\\* **_extreme_** \\\\\\*test\\\\\\* of" ,
avatar _url : undefined
} ]
}
2023-08-25 13:43:17 +00:00
)
} )
2023-08-26 08:30:22 +00:00
test ( "event2message: rich reply to a sim user" , async t => {
t . deepEqual (
await eventToMessage ( {
"type" : "m.room.message" ,
"sender" : "@cadence:cadence.moe" ,
"content" : {
"msgtype" : "m.text" ,
"body" : "> <@_ooye_kyuugryphon:cadence.moe> Slow news day.\n\nTesting this reply, ignore" ,
"format" : "org.matrix.custom.html" ,
"formatted_body" : "<mx-reply><blockquote><a href=\"https://matrix.to/#/!fGgIymcYWOqjbSRUdV:cadence.moe/$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04?via=cadence.moe&via=feather.onl\">In reply to</a> <a href=\"https://matrix.to/#/@_ooye_kyuugryphon:cadence.moe\">@_ooye_kyuugryphon:cadence.moe</a><br>Slow news day.</blockquote></mx-reply>Testing this reply, ignore" ,
"m.relates_to" : {
"m.in_reply_to" : {
"event_id" : "$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04"
}
}
} ,
"origin_server_ts" : 1693029683016 ,
"unsigned" : {
"age" : 91 ,
"transaction_id" : "m1693029682894.510"
} ,
"event_id" : "$v_Gtr-bzv9IVlSLBO5DstzwmiDd-GSFaNfHX66IupV8" ,
"room_id" : "!fGgIymcYWOqjbSRUdV:cadence.moe"
} , data . guild . general , {
api : {
getEvent : mockGetEvent ( t , "!fGgIymcYWOqjbSRUdV:cadence.moe" , "$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04" , {
type : "m.room.message" ,
content : {
msgtype : "m.text" ,
body : "Slow news day."
} ,
sender : "@_ooye_kyuugryphon:cadence.moe"
} )
}
} ) ,
2023-08-28 11:36:03 +00:00
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "> <:L1:1144820033948762203><:L2:1144820084079087647>https://discord.com/channels/112760669178241024/687028734322147344/1144865310588014633 <@111604486476181504>:"
+ "\n> Slow news day."
+ "\nTesting this reply, ignore" ,
avatar _url : "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU"
} ]
}
2023-08-26 08:30:22 +00:00
)
} )
2023-09-07 12:13:25 +00:00
test ( "event2message: rich reply to an already-edited message will quote the new message content" , async t => {
t . deepEqual (
await eventToMessage ( {
"type" : "m.room.message" ,
"sender" : "@cadence:cadence.moe" ,
"content" : {
"msgtype" : "m.text" ,
"body" : "> <@_ooye_kyuugryphon:cadence.moe> this is the new content. heya!\n\nhiiiii...." ,
"format" : "org.matrix.custom.html" ,
"formatted_body" : "<mx-reply><blockquote><a href=\"https://matrix.to/#/!fGgIymcYWOqjbSRUdV:cadence.moe/$DSQvWxOBB2DYaei6b83-fb33dQGYt5LJd_s8Nl2a43Q?via=cadence.moe&via=feather.onl\">In reply to</a> <a href=\"https://matrix.to/#/@_ooye_kyuugryphon:cadence.moe\">@_ooye_kyuugryphon:cadence.moe</a><br>this is the new content. heya!</blockquote></mx-reply>hiiiii...." ,
"m.relates_to" : {
"m.in_reply_to" : {
"event_id" : "$DSQvWxOBB2DYaei6b83-fb33dQGYt5LJd_s8Nl2a43Q"
}
}
} ,
"origin_server_ts" : 1693029683016 ,
"unsigned" : {
"age" : 91 ,
"transaction_id" : "m1693029682894.510"
} ,
"event_id" : "$v_Gtr-bzv9IVlSLBO5DstzwmiDd-GSFaNfHX66IupV8" ,
"room_id" : "!fGgIymcYWOqjbSRUdV:cadence.moe"
} , data . guild . general , {
api : {
getEvent : mockGetEvent ( t , "!fGgIymcYWOqjbSRUdV:cadence.moe" , "$DSQvWxOBB2DYaei6b83-fb33dQGYt5LJd_s8Nl2a43Q" , {
type : "m.room.message" ,
room _id : "!fGgIymcYWOqjbSRUdV:cadence.moe" ,
sender : "@_ooye_kyuugryphon:cadence.moe" ,
content : {
"m.mentions" : { } ,
msgtype : "m.text" ,
body : "this is the old content. don't use this!"
} ,
unsigned : {
"m.relations" : {
"m.replace" : {
type : "m.room.message" ,
room _id : "!fGgIymcYWOqjbSRUdV:cadence.moe" ,
sender : "@_ooye_kyuugryphon:cadence.moe" ,
content : {
"m.mentions" : { } ,
msgtype : "m.text" ,
body : "* this is the new content. heya!" ,
"m.new_content" : {
"m.mentions" : { } ,
msgtype : "m.text" ,
body : "this is the new content. heya!"
} ,
"m.relates_to" : {
rel _type : "m.replace" ,
event _id : "$DSQvWxOBB2DYaei6b83-fb33dQGYt5LJd_s8Nl2a43Q"
}
} ,
event _id : "$JOrl8ycWpo7NIAxZ4u-VJmANVrZFBF41LXyp30y8VvU" ,
user _id : "@_ooye_kyuugryphon:cadence.moe" ,
}
}
}
} )
}
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "> <:L1:1144820033948762203><:L2:1144820084079087647><@111604486476181504>:"
+ "\n> this is the new content. heya!"
+ "\nhiiiii...." ,
avatar _url : "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU"
} ]
}
)
} )
2023-09-03 04:38:54 +00:00
test ( "event2message: should avoid using blockquote contents as reply preview in rich reply to a sim user" , async t => {
t . deepEqual (
await eventToMessage ( {
type : "m.room.message" ,
sender : "@cadence:cadence.moe" ,
content : {
msgtype : "m.text" ,
body : "> <@_ooye_kyuugryphon:cadence.moe> > well, you said this, so...\n> \n> that can't be true! there's no way :o\n\nI agree!" ,
format : "org.matrix.custom.html" ,
formatted _body : "<mx-reply><blockquote><a href=\"https://matrix.to/#/!fGgIymcYWOqjbSRUdV:cadence.moe/$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04?via=cadence.moe\">In reply to</a> <a href=\"https://matrix.to/#/@_ooye_kyuugryphon:cadence.moe\">@_ooye_kyuugryphon:cadence.moe</a><br><blockquote>well, you said this, so...<br /></blockquote><br />that can't be true! there's no way :o</blockquote></mx-reply>I agree!" ,
"m.relates_to" : {
"m.in_reply_to" : {
event _id : "$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04"
}
}
} ,
event _id : "$BpGx8_vqHyN6UQDARPDU51ftrlRBhleutRSgpAJJ--g" ,
room _id : "!fGgIymcYWOqjbSRUdV:cadence.moe"
} , data . guild . general , {
api : {
getEvent : mockGetEvent ( t , "!fGgIymcYWOqjbSRUdV:cadence.moe" , "$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04" , {
"type" : "m.room.message" ,
"sender" : "@_ooye_kyuugryphon:cadence.moe" ,
"content" : {
"m.mentions" : { } ,
"msgtype" : "m.text" ,
"body" : "> well, you said this, so...\n\nthat can't be true! there's no way :o" ,
"format" : "org.matrix.custom.html" ,
"formatted_body" : "<blockquote>well, you said this, so...<br></blockquote><br>that can't be true! there's no way :o"
}
} )
}
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "> <:L1:1144820033948762203><:L2:1144820084079087647>https://discord.com/channels/112760669178241024/687028734322147344/1144865310588014633 <@111604486476181504>:"
+ "\n> that can't be true! there's no way :o"
+ "\nI agree!" ,
avatar _url : "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU"
} ]
}
)
} )
2023-10-01 11:14:46 +00:00
test ( "event2message: should include a reply preview when message ends with a blockquote" , async t => {
t . deepEqual (
await eventToMessage ( {
type : "m.room.message" ,
sender : "@cadence:cadence.moe" ,
content : {
msgtype : "m.text" ,
body : "> <@_ooye_cookie:cadence.moe> https://tootsuite.net/Warp-Gate2.gif\n> tanget: @ monster spawner\n> \n> **https://tootsuite.net/Warp-Gate2.gif**\n\naichmophobia" ,
format : "org.matrix.custom.html" ,
formatted _body : "<mx-reply><blockquote><a href=\"https://matrix.to/#/!fGgIymcYWOqjbSRUdV:cadence.moe/$uXM2I6w-XMtim14-OSZ_8Z2uQ6MDAZLT37eYIiEU6KQ?via=cadence.moe\">In reply to</a> <a href=\"https://matrix.to/#/@_ooye_cookie:cadence.moe\">@_ooye_cookie:cadence.moe</a><br><a href=\"https://tootsuite.net/Warp-Gate2.gif\">https://tootsuite.net/Warp-Gate2.gif</a><br />tanget: @ monster spawner<blockquote><strong><a href=\"https://tootsuite.net/Warp-Gate2.gif\">https://tootsuite.net/Warp-Gate2.gif</a></strong></blockquote></blockquote></mx-reply>aichmophobia" ,
"m.relates_to" : {
"m.in_reply_to" : {
event _id : "$uXM2I6w-XMtim14-OSZ_8Z2uQ6MDAZLT37eYIiEU6KQ"
}
}
} ,
event _id : "$n6sg1X9rLeMzCYufJTRvaLzFeLQ-oEXjCWkHtRxcem4" ,
room _id : "!fGgIymcYWOqjbSRUdV:cadence.moe"
} , data . guild . general , {
api : {
getEvent : mockGetEvent ( t , "!fGgIymcYWOqjbSRUdV:cadence.moe" , "$uXM2I6w-XMtim14-OSZ_8Z2uQ6MDAZLT37eYIiEU6KQ" , {
type : 'm.room.message' ,
sender : '@_ooye_cookie:cadence.moe' ,
content : {
'm.mentions' : { } ,
msgtype : 'm.text' ,
body : 'https://tootsuite.net/Warp-Gate2.gif\n' +
'\n' +
'**https://tootsuite.net/Warp-Gate2.gif**' ,
format : 'org.matrix.custom.html' ,
formatted _body : '<a href="https://tootsuite.net/Warp-Gate2.gif">https://tootsuite.net/Warp-Gate2.gif</a><blockquote><strong><a href="https://tootsuite.net/Warp-Gate2.gif">https://tootsuite.net/Warp-Gate2.gif</a></strong></blockquote>'
} ,
unsigned : {
'm.relations' : {
'm.replace' : {
type : 'm.room.message' ,
room _id : '!fGgIymcYWOqjbSRUdV:cadence.moe' ,
sender : '@_ooye_cookie:cadence.moe' ,
content : {
'm.mentions' : { } ,
msgtype : 'm.text' ,
body : '* https://tootsuite.net/Warp-Gate2.gif\n' +
'tanget: @ monster spawner\n' +
'\n' +
'**https://tootsuite.net/Warp-Gate2.gif**' ,
format : 'org.matrix.custom.html' ,
formatted _body : '* <a href="https://tootsuite.net/Warp-Gate2.gif">https://tootsuite.net/Warp-Gate2.gif</a><br>tanget: @ monster spawner<blockquote><strong><a href="https://tootsuite.net/Warp-Gate2.gif">https://tootsuite.net/Warp-Gate2.gif</a></strong></blockquote>' ,
'm.new_content' : {
'm.mentions' : { } ,
msgtype : 'm.text' ,
body : 'https://tootsuite.net/Warp-Gate2.gif\n' +
'tanget: @ monster spawner\n' +
'\n' +
'**https://tootsuite.net/Warp-Gate2.gif**' ,
format : 'org.matrix.custom.html' ,
formatted _body : '<a href="https://tootsuite.net/Warp-Gate2.gif">https://tootsuite.net/Warp-Gate2.gif</a><br>tanget: @ monster spawner<blockquote><strong><a href="https://tootsuite.net/Warp-Gate2.gif">https://tootsuite.net/Warp-Gate2.gif</a></strong></blockquote>'
} ,
'm.relates_to' : {
rel _type : 'm.replace' ,
event _id : '$uXM2I6w-XMtim14-OSZ_8Z2uQ6MDAZLT37eYIiEU6KQ'
}
} ,
event _id : '$onCj1MucuYz6-dFr30jcnnjSEDq50ouyEbRId1wtAa8' ,
user _id : '@_ooye_cookie:cadence.moe' ,
}
}
} ,
user _id : '@_ooye_cookie:cadence.moe' ,
} )
}
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "> <:L1:1144820033948762203><:L2:1144820084079087647>Ⓜ️**_ooye_cookie**:"
+ "\n> https://tootsuite.net/Warp-Gate2.gif tanget: @..."
+ "\naichmophobia" ,
avatar _url : "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU"
} ]
}
)
} )
2023-08-28 12:05:25 +00:00
test ( "event2message: editing a rich reply to a sim user" , async t => {
const eventsFetched = [ ]
t . deepEqual (
await eventToMessage ( {
"type" : "m.room.message" ,
"sender" : "@cadence:cadence.moe" ,
"content" : {
"msgtype" : "m.text" ,
"body" : "> <@_ooye_kyuugryphon:cadence.moe> Slow news day.\n\n * Editing this reply, which is also a test" ,
"m.new_content" : {
"msgtype" : "m.text" ,
"body" : "Editing this reply, which is also a test" ,
"format" : "org.matrix.custom.html" ,
"formatted_body" : "Editing this reply, which is also a test"
} ,
"format" : "org.matrix.custom.html" ,
"formatted_body" : "<mx-reply><blockquote><a href=\"https://matrix.to/#/!fGgIymcYWOqjbSRUdV:cadence.moe/$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04?via=cadence.moe&via=feather.onl\">In reply to</a> <a href=\"https://matrix.to/#/@_ooye_kyuugryphon:cadence.moe\">@_ooye_kyuugryphon:cadence.moe</a><br>Slow news day.</blockquote></mx-reply> * Editing this reply, which is also a test" ,
"m.relates_to" : {
"rel_type" : "m.replace" ,
"event_id" : "$v_Gtr-bzv9IVlSLBO5DstzwmiDd-GSFaNfHX66IupV8"
}
} ,
"origin_server_ts" : 1693222931237 ,
"unsigned" : {
"age" : 44 ,
"transaction_id" : "m1693222931143.837"
} ,
"event_id" : "$XEgssz13q-a7NLO7UZO2Oepq7tSiDBD7YRfr7Xu_QiA" ,
"room_id" : "!fGgIymcYWOqjbSRUdV:cadence.moe"
} , data . guild . general , {
api : {
getEvent : ( roomID , eventID ) => {
2023-10-07 09:47:31 +00:00
assert . ok ( eventID === "$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04" || eventID === "$v_Gtr-bzv9IVlSLBO5DstzwmiDd-GSFaNfHX66IupV8" )
2023-08-28 12:05:25 +00:00
if ( eventID === "$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04" ) {
eventsFetched . push ( "past" )
return mockGetEvent ( t , "!fGgIymcYWOqjbSRUdV:cadence.moe" , "$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04" , {
type : "m.room.message" ,
content : {
msgtype : "m.text" ,
body : "Slow news day."
} ,
sender : "@_ooye_kyuugryphon:cadence.moe"
} ) ( roomID , eventID )
} else if ( eventID === "$v_Gtr-bzv9IVlSLBO5DstzwmiDd-GSFaNfHX66IupV8" ) {
eventsFetched . push ( "original" )
return mockGetEvent ( t , "!fGgIymcYWOqjbSRUdV:cadence.moe" , "$v_Gtr-bzv9IVlSLBO5DstzwmiDd-GSFaNfHX66IupV8" , {
type : "m.room.message" ,
sender : "@cadence:cadence.moe" ,
content : {
msgtype : "m.text" ,
body : "> <@_ooye_kyuugryphon:cadence.moe> Slow news day.\n\nTesting this reply, ignore" ,
format : "org.matrix.custom.html" ,
formatted _body : "<mx-reply><blockquote><a href=\"https://matrix.to/#/!fGgIymcYWOqjbSRUdV:cadence.moe/$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04?via=cadence.moe&via=feather.onl\">In reply to</a> <a href=\"https://matrix.to/#/@_ooye_kyuugryphon:cadence.moe\">@_ooye_kyuugryphon:cadence.moe</a><br>Slow news day.</blockquote></mx-reply>Testing this reply, ignore" ,
"m.relates_to" : {
"m.in_reply_to" : {
event _id : "$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04"
}
}
}
} ) ( roomID , eventID )
}
}
}
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ {
id : "1144874214311067708" ,
message : {
username : "cadence [they]" ,
content : "> <:L1:1144820033948762203><:L2:1144820084079087647>https://discord.com/channels/112760669178241024/687028734322147344/1144865310588014633 <@111604486476181504>:"
+ "\n> Slow news day."
+ "\nEditing this reply, which is also a test" ,
avatar _url : "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU"
}
} ] ,
messagesToSend : [ ]
}
)
t . deepEqual ( eventsFetched , [ "original" , "past" ] )
} )
test ( "event2message: editing a plaintext body message" , async t => {
t . deepEqual (
await eventToMessage ( {
"type" : "m.room.message" ,
"sender" : "@cadence:cadence.moe" ,
"content" : {
"msgtype" : "m.text" ,
"body" : " * well, I guess it's no longer brand new... it's existed for mere seconds..." ,
"m.new_content" : {
"msgtype" : "m.text" ,
"body" : "well, I guess it's no longer brand new... it's existed for mere seconds..."
} ,
"m.relates_to" : {
"rel_type" : "m.replace" ,
"event_id" : "$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSs"
}
} ,
"origin_server_ts" : 1693223873912 ,
"unsigned" : {
"age" : 42 ,
"transaction_id" : "m1693223873796.842"
} ,
"event_id" : "$KxGwvVNzNcmlVbiI2m5kX-jMFNi3Jle71-uu1j7P7vM" ,
2023-10-04 10:23:57 +00:00
"room_id" : "!BnKuBPCvyfOkhcUjEu:cadence.moe"
2023-08-28 12:05:25 +00:00
} , data . guild . general , {
api : {
2023-10-04 10:23:57 +00:00
getEvent : mockGetEvent ( t , "!BnKuBPCvyfOkhcUjEu:cadence.moe" , "$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSs" , {
2023-08-28 12:05:25 +00:00
type : "m.room.message" ,
sender : "@cadence:cadence.moe" ,
content : {
msgtype : "m.text" ,
body : "brand new, never before seen message" ,
}
} )
}
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ {
id : "1145688633186193479" ,
message : {
username : "cadence [they]" ,
content : "well, I guess it's no longer brand new... it's existed for mere seconds..." ,
avatar _url : "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU"
}
} ] ,
messagesToSend : [ ]
}
)
} )
2023-08-30 01:29:16 +00:00
test ( "event2message: editing a plaintext message to be longer" , async t => {
t . deepEqual (
await eventToMessage ( {
"type" : "m.room.message" ,
"sender" : "@cadence:cadence.moe" ,
"content" : {
"msgtype" : "m.text" ,
"body" : " * " + "aaaaaaaaa " . repeat ( 198 ) + "well, I guess it's no longer brand new... it's existed for mere seconds..." + "aaaaaaaaa " . repeat ( 20 ) ,
"m.new_content" : {
"msgtype" : "m.text" ,
"body" : "aaaaaaaaa " . repeat ( 198 ) + "well, I guess it's no longer brand new... it's existed for mere seconds..." + "aaaaaaaaa " . repeat ( 20 )
} ,
"m.relates_to" : {
"rel_type" : "m.replace" ,
"event_id" : "$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSs"
}
} ,
"origin_server_ts" : 1693223873912 ,
"unsigned" : {
"age" : 42 ,
"transaction_id" : "m1693223873796.842"
} ,
"event_id" : "$KxGwvVNzNcmlVbiI2m5kX-jMFNi3Jle71-uu1j7P7vM" ,
2023-10-04 10:23:57 +00:00
"room_id" : "!BnKuBPCvyfOkhcUjEu:cadence.moe"
2023-08-30 01:29:16 +00:00
} , data . guild . general , {
api : {
2023-10-04 10:23:57 +00:00
getEvent : mockGetEvent ( t , "!BnKuBPCvyfOkhcUjEu:cadence.moe" , "$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSs" , {
2023-08-30 01:29:16 +00:00
type : "m.room.message" ,
sender : "@cadence:cadence.moe" ,
content : {
msgtype : "m.text" ,
body : "brand new, never before seen message" ,
}
} )
}
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ {
id : "1145688633186193479" ,
message : {
content : "aaaaaaaaa " . repeat ( 198 ) + "well, I guess it's" ,
username : "cadence [they]" ,
avatar _url : "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU"
}
} ] ,
messagesToSend : [ {
content : "no longer brand new... it's existed for mere seconds..." + ( "aaaaaaaaa " . repeat ( 20 ) ) . slice ( 0 , - 1 ) ,
username : "cadence [they]" ,
avatar _url : "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU"
} ]
}
)
} )
test ( "event2message: editing a plaintext message to be shorter" , async t => {
t . deepEqual (
await eventToMessage ( {
"type" : "m.room.message" ,
"sender" : "@cadence:cadence.moe" ,
"content" : {
"msgtype" : "m.text" ,
"body" : " * well, I guess it's no longer brand new... it's existed for mere seconds..." ,
"m.new_content" : {
"msgtype" : "m.text" ,
"body" : "well, I guess it's no longer brand new... it's existed for mere seconds..."
} ,
"m.relates_to" : {
"rel_type" : "m.replace" ,
"event_id" : "$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSt"
}
} ,
"origin_server_ts" : 1693223873912 ,
"unsigned" : {
"age" : 42 ,
"transaction_id" : "m1693223873796.842"
} ,
"event_id" : "$KxGwvVNzNcmlVbiI2m5kX-jMFNi3Jle71-uu1j7P7vM" ,
2023-10-04 10:23:57 +00:00
"room_id" : "!BnKuBPCvyfOkhcUjEu:cadence.moe"
2023-08-30 01:29:16 +00:00
} , data . guild . general , {
api : {
2023-10-04 10:23:57 +00:00
getEvent : mockGetEvent ( t , "!BnKuBPCvyfOkhcUjEu:cadence.moe" , "$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSt" , {
2023-08-30 01:29:16 +00:00
type : "m.room.message" ,
sender : "@cadence:cadence.moe" ,
content : {
msgtype : "m.text" ,
body : "aaaaaaaaa " . repeat ( 198 ) + "well, I guess it's no longer brand new... it's existed for mere seconds..." + "aaaaaaaaa " . repeat ( 20 )
}
} )
}
} ) ,
{
messagesToDelete : [ "1145688633186193481" ] ,
messagesToEdit : [ {
id : "1145688633186193480" ,
message : {
username : "cadence [they]" ,
content : "well, I guess it's no longer brand new... it's existed for mere seconds..." ,
avatar _url : "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU"
}
} ] ,
messagesToSend : [ ]
}
)
} )
2023-08-28 13:31:52 +00:00
test ( "event2message: editing a formatted body message" , async t => {
t . deepEqual (
await eventToMessage ( {
"type" : "m.room.message" ,
"sender" : "@cadence:cadence.moe" ,
"content" : {
"msgtype" : "m.text" ,
"body" : " * **well, I guess it's no longer brand new... it's existed for mere seconds...**" ,
"format" : "org.matrix.custom.html" ,
"formatted_body" : "* <strong>well, I guess it's no longer brand new... it's existed for mere seconds...</strong>" ,
"m.new_content" : {
"msgtype" : "m.text" ,
"body" : "**well, I guess it's no longer brand new... it's existed for mere seconds...**" ,
"format" : "org.matrix.custom.html" ,
"formatted_body" : "<strong>well, I guess it's no longer brand new... it's existed for mere seconds...</strong>"
} ,
"m.relates_to" : {
"rel_type" : "m.replace" ,
"event_id" : "$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSs"
}
} ,
"origin_server_ts" : 1693223873912 ,
"unsigned" : {
"age" : 42 ,
"transaction_id" : "m1693223873796.842"
} ,
"event_id" : "$KxGwvVNzNcmlVbiI2m5kX-jMFNi3Jle71-uu1j7P7vM" ,
2023-10-04 10:23:57 +00:00
"room_id" : "!BnKuBPCvyfOkhcUjEu:cadence.moe"
2023-08-28 13:31:52 +00:00
} , data . guild . general , {
api : {
2023-10-04 10:23:57 +00:00
getEvent : mockGetEvent ( t , "!BnKuBPCvyfOkhcUjEu:cadence.moe" , "$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSs" , {
2023-08-28 13:31:52 +00:00
type : "m.room.message" ,
sender : "@cadence:cadence.moe" ,
content : {
msgtype : "m.text" ,
body : "**brand new, never before seen message**" ,
format : "org.matrix.custom.html" ,
formatted _body : "<strong>brand new, never before seen message</strong>"
}
} )
}
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ {
id : "1145688633186193479" ,
message : {
username : "cadence [they]" ,
content : "**well, I guess it's no longer brand new... it's existed for mere seconds...**" ,
avatar _url : "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU"
}
} ] ,
messagesToSend : [ ]
}
)
} )
2023-08-26 08:30:22 +00:00
test ( "event2message: rich reply to a matrix user's long message with formatting" , async t => {
t . deepEqual (
await eventToMessage ( {
"type" : "m.room.message" ,
"sender" : "@cadence:cadence.moe" ,
"content" : {
2023-09-07 12:13:25 +00:00
"msgtype" : "m.text" ,
"body" : "> <@cadence:cadence.moe> ```\n> i should have a little happy test\n> ```\n> * list **bold** _em_ ~~strike~~\n> # heading 1\n> ## heading 2\n> ### heading 3\n> https://cadence.moe\n> [legit website](https://cadence.moe)\n\nno you can't!!!" ,
"format" : "org.matrix.custom.html" ,
"formatted_body" : "<mx-reply><blockquote><a href=\"https://matrix.to/#/!fGgIymcYWOqjbSRUdV:cadence.moe/$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04?via=cadence.moe&via=feather.onl\">In reply to</a> <a href=\"https://matrix.to/#/@cadence:cadence.moe\">@cadence:cadence.moe</a><br><pre><code>i should have a little happy test\n</code></pre>\n<ul>\n<li>list <strong>bold</strong> <em>em</em> ~~strike~~</li>\n</ul>\n<h1>heading 1</h1>\n<h2>heading 2</h2>\n<h3>heading 3</h3>\n<p>https://cadence.moe<br /><a href=\"https://cadence.moe\">legit website</a></p>\n</blockquote></mx-reply><strong>no you can't!!!</strong>" ,
"m.relates_to" : {
"m.in_reply_to" : {
"event_id" : "$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04"
}
}
2023-08-26 08:30:22 +00:00
} ,
"origin_server_ts" : 1693037401693 ,
"unsigned" : {
2023-09-07 12:13:25 +00:00
"age" : 381 ,
"transaction_id" : "m1693037401592.521"
2023-08-26 08:30:22 +00:00
} ,
"event_id" : "$v_Gtr-bzv9IVlSLBO5DstzwmiDd-GSFaNfHX66IupV8" ,
"room_id" : "!fGgIymcYWOqjbSRUdV:cadence.moe"
} , data . guild . general , {
api : {
getEvent : mockGetEvent ( t , "!fGgIymcYWOqjbSRUdV:cadence.moe" , "$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04" , {
"type" : "m.room.message" ,
"sender" : "@cadence:cadence.moe" ,
"content" : {
"msgtype" : "m.text" ,
"body" : "```\ni should have a little happy test\n```\n* list **bold** _em_ ~~strike~~\n# heading 1\n## heading 2\n### heading 3\nhttps://cadence.moe\n[legit website](https://cadence.moe)" ,
"format" : "org.matrix.custom.html" ,
"formatted_body" : "<pre><code>i should have a little happy test\n</code></pre>\n<ul>\n<li>list <strong>bold</strong> <em>em</em> ~~strike~~</li>\n</ul>\n<h1>heading 1</h1>\n<h2>heading 2</h2>\n<h3>heading 3</h3>\n<p>https://cadence.moe<br><a href=\"https://cadence.moe\">legit website</a></p>\n"
}
} )
}
} ) ,
2023-08-28 11:36:03 +00:00
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
2023-10-13 10:05:07 +00:00
content : "> <:L1:1144820033948762203><:L2:1144820084079087647>https://discord.com/channels/112760669178241024/687028734322147344/1144865310588014633 Ⓜ️**cadence [they]**:"
2023-08-28 11:36:03 +00:00
+ "\n> i should have a little happy test list bold em..."
+ "\n**no you can't!!!**" ,
avatar _url : "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU"
} ]
}
2023-08-26 08:30:22 +00:00
)
} )
2023-09-07 11:48:44 +00:00
test ( "event2message: rich reply to an image" , async t => {
t . deepEqual (
await eventToMessage ( {
"type" : "m.room.message" ,
"sender" : "@cadence:cadence.moe" ,
"content" : {
2023-09-07 12:13:25 +00:00
"msgtype" : "m.text" ,
"body" : "> <@cadence:cadence.moe> sent an image.\n\nCaught in 8K UHD VR QLED Epic Edition" ,
"format" : "org.matrix.custom.html" ,
"formatted_body" : "<mx-reply><blockquote><a href=\"https://matrix.to/#/!fGgIymcYWOqjbSRUdV:cadence.moe/$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04?via=cadence.moe&via=feather.onl\">In reply to</a> <a href=\"https://matrix.to/#/@cadence:cadence.moe\">@cadence:cadence.moe</a><br>sent an image.</blockquote></mx-reply>Caught in 8K UHD VR QLED Epic Edition" ,
"m.relates_to" : {
"m.in_reply_to" : {
"event_id" : "$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04"
}
}
2023-09-07 11:48:44 +00:00
} ,
"origin_server_ts" : 1693037401693 ,
"unsigned" : {
2023-09-07 12:13:25 +00:00
"age" : 381 ,
"transaction_id" : "m1693037401592.521"
2023-09-07 11:48:44 +00:00
} ,
"event_id" : "$v_Gtr-bzv9IVlSLBO5DstzwmiDd-GSFaNfHX66IupV8" ,
"room_id" : "!fGgIymcYWOqjbSRUdV:cadence.moe"
} , data . guild . general , {
api : {
getEvent : mockGetEvent ( t , "!fGgIymcYWOqjbSRUdV:cadence.moe" , "$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04" , {
type : "m.room.message" ,
sender : "@_ooye_kyuugryphon:cadence.moe" ,
content : {
"m.mentions" : { } ,
msgtype : "m.image" ,
url : "mxc://cadence.moe/ABfYgGdcIECnraZLGpRnoArG" ,
external _url : "https://cdn.discordapp.com/attachments/1100319550446252084/1149300251648339998/arcafeappx2.png" ,
body : "arcafeappx2.png" ,
filename : "arcafeappx2.png" ,
info : {
mimetype : "image/png" ,
w : 512 ,
h : 512 ,
size : 43990
}
}
} )
}
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "> <:L1:1144820033948762203><:L2:1144820084079087647>https://discord.com/channels/112760669178241024/687028734322147344/1144865310588014633 <@111604486476181504> 🖼️"
+ "\nCaught in 8K UHD VR QLED Epic Edition" ,
avatar _url : "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU"
} ]
}
)
} )
2023-09-07 12:13:25 +00:00
test ( "event2message: rich reply to a spoiler should ensure the spoiler is hidden" , async t => {
t . deepEqual (
await eventToMessage ( {
"type" : "m.room.message" ,
"sender" : "@cadence:cadence.moe" ,
"content" : {
"msgtype" : "m.text" ,
"body" : "> <@cadence:cadence.moe> ||zoe kills a 5 letter noun at the end. don't tell anybody|| cw crossword spoilers you'll never believe\n\nomg NO WAY!!" ,
"format" : "org.matrix.custom.html" ,
"formatted_body" : "<mx-reply><blockquote><a href=\"https://matrix.to/#/!fGgIymcYWOqjbSRUdV:cadence.moe/$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04?via=cadence.moe&via=feather.onl\">In reply to</a> <a href=\"https://matrix.to/#/@cadence:cadence.moe\">@cadence:cadence.moe</a><br><span data-mx-spoiler=\"\">zoe kills a 5 letter noun at the end. don't tell anybody</span> cw crossword spoilers you'll never believe</blockquote></mx-reply>omg NO WAY!!" ,
"m.relates_to" : {
"m.in_reply_to" : {
"event_id" : "$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04"
}
}
} ,
"origin_server_ts" : 1693037401693 ,
"unsigned" : {
"age" : 381 ,
"transaction_id" : "m1693037401592.521"
} ,
"event_id" : "$v_Gtr-bzv9IVlSLBO5DstzwmiDd-GSFaNfHX66IupV8" ,
"room_id" : "!fGgIymcYWOqjbSRUdV:cadence.moe"
} , data . guild . general , {
api : {
getEvent : mockGetEvent ( t , "!fGgIymcYWOqjbSRUdV:cadence.moe" , "$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04" , {
type : "m.room.message" ,
sender : "@_ooye_kyuugryphon:cadence.moe" ,
content : {
"m.mentions" : { } ,
msgtype : "m.text" ,
body : "||zoe kills a 5 letter noun at the end. don't tell anybody|| cw crossword spoilers you'll never believe" ,
format : "org.matrix.custom.html" ,
formatted _body : ` <span data-mx-spoiler="">zoe kills a 5 letter noun at the end. don't tell anybody</span> cw crossword spoilers you'll never believe `
}
} )
}
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "> <:L1:1144820033948762203><:L2:1144820084079087647>https://discord.com/channels/112760669178241024/687028734322147344/1144865310588014633 <@111604486476181504>:"
+ "\n> [spoiler] cw crossword spoilers you'll never..."
+ "\nomg NO WAY!!" ,
avatar _url : "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU"
} ]
}
)
} )
2023-08-26 08:30:22 +00:00
test ( "event2message: with layered rich replies, the preview should only be the real text" , async t => {
t . deepEqual (
await eventToMessage ( {
type : "m.room.message" ,
sender : "@cadence:cadence.moe" ,
content : {
msgtype : "m.text" ,
body : "> <@cadence:cadence.moe> two\n\nthree" ,
format : "org.matrix.custom.html" ,
2023-10-04 10:23:57 +00:00
formatted _body : "<mx-reply><blockquote><a href=\"https://matrix.to/#/!BnKuBPCvyfOkhcUjEu:cadence.moe/$f-noT-d-Eo_Xgpc05Ww89ErUXku4NwKWYGHLzWKo1kU?via=cadence.moe\">In reply to</a> <a href=\"https://matrix.to/#/@cadence:cadence.moe\">@cadence:cadence.moe</a><br>two</blockquote></mx-reply>three" ,
2023-08-26 08:30:22 +00:00
"m.relates_to" : {
"m.in_reply_to" : {
event _id : "$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04"
}
}
} ,
event _id : "$v_Gtr-bzv9IVlSLBO5DstzwmiDd-GSFaNfHX66IupV8" ,
room _id : "!fGgIymcYWOqjbSRUdV:cadence.moe"
} , data . guild . general , {
api : {
getEvent : mockGetEvent ( t , "!fGgIymcYWOqjbSRUdV:cadence.moe" , "$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04" , {
"type" : "m.room.message" ,
"sender" : "@cadence:cadence.moe" ,
"content" : {
"msgtype" : "m.text" ,
"body" : "> <@cadence:cadence.moe> one\n\ntwo" ,
"format" : "org.matrix.custom.html" ,
2023-10-04 10:23:57 +00:00
"formatted_body" : "<mx-reply><blockquote><a href=\"https://matrix.to/#/!BnKuBPCvyfOkhcUjEu:cadence.moe/$5UtboIC30EFlAYD_Oh0pSYVW8JqOp6GsDIJZHtT0Wls?via=cadence.moe\">In reply to</a> <a href=\"https://matrix.to/#/@cadence:cadence.moe\">@cadence:cadence.moe</a><br>one</blockquote></mx-reply>two" ,
2023-08-26 08:30:22 +00:00
"m.relates_to" : {
"m.in_reply_to" : {
"event_id" : "$5UtboIC30EFlAYD_Oh0pSYVW8JqOp6GsDIJZHtT0Wls"
}
}
}
} )
}
} ) ,
2023-08-28 11:36:03 +00:00
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
2023-10-13 10:05:07 +00:00
content : "> <:L1:1144820033948762203><:L2:1144820084079087647>https://discord.com/channels/112760669178241024/687028734322147344/1144865310588014633 Ⓜ️**cadence [they]**:"
2023-08-28 11:36:03 +00:00
+ "\n> two"
+ "\nthree" ,
avatar _url : "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU"
} ]
}
2023-08-26 08:30:22 +00:00
)
} )
2023-08-26 11:22:23 +00:00
2023-09-14 00:32:27 +00:00
test ( "event2message: raw mentioning discord users in plaintext body works" , async t => {
t . deepEqual (
await eventToMessage ( {
content : {
msgtype : "m.text" ,
body : "<@114147806469554185> what do you think?"
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
origin _server _ts : 1688301929913 ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe" ,
sender : "@cadence:cadence.moe" ,
type : "m.room.message" ,
unsigned : {
age : 405299
}
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "<@114147806469554185> what do you think?" ,
avatar _url : undefined
} ]
}
)
} )
test ( "event2message: raw mentioning discord users in formatted body works" , async t => {
t . deepEqual (
await eventToMessage ( {
content : {
msgtype : "m.text" ,
body : "wrong body" ,
format : "org.matrix.custom.html" ,
formatted _body : ` <@114147806469554185> what do you think? `
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
origin _server _ts : 1688301929913 ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe" ,
sender : "@cadence:cadence.moe" ,
type : "m.room.message" ,
unsigned : {
age : 405299
}
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "<@114147806469554185> what do you think?" ,
avatar _url : undefined
} ]
}
)
} )
2023-08-26 11:22:23 +00:00
test ( "event2message: mentioning discord users works" , async t => {
t . deepEqual (
await eventToMessage ( {
content : {
msgtype : "m.text" ,
body : "wrong body" ,
format : "org.matrix.custom.html" ,
formatted _body : ` I'm just <a href="https://matrix.to/#/@_ooye_extremity:cadence.moe">▲</a> testing mentions `
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
origin _server _ts : 1688301929913 ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe" ,
sender : "@cadence:cadence.moe" ,
type : "m.room.message" ,
unsigned : {
age : 405299
}
} ) ,
2023-08-28 11:36:03 +00:00
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "I'm just <@114147806469554185> testing mentions" ,
avatar _url : undefined
} ]
}
2023-08-26 11:22:23 +00:00
)
} )
test ( "event2message: mentioning matrix users works" , async t => {
t . deepEqual (
await eventToMessage ( {
content : {
msgtype : "m.text" ,
body : "wrong body" ,
format : "org.matrix.custom.html" ,
formatted _body : ` I'm just <a href="https://matrix.to/#/@rnl:cadence.moe">▲</a> testing mentions `
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
origin _server _ts : 1688301929913 ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe" ,
sender : "@cadence:cadence.moe" ,
type : "m.room.message" ,
unsigned : {
age : 405299
}
} ) ,
2023-08-28 11:36:03 +00:00
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "I'm just [▲](<https://matrix.to/#/@rnl:cadence.moe>) testing mentions" ,
avatar _url : undefined
} ]
}
2023-08-26 11:22:23 +00:00
)
} )
test ( "event2message: mentioning bridged rooms works" , async t => {
t . deepEqual (
await eventToMessage ( {
content : {
msgtype : "m.text" ,
body : "wrong body" ,
format : "org.matrix.custom.html" ,
2023-10-04 10:23:57 +00:00
formatted _body : ` I'm just <a href="https://matrix.to/#/!BnKuBPCvyfOkhcUjEu:cadence.moe">worm-form</a> testing channel mentions `
2023-08-26 11:22:23 +00:00
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
origin _server _ts : 1688301929913 ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe" ,
sender : "@cadence:cadence.moe" ,
type : "m.room.message" ,
unsigned : {
age : 405299
}
} ) ,
2023-08-28 11:36:03 +00:00
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
2023-08-30 01:29:16 +00:00
content : "I'm just <#1100319550446252084> testing channel mentions" ,
avatar _url : undefined
} ]
}
)
} )
test ( "event2message: caches the member if the member is not known" , async t => {
let called = 0
t . deepEqual (
await eventToMessage ( {
content : {
body : "testing the member state cache" ,
msgtype : "m.text"
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
origin _server _ts : 1688301929913 ,
room _id : "!should_be_newly_cached:cadence.moe" ,
sender : "@should_be_newly_cached:cadence.moe" ,
type : "m.room.message" ,
unsigned : {
age : 405299
}
} , { } , {
api : {
getStateEvent : async ( roomID , type , stateKey ) => {
called ++
t . equal ( roomID , "!should_be_newly_cached:cadence.moe" )
t . equal ( type , "m.room.member" )
t . equal ( stateKey , "@should_be_newly_cached:cadence.moe" )
return {
2023-09-06 00:27:28 +00:00
avatar _url : "mxc://cadence.moe/this_is_the_avatar"
2023-08-30 01:29:16 +00:00
}
}
}
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
2023-09-06 00:27:28 +00:00
username : "should_be_newly_cached" ,
2023-08-30 01:29:16 +00:00
content : "testing the member state cache" ,
2023-09-06 00:27:28 +00:00
avatar _url : "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/this_is_the_avatar"
2023-08-30 01:29:16 +00:00
} ]
}
)
2023-09-18 10:51:59 +00:00
2023-10-05 23:31:10 +00:00
t . deepEqual ( select ( "member_cache" , [ "avatar_url" , "displayname" , "mxid" ] , { room _id : "!should_be_newly_cached:cadence.moe" } ) . all ( ) , [
2023-09-06 00:27:28 +00:00
{ avatar _url : "mxc://cadence.moe/this_is_the_avatar" , displayname : null , mxid : "@should_be_newly_cached:cadence.moe" }
2023-08-30 01:29:16 +00:00
] )
t . equal ( called , 1 , "getStateEvent should be called once" )
} )
test ( "event2message: skips caching the member if the member does not exist, somehow" , async t => {
let called = 0
t . deepEqual (
await eventToMessage ( {
content : {
body : "should honestly never happen" ,
msgtype : "m.text"
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
origin _server _ts : 1688301929913 ,
room _id : "!not_real:cadence.moe" ,
sender : "@not_real:cadence.moe" ,
type : "m.room.message" ,
unsigned : {
age : 405299
}
} , { } , {
api : {
getStateEvent : async ( roomID , type , stateKey ) => {
called ++
t . equal ( roomID , "!not_real:cadence.moe" )
t . equal ( type , "m.room.member" )
t . equal ( stateKey , "@not_real:cadence.moe" )
throw new MatrixServerError ( "State event doesn't exist or something" )
}
}
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "not_real" ,
content : "should honestly never happen" ,
2023-08-28 11:36:03 +00:00
avatar _url : undefined
} ]
}
2023-08-26 11:22:23 +00:00
)
2023-10-05 23:31:10 +00:00
t . deepEqual ( select ( "member_cache" , [ "avatar_url" , "displayname" , "mxid" ] , { room _id : "!not_real:cadence.moe" } ) . all ( ) , [ ] )
2023-08-30 01:29:16 +00:00
t . equal ( called , 1 , "getStateEvent should be called once" )
2023-08-26 11:22:23 +00:00
} )
2023-09-02 11:28:41 +00:00
2023-09-06 00:27:28 +00:00
test ( "event2message: overly long usernames are shifted into the message content" , async t => {
let called = 0
t . deepEqual (
await eventToMessage ( {
content : {
body : "testing the member state cache" ,
msgtype : "m.text"
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
origin _server _ts : 1688301929913 ,
room _id : "!should_be_newly_cached_2:cadence.moe" ,
sender : "@should_be_newly_cached_2:cadence.moe" ,
type : "m.room.message" ,
unsigned : {
age : 405299
}
} , { } , {
api : {
getStateEvent : async ( roomID , type , stateKey ) => {
called ++
t . equal ( roomID , "!should_be_newly_cached_2:cadence.moe" )
t . equal ( type , "m.room.member" )
t . equal ( stateKey , "@should_be_newly_cached_2:cadence.moe" )
return {
displayname : "I am BLACK I am WHITE I am SHORT I am LONG I am EVERYTHING YOU THINK IS IMPORTANT and I DON'T MATTER" ,
}
}
}
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
2023-09-10 01:47:24 +00:00
username : "I am BLACK I am WHITE I am SHORT I am LONG I am EVERYTHING YOU THINK IS" ,
content : "**IMPORTANT and I DON'T MATTER**\ntesting the member state cache" ,
2023-09-06 00:27:28 +00:00
avatar _url : undefined
} ]
}
)
2023-10-05 23:31:10 +00:00
t . deepEqual ( select ( "member_cache" , [ "avatar_url" , "displayname" , "mxid" ] , { room _id : "!should_be_newly_cached_2:cadence.moe" } ) . all ( ) , [
2023-09-06 00:27:28 +00:00
{ avatar _url : null , displayname : "I am BLACK I am WHITE I am SHORT I am LONG I am EVERYTHING YOU THINK IS IMPORTANT and I DON'T MATTER" , mxid : "@should_be_newly_cached_2:cadence.moe" }
] )
t . equal ( called , 1 , "getStateEvent should be called once" )
} )
test ( "event2message: overly long usernames are not treated specially when the msgtype is m.emote" , async t => {
t . deepEqual (
await eventToMessage ( {
content : {
body : "looks at the start of the message" ,
msgtype : "m.emote"
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
origin _server _ts : 1688301929913 ,
room _id : "!should_be_newly_cached_2:cadence.moe" ,
sender : "@should_be_newly_cached_2:cadence.moe" ,
type : "m.room.message" ,
unsigned : {
age : 405299
}
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
2023-09-10 01:47:24 +00:00
username : "I am BLACK I am WHITE I am SHORT I am LONG I am EVERYTHING YOU THINK IS" ,
2023-09-06 00:27:28 +00:00
content : "\\* I am BLACK I am WHITE I am SHORT I am LONG I am EVERYTHING YOU THINK IS IMPORTANT and I DON'T MATTER looks at the start of the message" ,
avatar _url : undefined
} ]
}
)
} )
2023-09-02 11:28:41 +00:00
test ( "event2message: text attachments work" , async t => {
t . deepEqual (
await eventToMessage ( {
type : "m.room.message" ,
content : {
body : "chiki-powerups.txt" ,
info : {
size : 971 ,
mimetype : "text/plain"
} ,
msgtype : "m.file" ,
url : "mxc://cadence.moe/zyThGlYQxvlvBVbVgKDDbiHH"
} ,
sender : "@cadence:cadence.moe" ,
event _id : "$c2WVyP6KcfAqh5imOa8e0xzt2C8JTR-cWbEd3GargEQ" ,
2023-10-04 10:23:57 +00:00
room _id : "!BnKuBPCvyfOkhcUjEu:cadence.moe"
2023-09-02 11:28:41 +00:00
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "" ,
avatar _url : "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU" ,
attachments : [ { id : "0" , filename : "chiki-powerups.txt" } ] ,
pendingFiles : [ { name : "chiki-powerups.txt" , url : "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/zyThGlYQxvlvBVbVgKDDbiHH" } ]
} ]
}
)
} )
test ( "event2message: image attachments work" , async t => {
t . deepEqual (
await eventToMessage ( {
type : "m.room.message" ,
sender : "@cadence:cadence.moe" ,
content : {
body : "cool cat.png" ,
info : {
size : 43170 ,
mimetype : "image/png" ,
w : 480 ,
h : 480 ,
"xyz.amorgan.blurhash" : "URTHsVaTpdj2eKZgkkkXp{pHl7feo@lSl9Z$"
} ,
msgtype : "m.image" ,
url : "mxc://cadence.moe/IvxVJFLEuksCNnbojdSIeEvn"
} ,
event _id : "$CXQy3Wmg1A-gL_xAesC1HQcQTEXwICLdSwwUx55FBTI" ,
2023-10-04 10:23:57 +00:00
room _id : "!BnKuBPCvyfOkhcUjEu:cadence.moe"
2023-09-02 11:28:41 +00:00
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "" ,
avatar _url : "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU" ,
attachments : [ { id : "0" , filename : "cool cat.png" } ] ,
pendingFiles : [ { name : "cool cat.png" , url : "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/IvxVJFLEuksCNnbojdSIeEvn" } ]
} ]
}
)
} )
2023-09-03 03:40:25 +00:00
test ( "event2message: encrypted image attachments work" , async t => {
t . deepEqual (
await eventToMessage ( {
type : "m.room.message" ,
sender : "@cadence:cadence.moe" ,
content : {
info : {
mimetype : "image/png" ,
size : 105691 ,
w : 1192 ,
h : 309 ,
"xyz.amorgan.blurhash" : "U17USN~q9FtQ-;Rjxuj[9FIUoMM|-=WB9Ft7"
} ,
msgtype : "m.image" ,
body : "image.png" ,
file : {
v : "v2" ,
key : {
alg : "A256CTR" ,
ext : true ,
k : "QTo-oMPnN1Rbc7vBFg9WXMgoctscdyxdFEIYm8NYceo" ,
key _ops : [ "encrypt" , "decrypt" ] ,
kty : "oct"
} ,
iv : "Va9SHZpIn5kAAAAAAAAAAA" ,
hashes : {
sha256 : "OUZqZFBcANFt42iAKET9YXfWMCdT0BX7QO0Eyk9q4Js"
} ,
url : "mxc://heyquark.com/LOGkUTlVFrqfiExlGZNgCJJX" ,
mimetype : "image/png"
}
} ,
event _id : "$JNhONhXO-5jrztZz8b7mbTMJasbU78TwQr4tog-3Mnk" ,
2023-10-04 10:23:57 +00:00
room _id : "!BnKuBPCvyfOkhcUjEu:cadence.moe"
2023-09-03 03:40:25 +00:00
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "" ,
avatar _url : "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU" ,
attachments : [ { id : "0" , filename : "image.png" } ] ,
pendingFiles : [ {
name : "image.png" ,
url : "https://matrix.cadence.moe/_matrix/media/r0/download/heyquark.com/LOGkUTlVFrqfiExlGZNgCJJX" ,
key : "QTo-oMPnN1Rbc7vBFg9WXMgoctscdyxdFEIYm8NYceo" ,
iv : "Va9SHZpIn5kAAAAAAAAAAA"
} ]
} ]
}
)
} )
2023-09-02 11:28:41 +00:00
test ( "event2message: stickers work" , async t => {
t . deepEqual (
await eventToMessage ( {
type : "m.sticker" ,
sender : "@cadence:cadence.moe" ,
content : {
body : "get_real2" ,
url : "mxc://cadence.moe/NyMXQFAAdniImbHzsygScbmN" ,
info : {
w : 320 ,
h : 298 ,
mimetype : "image/gif" ,
size : 331394 ,
thumbnail _info : {
w : 320 ,
h : 298 ,
mimetype : "image/gif" ,
size : 331394
} ,
thumbnail _url : "mxc://cadence.moe/NyMXQFAAdniImbHzsygScbmN"
}
} ,
event _id : "$PdI-KjdQ8Z_Tb4x9_7wKRPZCsrrXym4BXtbAPekypuM" ,
2023-10-04 10:23:57 +00:00
room _id : "!BnKuBPCvyfOkhcUjEu:cadence.moe"
2023-09-02 11:28:41 +00:00
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "" ,
avatar _url : "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU" ,
attachments : [ { id : "0" , filename : "get_real2.gif" } ] ,
pendingFiles : [ { name : "get_real2.gif" , url : "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/NyMXQFAAdniImbHzsygScbmN" } ]
} ]
}
)
} )
2023-09-19 07:59:58 +00:00
test ( "event2message: static emojis work" , async t => {
t . deepEqual (
await eventToMessage ( {
type : "m.room.message" ,
sender : "@cadence:cadence.moe" ,
content : {
msgtype : "m.text" ,
body : ":hippo:" ,
format : "org.matrix.custom.html" ,
formatted _body : '<img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/qWmbXeRspZRLPcjseyLmeyXC\" title=\":hippo:\" alt=\":hippo:\">'
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe"
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "<:hippo:230201364309868544>" ,
avatar _url : undefined
} ]
}
)
} )
test ( "event2message: animated emojis work" , async t => {
t . deepEqual (
await eventToMessage ( {
type : "m.room.message" ,
sender : "@cadence:cadence.moe" ,
content : {
msgtype : "m.text" ,
body : ":hippo:" ,
format : "org.matrix.custom.html" ,
formatted _body : '<img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/WbYqNlACRuicynBfdnPYtmvc\" title=\":hipposcope:\" alt=\":hipposcope:\">'
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe"
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "<a:hipposcope:393635038903926784>" ,
avatar _url : undefined
} ]
}
)
} )
2023-09-23 13:55:47 +00:00
test ( "event2message: unknown emojis in the middle are linked" , async t => {
t . deepEqual (
await eventToMessage ( {
type : "m.room.message" ,
sender : "@cadence:cadence.moe" ,
content : {
msgtype : "m.text" ,
body : "wrong body" ,
format : "org.matrix.custom.html" ,
formatted _body : 'a <img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/RLMgJGfgTPjIQtvvWZsYjhjy\" title=\":ms_robot_grin:\" alt=\":ms_robot_grin:\"> b'
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe"
} ) ,
{
messagesToDelete : [ ] ,
messagesToEdit : [ ] ,
messagesToSend : [ {
username : "cadence [they]" ,
content : "a [:ms_robot_grin:](https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/RLMgJGfgTPjIQtvvWZsYjhjy) b" ,
avatar _url : undefined
} ]
}
)
} )
slow ( ) ( "event2message: unknown emoji in the end is reuploaded as a sprite sheet" , async t => {
const messages = await eventToMessage ( {
type : "m.room.message" ,
sender : "@cadence:cadence.moe" ,
content : {
msgtype : "m.text" ,
body : "wrong body" ,
format : "org.matrix.custom.html" ,
formatted _body : 'a b <img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/RLMgJGfgTPjIQtvvWZsYjhjy\" title=\":ms_robot_grin:\" alt=\":ms_robot_grin:\">'
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe"
} )
const testResult = {
content : messages . messagesToSend [ 0 ] . content ,
fileName : messages . messagesToSend [ 0 ] . pendingFiles [ 0 ] . name ,
fileContentStart : messages . messagesToSend [ 0 ] . pendingFiles [ 0 ] . buffer . subarray ( 0 , 90 ) . toString ( "base64" )
}
t . deepEqual ( testResult , {
content : "a b" ,
fileName : "emojis.png" ,
fileContentStart : "iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAAAPoAAAD6AG1e1JrAAALkklEQVR4nM1ZeWyUxxV/azAGwn0JMJUppPhce++1Oc1i"
} )
} )
slow ( ) ( "event2message: known and unknown emojis in the end are reuploaded as a sprite sheet" , async t => {
const messages = await eventToMessage ( {
type : "m.room.message" ,
sender : "@cadence:cadence.moe" ,
content : {
msgtype : "m.text" ,
body : "wrong body" ,
format : "org.matrix.custom.html" ,
formatted _body : 'known unknown: <img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/qWmbXeRspZRLPcjseyLmeyXC\" title=\":hippo:\" alt=\":hippo:\"> <img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/wcouHVjbKJJYajkhJLsyeJAA\" title=\":ms_robot_dress:\" alt=\":ms_robot_dress:\"> and known unknown: <img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/WbYqNlACRuicynBfdnPYtmvc\" title=\":hipposcope:\" alt=\":hipposcope:\"> <img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/HYcztccFIPgevDvoaWNsEtGJ\" title=\":ms_robot_cat:\" alt=\":ms_robot_cat:\">'
} ,
event _id : "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU" ,
room _id : "!kLRqKKUQXcibIMtOpl:cadence.moe"
} )
const testResult = {
content : messages . messagesToSend [ 0 ] . content ,
fileName : messages . messagesToSend [ 0 ] . pendingFiles [ 0 ] . name ,
fileContentStart : messages . messagesToSend [ 0 ] . pendingFiles [ 0 ] . buffer . subarray ( 0 , 90 ) . toString ( "base64" )
}
t . deepEqual ( testResult , {
content : "known unknown: <:hippo:230201364309868544> [:ms_robot_dress:](https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/wcouHVjbKJJYajkhJLsyeJAA) and known unknown:" ,
fileName : "emojis.png" ,
fileContentStart : "iVBORw0KGgoAAAANSUhEUgAAAGAAAAAwCAYAAADuFn/PAAAACXBIWXMAAAPoAAAD6AG1e1JrAAAT5UlEQVR4nOVbCXSVRZauR9gMsoYlvKwvARKSkPUlJOyL"
} )
} )
2023-09-27 10:25:46 +00:00
slow ( ) ( "event2message: all unknown chess emojis are reuploaded as a sprite sheet" , async t => {
const messages = await eventToMessage ( {
type : "m.room.message" ,
sender : "@cadence:cadence.moe" ,
content : {
msgtype : "m.text" ,
2023-10-07 09:47:31 +00:00
body : "testing :chess_good_move::chess_incorrect::chess_blund::chess_brilliant_move::chess_blundest::chess_draw_black::chess_good_move::chess_incorrect::chess_blund::chess_brilliant_move::chess_blundest::chess_draw_black:" ,
2023-09-27 10:25:46 +00:00
format : "org.matrix.custom.html" ,
2023-10-07 09:47:31 +00:00
formatted _body : "testing <img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/lHfmJpzgoNyNtYHdAmBHxXix\" title=\":chess_good_move:\" alt=\":chess_good_move:\"><img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/MtRdXixoKjKKOyHJGWLsWLNU\" title=\":chess_incorrect:\" alt=\":chess_incorrect:\"><img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/HXfFuougamkURPPMflTJRxGc\" title=\":chess_blund:\" alt=\":chess_blund:\"><img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/ikYKbkhGhMERAuPPbsnQzZiX\" title=\":chess_brilliant_move:\" alt=\":chess_brilliant_move:\"><img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/AYPpqXzVJvZdzMQJGjioIQBZ\" title=\":chess_blundest:\" alt=\":chess_blundest:\"><img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/UVuzvpVUhqjiueMxYXJiFEAj\" title=\":chess_draw_black:\" alt=\":chess_draw_black:\"><img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/lHfmJpzgoNyNtYHdAmBHxXix\" title=\":chess_good_move:\" alt=\":chess_good_move:\"><img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/MtRdXixoKjKKOyHJGWLsWLNU\" title=\":chess_incorrect:\" alt=\":chess_incorrect:\"><img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/HXfFuougamkURPPMflTJRxGc\" title=\":chess_blund:\" alt=\":chess_blund:\"><img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/ikYKbkhGhMERAuPPbsnQzZiX\" title=\":chess_brilliant_move:\" alt=\":chess_brilliant_move:\"><img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/AYPpqXzVJvZdzMQJGjioIQBZ\" title=\":chess_blundest:\" alt=\":chess_blundest:\"><img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/UVuzvpVUhqjiueMxYXJiFEAj\" title=\":chess_draw_black:\" alt=\":chess_draw_black:\">"
2023-09-27 10:25:46 +00:00
} ,
event _id : "$Me6iE8C8CZyrDEOYYrXKSYRuuh_25Jj9kZaNrf7LKr4" ,
room _id : "!maggESguZBqGBZtSnr:cadence.moe"
} )
const testResult = {
content : messages . messagesToSend [ 0 ] . content ,
fileName : messages . messagesToSend [ 0 ] . pendingFiles [ 0 ] . name ,
fileContentStart : messages . messagesToSend [ 0 ] . pendingFiles [ 0 ] . buffer . subarray ( 0 , 90 ) . toString ( "base64" )
}
t . deepEqual ( testResult , {
content : "testing" ,
fileName : "emojis.png" ,
fileContentStart : "iVBORw0KGgoAAAANSUhEUgAAASAAAAAwCAYAAACxIqevAAAACXBIWXMAAAPoAAAD6AG1e1JrAAAgAElEQVR4nOV9B1xUV9r3JMbEGBQLbRodhukDg2jWZP02"
} )
} )