"use strict" ;
const required = require ( "@validatem/required" ) ;
const isString = require ( "@validatem/is-string" ) ;
const isInteger = require ( "@validatem/is-integer" ) ;
const isPlainObject = require ( "@validatem/is-plain-object" ) ;
const isEvent = require ( "../is-event" ) ;
const isMatrixID = require ( "../is-matrix-id" ) ;
const isEventID = require ( "../is-event-id" ) ;
const isRoomID = require ( "../is-room-id" ) ;
const optionalObject = require ( "../optional-object" ) ;
const isPaginatedChunkOf = require ( "../is-paginated-chunk-of" ) ;
module . exports = function isRoomEvent ( strict = false , extraFields = { } ) {
return isEvent ( strict , {
event _id : [ required , isString ] ,
sender : [ required , isMatrixID ] ,
origin _server _ts : [ required , isInteger ] ,
// In spec, but missing from Room Event format: https://github.com/matrix-org/matrix-doc/issues/2684
redacts : isEventID , // FIXME: Make required when redaction-type event
// Spec omission: https://github.com/matrix-org/matrix-doc/issues/2685
age _ts : isInteger ,
room _id : [ isRoomID ] , // FIXME: Not present on /sync, but will need to be required-checked for event validation elsewhere
// Synapse bug: https://github.com/matrix-org/synapse/issues/7925
age : isInteger ,
// Synapse bug: https://github.com/matrix-org/synapse/issues/7924
user _id : isMatrixID ,
// Synapse bug: https://github.com/matrix-org/synapse/issues/7925#issuecomment-662089208
replaces _state : isEventID ,
// Synapse bug: https://github.com/matrix-org/synapse/issues/7925#issuecomment-663247760
redacted _because : isPlainObject ,
// Obsolete field originating from a now-defunct Synapse fork running on ponies.im
origin _server _ipts : [ isInteger ] ,
unsigned : optionalObject ( {
age : isInteger ,
transaction _id : isString ,
redacted _because : isPlainObject , // FIXME: Cannot do recursion with isRoomEvent (/isStateEvent) -- fixable via `dynamic` wrapper, so that the rules are only generated *after* the validator has finished being declared?
// Spec omission: https://github.com/matrix-org/matrix-doc/issues/2690
redacted _by : isEventID ,
// Spec omission: https://github.com/matrix-org/matrix-doc/issues/1167
replaces _state : isEventID ,
// Spec omission and/or Synapse bug: https://github.com/matrix-org/matrix-doc/issues/877
prev _content : isPlainObject ,
// Spec omission: https://github.com/matrix-org/matrix-doc/issues/684
prev _sender : isMatrixID ,
// MSC 1849, not merged yet: https://github.com/matrix-org/matrix-doc/blob/matthew/msc1849/proposals/1849-aggregations.md
"m.relations" : {
"m.annotation" : isPaginatedChunkOf ( {
type : [ required , isString ] ,
key : [ required , isString ] ,
// Should be required according to MSC, but currently missing in Synapse: https://github.com/matrix-org/synapse/issues/7941#issuecomment-663238820
origin _server _ts : [ /* required, */ isInteger ] ,
count : [ required , isInteger ]
} ) ,
"m.reference" : isPaginatedChunkOf ( {
// Should be required according to MSC, but currently missing in Synapse: https://github.com/matrix-org/synapse/issues/7941
type : [ /* required, */ isString ] ,
event _id : [ required , isEventID ]
} ) ,
"m.replace" : {
event _id : [ required , isEventID ] ,
origin _server _ts : [ required , isInteger ] ,
sender : [ required , isMatrixID ]
}
}
} ) ,
... extraFields
} ) ;
} ;