Skip to content

Commit c9c4687

Browse files
feat: add CreatorInCreateEvent to help with default room v11 (#465)
related to matrix-org/complement#858 ### Pull Request Checklist * [x] Pull request includes a [sign off](https://github.com/matrix-org/dendrite/blob/master/docs/CONTRIBUTING.md#sign-off) Signed-off-by: `Thomas Traineau <t.traineau@famedly.com>` --------- Signed-off-by: Thomas Traineau t.traineau@famedly.com
1 parent 20c9de3 commit c9c4687

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

eventversion.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ type IRoomVersion interface {
3939
DomainlessRoomIDs() bool
4040
PrivilegedCreators() bool
4141
StateDAGs() bool
42+
// returns true if this room version requires a "creator" field
43+
// in the m.room.create event content (room versions 1–10). The field
44+
// was removed in room version 11, where the creator is instead derived from
45+
// the event sender.
46+
CreatorInCreateEvent() bool
47+
// StrictEventByteLimits returns true if this room version enforces field
48+
// length limits in bytes rather than Unicode codepoints (introduced in v11 for synapse).
49+
StrictEventByteLimits() bool
4250
}
4351

4452
type KnownRoomVersionFunc func(RoomVersion) bool
@@ -110,6 +118,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
110118
checkKnockingAllowedFunc: disallowKnocking,
111119
checkRestrictedJoinAllowedFunc: disallowRestrictedJoins,
112120
checkCreateEvent: checkCreateEventV1,
121+
creatorInCreateEvent: true,
113122
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV1,
114123
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV1,
115124
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV1,
@@ -130,6 +139,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
130139
checkKnockingAllowedFunc: disallowKnocking,
131140
checkRestrictedJoinAllowedFunc: disallowRestrictedJoins,
132141
checkCreateEvent: checkCreateEventV1,
142+
creatorInCreateEvent: true,
133143
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV1,
134144
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV1,
135145
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV1,
@@ -150,6 +160,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
150160
checkKnockingAllowedFunc: disallowKnocking,
151161
checkRestrictedJoinAllowedFunc: disallowRestrictedJoins,
152162
checkCreateEvent: checkCreateEventV1,
163+
creatorInCreateEvent: true,
153164
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
154165
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
155166
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
@@ -170,6 +181,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
170181
checkKnockingAllowedFunc: disallowKnocking,
171182
checkRestrictedJoinAllowedFunc: disallowRestrictedJoins,
172183
checkCreateEvent: checkCreateEventV1,
184+
creatorInCreateEvent: true,
173185
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
174186
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
175187
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
@@ -190,6 +202,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
190202
checkKnockingAllowedFunc: disallowKnocking,
191203
checkRestrictedJoinAllowedFunc: disallowRestrictedJoins,
192204
checkCreateEvent: checkCreateEventV1,
205+
creatorInCreateEvent: true,
193206
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
194207
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
195208
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
@@ -210,6 +223,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
210223
checkKnockingAllowedFunc: disallowKnocking,
211224
checkRestrictedJoinAllowedFunc: disallowRestrictedJoins,
212225
checkCreateEvent: checkCreateEventV1,
226+
creatorInCreateEvent: true,
213227
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
214228
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
215229
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
@@ -230,6 +244,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
230244
checkKnockingAllowedFunc: checkKnocking,
231245
checkRestrictedJoinAllowedFunc: disallowRestrictedJoins,
232246
checkCreateEvent: checkCreateEventV1,
247+
creatorInCreateEvent: true,
233248
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
234249
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
235250
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
@@ -250,6 +265,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
250265
checkKnockingAllowedFunc: checkKnocking,
251266
checkRestrictedJoinAllowedFunc: allowRestrictedJoins,
252267
checkCreateEvent: checkCreateEventV1,
268+
creatorInCreateEvent: true,
253269
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
254270
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
255271
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
@@ -270,6 +286,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
270286
checkKnockingAllowedFunc: checkKnocking,
271287
checkRestrictedJoinAllowedFunc: allowRestrictedJoins,
272288
checkCreateEvent: checkCreateEventV1,
289+
creatorInCreateEvent: true,
273290
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
274291
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
275292
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
@@ -290,6 +307,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
290307
checkKnockingAllowedFunc: checkKnocking,
291308
checkRestrictedJoinAllowedFunc: allowRestrictedJoins,
292309
checkCreateEvent: checkCreateEventV1,
310+
creatorInCreateEvent: true,
293311
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
294312
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
295313
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
@@ -310,6 +328,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
310328
checkKnockingAllowedFunc: checkKnocking,
311329
checkRestrictedJoinAllowedFunc: allowRestrictedJoins,
312330
checkCreateEvent: checkCreateEventV2,
331+
strictEventByteLimits: true,
313332
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
314333
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
315334
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
@@ -330,6 +349,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
330349
checkKnockingAllowedFunc: checkKnocking,
331350
checkRestrictedJoinAllowedFunc: allowRestrictedJoins,
332351
checkCreateEvent: checkCreateEventV3,
352+
strictEventByteLimits: true,
333353
// v3 versions relax the room ID check as the room ID has no domain now.
334354
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV3,
335355
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV3,
@@ -353,6 +373,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
353373
checkKnockingAllowedFunc: checkKnocking,
354374
checkRestrictedJoinAllowedFunc: allowRestrictedJoins,
355375
checkCreateEvent: checkCreateEventV1,
376+
creatorInCreateEvent: true,
356377
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
357378
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
358379
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
@@ -373,6 +394,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
373394
checkKnockingAllowedFunc: checkKnocking,
374395
checkRestrictedJoinAllowedFunc: disallowRestrictedJoins,
375396
checkCreateEvent: checkCreateEventV1,
397+
creatorInCreateEvent: true,
376398
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
377399
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
378400
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
@@ -392,6 +414,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
392414
parsePowerLevelsFunc: parsePowerLevels,
393415
checkKnockingAllowedFunc: checkKnocking,
394416
checkCreateEvent: checkCreateEventV1,
417+
creatorInCreateEvent: true,
395418
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
396419
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
397420
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
@@ -436,6 +459,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
436459
checkKnockingAllowedFunc: checkKnocking,
437460
checkRestrictedJoinAllowedFunc: allowRestrictedJoins,
438461
checkCreateEvent: checkCreateEventV3,
462+
strictEventByteLimits: true,
439463
// v3 versions relax the room ID check as the room ID has no domain now.
440464
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV3,
441465
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV3,
@@ -529,6 +553,13 @@ type RoomVersionImpl struct {
529553
domainlessRoomID bool
530554
// creators have infinite PL
531555
privilegedCreators bool
556+
// the m.room.create content includes a "creator" field
557+
// (room versions 1–10). This is distinct from privilegedCreators, which
558+
// governs power-levels; this flag only controls whether the field
559+
// must be present in the create event content.
560+
creatorInCreateEvent bool
561+
// field length limits are in bytes rather than Unicode codepoints
562+
strictEventByteLimits bool
532563
// Events form two graphs, a state DAG and an event DAG.
533564
stateDAGs bool
534565
checkRestrictedJoin func(ctx context.Context, localServerName spec.ServerName, roomQuerier RestrictedRoomJoinQuerier, roomID spec.RoomID, senderID spec.SenderID, privilegedCreators bool) (string, error)
@@ -562,6 +593,14 @@ func (v RoomVersionImpl) PrivilegedCreators() bool {
562593
return v.privilegedCreators
563594
}
564595

596+
func (v RoomVersionImpl) CreatorInCreateEvent() bool {
597+
return v.creatorInCreateEvent
598+
}
599+
600+
func (v RoomVersionImpl) StrictEventByteLimits() bool {
601+
return v.strictEventByteLimits
602+
}
603+
565604
// StateResAlgorithm returns the state resolution for the given room version.
566605
func (v RoomVersionImpl) StateResAlgorithm() StateResAlgorithm {
567606
return v.stateResAlgorithm

0 commit comments

Comments
 (0)