1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
//! SceneBackend trait and supporting types for the JMAP Scene method
//! handlers.
//!
//! Read-side operations (`get_objects`, `get_state`, `get_changes`,
//! `query_objects`, `query_changes`) are defined on the
//! [`jmap_server::JmapBackend`] supertrait. This module adds the write
//! operations and the deployment facts the handlers consult.
//!
//! The crate root re-exports this module's public items and the
//! [`jmap_server`] backend types a downstream impl needs.
use jmap_server::{BackendSetError, JmapBackend, JmapObject, SetObject};
use jmap_scene_types::{
SceneAsset, SceneAvatar, SceneCapability, SceneInteractionEvent, SceneObject, SceneRegion,
};
/// A SceneRegion binding property, the reference
/// [`SceneBackend::region_binding`] is asked about
/// (draft-atwood-jmap-scene-00 §Creating a Region, §Updating a Region).
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum BindingProperty {
/// `chatId`, a Chat (`urn:ietf:params:jmap:chat`).
ChatId,
/// `spaceId`, a Space (`urn:ietf:params:jmap:chat`).
SpaceId,
/// `channelId`, a channel of a Space (`urn:ietf:params:jmap:chat`).
ChannelId,
/// `activeCallId`, a VTCCall (`urn:ietf:params:jmap:vtc`).
ActiveCallId,
}
impl BindingProperty {
/// The SceneRegion property name, e.g. `"activeCallId"`.
pub fn as_str(self) -> &'static str {
match self {
Self::ChatId => "chatId",
Self::SpaceId => "spaceId",
Self::ChannelId => "channelId",
Self::ActiveCallId => "activeCallId",
}
}
}
/// What [`SceneBackend::region_binding`] knows about the object a
/// SceneRegion binding property references.
///
/// `SceneRegion/set` maps it to the SetError the draft requires
/// (draft-atwood-jmap-scene-00 §Creating a Region, §Updating a Region).
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BindingTarget {
/// The object exists and the caller may bind it: for `activeCallId`,
/// the VTCCall is not `"ended"` and the caller is a participant in or
/// moderator of it, or an administrator.
Usable,
/// The object does not exist; for `activeCallId`, also a VTCCall in
/// state `"ended"`. `SceneRegion/set` returns `invalidProperties`
/// naming the property.
Missing,
/// The object exists but the caller cannot access it. For `chatId`,
/// `spaceId` and `channelId` this is `invalidProperties` naming the
/// property ("if the referenced object does not exist or the caller
/// cannot access it"); for `activeCallId` it is `forbidden` ("and
/// `forbidden` if the caller lacks access").
Inaccessible,
}
/// Storage backend for the JMAP Scene method handlers
/// (draft-atwood-jmap-scene-00).
///
/// # Permission enforcement (backend canonical)
///
/// Per the workspace AGENTS.md "Caller identity (foundation seam)" rule the
/// backend re-verifies every permission atomically with the mutation. The
/// handlers apply the draft's checks (media type, blob, size quota, the
/// owner-or-admin rule via [`Self::may_modify_asset`]) as defense in depth.
///
/// # Changes
///
/// Unlike `/get` and `/query`, [`JmapBackend::get_changes`] is not scoped to
/// the caller. Visibility filtering "does not change the JMAP state model:
/// each data type has one state string per account", and `/changes` reports
/// the account's changes (draft-atwood-jmap-scene-00 §Visibility Contract).
/// A `/changes` result may therefore name an id that `/get` then hides: "A
/// server MAY report an object hidden from the caller in `notFound` from
/// `/get`". Unlike draft-atwood-jmap-graph-00, Scene does not ask `/changes`
/// to omit what the caller may not read.
///
/// This trait is not object-safe by design (generic methods). Use
/// `Arc<impl SceneBackend>` when sharing across tasks.
pub trait SceneBackend: JmapBackend {
/// The account-level `urn:ietf:params:jmap:scene` capability object
/// (draft-atwood-jmap-scene-00 §Account-Level Capability Object) the
/// consumer advertises for `account_id` to this caller.
///
/// Every `SceneAsset/*` handler reads `supportsSceneAsset` from it and
/// returns `unknownMethod` when it is `false`; `SceneAsset/set` also
/// reads `supportedVisualTypes` and `maxAssetSizeBytes`. Return the value the Session object
/// carries; a different value makes the handler contradict the
/// advertised capability. `supportedVisualTypes` "MUST include at least
/// `\"model/gltf-binary\"`"; the handler accepts that type whether or
/// not it is listed.
fn scene_capability(
&self,
caller: &Self::CallerCtx,
account_id: &jmap_types::Id,
) -> impl std::future::Future<Output = Result<SceneCapability, Self::Error>> + Send;
/// The size in bytes of blob `blob_id`, or `None` if no such blob was
/// uploaded to `account_id` (RFC 8620 §6.1).
///
/// `SceneAsset/set` create stores the size as the asset's `size` and
/// refuses a missing blob with `invalidProperties` naming `blobId`
/// ("`blobId` does not reference a valid blob"). There is no default: a default would invent sizes or
/// refuse every create. Return `Err` for a transient storage failure,
/// never `Ok(None)`: the handler maps `Err` to `serverFail` so the
/// client retries.
fn blob_size(
&self,
caller: &Self::CallerCtx,
account_id: &jmap_types::Id,
blob_id: &jmap_types::Id,
) -> impl std::future::Future<Output = Result<Option<u64>, Self::Error>> + Send;
/// Create an object.
///
/// The handler has validated the create against
/// draft-atwood-jmap-scene-00 §SceneAsset/set and filled the server-set
/// properties other than `id`. The backend MUST, in one atomic step,
/// mint a ULID `id` ("A ULID assigned at creation"), call `build(&id)`
/// once for the object carrying it, and store that object.
///
/// For a `SceneAsset` the backend also enforces the deployment-defined
/// rules of §SetError Conditions atomically with the insert: refuse
/// with `overQuota` for "Account asset storage quota
/// exceeded", and with `forbidden` when the "Deployment restricts
/// shared-asset creation to administrators" and the caller is not one.
///
/// For a `SceneRegion` the backend refuses with `overQuota` when the
/// account already holds `maxRegionsPerAccount` regions ("The server
/// MUST return `overQuota` when `maxRegionsPerAccount` would be
/// exceeded"), counted atomically with the insert.
///
/// For a `SceneObject` the backend sets `ownerId` to the caller's
/// userId ("The userId of the user who created this object"; the
/// handler sends `null`) and refuses with `overQuota` when the object's
/// region already holds `maxObjectsPerRegion` objects ("The server MUST
/// return `overQuota` when `maxObjectsPerRegion` would be exceeded"),
/// counted atomically with the insert.
///
/// For a `SceneAvatar` (§Entering a Region) the handler has filled
/// `userId` from [`Self::caller_user_id`], `position`, `orientation`,
/// `joinedAt` (now) and `leftAt` (`null`). In one atomic step the
/// backend:
///
/// 1. refuses with `alreadyExists` and `existingId` naming the record
/// when the user already has an avatar in the region, present or
/// departed ("the server MUST NOT create a second record and MUST
/// return an `alreadyExists` SetError ... with `existingId` set to
/// the id of that record");
/// 2. refuses with `overQuota` when the region already holds
/// `maxAvatarsPerRegion` avatars with `leftAt` `null`;
/// 3. sets `leftAt` to the new `joinedAt` on the user's active avatar
/// in any other region ("the server SHOULD set `leftAt` on the
/// previous avatar before creating the new one");
/// 4. keeps each affected region's `activeAvatarCount` ("Number of
/// avatars currently present in the region") equal to its avatars
/// with `leftAt` `null`, advancing the SceneRegion state.
///
/// Returns the assigned id and the stored object. `create_id` is the
/// client's creation id. Error mapping, state-counter and change-log
/// rules are those of the canonical `jmap-mail-server` `create_object`:
/// the state advances only when the create commits.
fn create_object<O, F>(
&self,
caller: &Self::CallerCtx,
account_id: &jmap_types::Id,
create_id: &str,
build: F,
) -> impl std::future::Future<Output = Result<(jmap_types::Id, O), BackendSetError<Self::Error>>>
+ Send
where
O: SetObject + Send + Sync,
F: FnOnce(&jmap_types::Id) -> O + Send;
/// Apply an RFC 8620 §5.3 PatchObject to an existing object.
///
/// `Ok(Some(o))` echoes server-changed properties; `Ok(None)` means the
/// patch applied verbatim. Both MUST advance the state and record an
/// `updated` change. Unknown `id` is `notFound`; a malformed patch is
/// `invalidPatch`; a result that no longer decodes is
/// `invalidProperties`. Apply the whole patch or none of it.
///
/// For a `SceneAvatar` whose patch sets `leftAt` to a UTCDate, the
/// backend refuses with `invalidProperties` naming `leftAt` when the
/// stored `leftAt` is already non-null ("double-leave is invalid"), and
/// otherwise decrements the region's `activeAvatarCount` in the same
/// atomic step ("The server decrements the region's
/// `activeAvatarCount`"), advancing the SceneRegion state.
///
/// A patch that sets `leftAt` to `null` re-enters the region
/// (§Re-entering a Region); the handler has added `joinedAt` (now),
/// `position` and `orientation` (the region's spawn point). In the
/// same atomic step the backend refuses with `invalidProperties`
/// naming `leftAt` when the stored `leftAt` is `null`, then applies
/// steps 2 to 4 of [`Self::create_object`] for a `SceneAvatar`: the
/// `maxAvatarsPerRegion` `overQuota`, setting `leftAt` on the user's
/// active avatar in any other region, and the `activeAvatarCount`
/// update.
fn update_object<O: SetObject + Send + Sync>(
&self,
caller: &Self::CallerCtx,
account_id: &jmap_types::Id,
id: &jmap_types::Id,
patch: O::Patch,
) -> impl std::future::Future<Output = Result<Option<O>, BackendSetError<Self::Error>>> + Send;
/// Destroy an object by id. Unknown `id` is `notFound`; the state
/// advances only when the destroy commits. The handler has already
/// applied the permission check.
///
/// Destroying a `SceneRegion` "removes the SceneRegion and all
/// SceneObject and SceneAvatar records in it; `SceneObject/changes` and
/// `SceneAvatar/changes` report those records as destroyed"
/// (draft-atwood-jmap-scene-00 §Destroying a Region): in the same atomic
/// step the backend destroys every SceneObject and SceneAvatar whose
/// `regionId` is `id` and records each as a destroyed change of its
/// type. It does not end a VTCCall the
/// region's `activeCallId` references ("the server MUST NOT
/// automatically end the referenced VTCCall").
///
/// Destroying a `SceneObject` "removes the SceneObject and all its
/// children (objects whose `parentId` references this object,
/// recursively)": in the same atomic step the backend destroys every
/// descendant and records each as a destroyed SceneObject change.
fn destroy_object<O: SetObject + Send + Sync>(
&self,
caller: &Self::CallerCtx,
account_id: &jmap_types::Id,
id: &jmap_types::Id,
) -> impl std::future::Future<Output = Result<(), BackendSetError<Self::Error>>> + Send;
/// `true` if the caller may update or destroy `asset`: "Only the asset
/// owner or an admin may modify asset metadata"
/// (draft-atwood-jmap-scene-00 §SceneAsset/set Update Errors; Destroy
/// Errors use the "Same permission model as update").
///
/// `SceneAsset/set` returns `forbidden` for an update or destroy when
/// this is `false`.
///
/// # Default implementation
///
/// Returns `Ok(true)`: every caller may modify every asset. This is the
/// workspace's fail-open posture for permission hooks (bd:JMAP-bghk);
/// production backends override it.
fn may_modify_asset(
&self,
caller: &Self::CallerCtx,
account_id: &jmap_types::Id,
asset: &SceneAsset,
) -> impl std::future::Future<Output = Result<bool, Self::Error>> + Send {
let _ = (caller, account_id, asset);
async { Ok(true) }
}
/// `true` if the consumer advertises the capability `uri` for
/// `account_id`.
///
/// The SceneRegion binding properties "are present only when the
/// corresponding companion capability is advertised on the same
/// account": `chatId`, `spaceId` and `channelId` need
/// `urn:ietf:params:jmap:chat`, `activeCallId` needs
/// `urn:ietf:params:jmap:vtc`. `SceneRegion/set` refuses a non-null
/// binding without its capability, and `accessPolicy` `"space"`
/// without `urn:ietf:params:jmap:chat`, with `invalidProperties`; a
/// create stores `null` for the bindings whose capability is
/// advertised.
fn has_capability(
&self,
caller: &Self::CallerCtx,
account_id: &jmap_types::Id,
uri: &str,
) -> bool;
/// What the binding `property` set to `id` references, for the checks of
/// draft-atwood-jmap-scene-00 §Creating a Region ("the server MUST
/// verify that the referenced object exists and the caller has access
/// to it") and §Updating a Region (for `activeCallId`: "(a) the
/// referenced VTCCall exists, (b) its state is not `\"ended\"`, and (c)
/// the caller is a participant in or moderator of the referenced call,
/// or has deployment-defined administrative privileges").
///
/// `SceneRegion/set` calls this for each non-null binding a create
/// sets or an update patches, after the capability check. The Chat and
/// VTC lookups live in the binding crates; this crate depends on
/// RFC 8620 only.
///
/// # Default implementation
///
/// Returns `Ok(BindingTarget::Usable)`: every reference is accepted.
/// This is the workspace's fail-open posture for permission hooks
/// (bd:JMAP-bghk); a backend that advertises Chat or VTC overrides it.
fn region_binding(
&self,
caller: &Self::CallerCtx,
account_id: &jmap_types::Id,
property: BindingProperty,
id: &jmap_types::Id,
) -> impl std::future::Future<Output = Result<BindingTarget, Self::Error>> + Send {
let _ = (caller, account_id, property, id);
async { Ok(BindingTarget::Usable) }
}
/// `true` if `channel_id` "is a channel of the Space named by
/// `spaceId`" (draft-atwood-jmap-scene-00 §Updating a Region, the
/// binding checks).
///
/// `SceneRegion/set` calls this when a create or an update sets
/// `channelId` or `spaceId` and the region as it would be after the
/// write has both non-null, after [`Self::region_binding`] accepted
/// each. `false` fails the write with `invalidProperties` naming
/// `channelId`.
///
/// # Default implementation
///
/// Returns `Ok(true)` (fail-open, bd:JMAP-bghk); a backend that
/// advertises Chat overrides it.
fn channel_in_space(
&self,
caller: &Self::CallerCtx,
account_id: &jmap_types::Id,
channel_id: &jmap_types::Id,
space_id: &jmap_types::Id,
) -> impl std::future::Future<Output = Result<bool, Self::Error>> + Send {
let _ = (caller, account_id, channel_id, space_id);
async { Ok(true) }
}
/// `true` if the caller may update `region`: "Only the owner or an
/// admin may modify region properties" (draft-atwood-jmap-scene-00
/// §SceneRegion/set Update Errors).
///
/// # Default implementation
///
/// Returns `Ok(true)` (fail-open, bd:JMAP-bghk); production backends
/// override it.
fn may_update_region(
&self,
caller: &Self::CallerCtx,
account_id: &jmap_types::Id,
region: &SceneRegion,
) -> impl std::future::Future<Output = Result<bool, Self::Error>> + Send {
let _ = (caller, account_id, region);
async { Ok(true) }
}
/// `true` if the caller may destroy `region`: "Only the region owner
/// or an admin may destroy a region" (draft-atwood-jmap-scene-00
/// §SceneRegion/set Destroy Errors).
///
/// # Default implementation
///
/// Returns `Ok(true)` (fail-open, bd:JMAP-bghk); production backends
/// override it.
fn may_destroy_region(
&self,
caller: &Self::CallerCtx,
account_id: &jmap_types::Id,
region: &SceneRegion,
) -> impl std::future::Future<Output = Result<bool, Self::Error>> + Send {
let _ = (caller, account_id, region);
async { Ok(true) }
}
/// `true` if the caller may update or destroy `object`: "Only the
/// object's `ownerId`, the region owner, or a deployment-admin may
/// modify another user's object" (draft-atwood-jmap-scene-00
/// §SceneObject/set Update Errors; Destroy Errors use the "Same
/// permission model as update").
///
/// `SceneObject/set` returns `forbidden` for an update or destroy when
/// this is `false`.
///
/// # Default implementation
///
/// Returns `Ok(true)` (fail-open, bd:JMAP-bghk); production backends
/// override it.
fn may_modify_object(
&self,
caller: &Self::CallerCtx,
account_id: &jmap_types::Id,
object: &SceneObject,
) -> impl std::future::Future<Output = Result<bool, Self::Error>> + Send {
let _ = (caller, account_id, object);
async { Ok(true) }
}
/// The caller's userId: "The authenticated user identity string"
/// (draft-atwood-jmap-scene-00 §SceneAvatar `userId`).
///
/// `SceneAvatar/set` stores it as a created avatar's `userId` ("The
/// server sets `userId` from the authenticated identity") and compares
/// it with an updated avatar's `userId` ("Users MUST NOT update other
/// users' avatars"). There is no default: the handlers cannot know the
/// identity.
fn caller_user_id(
&self,
caller: &Self::CallerCtx,
account_id: &jmap_types::Id,
) -> impl std::future::Future<Output = Result<String, Self::Error>> + Send;
/// The `displayName` of a new avatar for `user_id` when the create
/// supplies none: "the server sets it from the user profile or
/// ChatContact when {{JMAP-CHAT}} is present".
///
/// # Default implementation
///
/// Returns `user_id`. A Chat binding crate or a backend with user
/// profiles overrides it.
fn avatar_display_name(
&self,
caller: &Self::CallerCtx,
account_id: &jmap_types::Id,
user_id: &str,
) -> impl std::future::Future<Output = Result<String, Self::Error>> + Send {
let _ = (caller, account_id);
let name = user_id.to_owned();
async { Ok(name) }
}
/// The reserved display names (draft-atwood-jmap-scene-00 §Avatar
/// Identity and Impersonation): "The server SHOULD maintain a list of
/// reserved display names that correspond to system roles or
/// administrative functions and MUST reject `SceneAvatar/set`
/// operations that attempt to use a reserved name with a `SetError` of
/// type `forbidden`."
///
/// `SceneAvatar/set` refuses a create or update whose client-supplied
/// `displayName` equals one of these names exactly with `forbidden`.
/// The comparison is case-sensitive, so list each spelling to reserve.
/// A name set by [`Self::avatar_display_name`] is not checked.
///
/// # Default implementation
///
/// Returns no names (fail-open, bd:JMAP-bghk); deployments supply
/// their list.
fn reserved_display_names(
&self,
caller: &Self::CallerCtx,
account_id: &jmap_types::Id,
) -> impl std::future::Future<Output = Result<Vec<String>, Self::Error>> + Send {
let _ = (caller, account_id);
async { Ok(Vec::new()) }
}
/// `true` unless the caller is barred from entering `region`, which
/// it already has access to: "User is banned or ejected with a
/// cooldown period still active" (draft-atwood-jmap-scene-00
/// §Create Errors). `SceneAvatar/set` create and an update that
/// re-enters a region return `forbidden` when this is `false`, since
/// "The user already knows the region exists". Access under the
/// region's `accessPolicy` is [`Self::may_access_region`], not this
/// hook: a create without it is `invalidProperties` naming
/// `regionId`, a re-entry `notFound`.
///
/// # Default implementation
///
/// Returns `Ok(true)` (fail-open, bd:JMAP-bghk); production backends
/// override it.
fn may_enter_region(
&self,
caller: &Self::CallerCtx,
account_id: &jmap_types::Id,
region: &SceneRegion,
) -> impl std::future::Future<Output = Result<bool, Self::Error>> + Send {
let _ = (caller, account_id, region);
async { Ok(true) }
}
/// `true` if the caller may eject `avatar`, another user's avatar:
/// "region owners and administrators may set `leftAt` on another
/// user's avatar to eject them" (draft-atwood-jmap-scene-00 §Update
/// Errors).
///
/// `SceneAvatar/set` calls this only for a patch of another user's
/// avatar that sets `leftAt` and touches nothing else ("An eject
/// update patches only `leftAt`", §Avatar Permissions); `false` is
/// `forbidden`.
///
/// # Default implementation
///
/// Returns `Ok(true)` (fail-open, bd:JMAP-bghk); production backends
/// override it.
fn may_eject_avatar(
&self,
caller: &Self::CallerCtx,
account_id: &jmap_types::Id,
avatar: &SceneAvatar,
) -> impl std::future::Future<Output = Result<bool, Self::Error>> + Send {
let _ = (caller, account_id, avatar);
async { Ok(true) }
}
/// `true` if the caller has access to region `region_id`
/// (draft-atwood-jmap-scene-00 §Region Access): "A user has access to a
/// region when its `accessPolicy` admits the user, when the user is the
/// region owner, when the user has deployment-defined administrative
/// privileges, or when the user has an active SceneAvatar in it."
/// `"invite"` admits "The users whose userIds are listed in
/// `invitedUserIds`", and "Servers MAY admit users to an `\"invite\"`
/// region by other mechanisms as well".
///
/// `SceneRegion/get`, `SceneObject/get` and `SceneAvatar/get` report a
/// region, object or avatar in a region without access as `notFound`:
/// "The server SHOULD treat a request from a user without access to a
/// region as if the region did not exist: `notFound` for
/// `SceneRegion/get`, `SceneObject/get`, and `SceneAvatar/get` ... and
/// no results from the region in `/query`" (draft-atwood-jmap-scene-00
/// at 29e9a41, L2606).
/// `SceneRegion/set`, `SceneObject/set` and `SceneAvatar/set` report an
/// update or destroy of such a record as `notFound` too, never
/// `forbidden`. A region that no longer exists
/// may be treated either way.
///
/// The handlers cannot filter a `/query` page they did not cut, so
/// `query_objects` should omit what `/get` would hide: "The server
/// SHOULD NOT include a SceneObject in a `SceneObject/get` response or
/// `SceneObject/query` result if the authenticated user does not have
/// access to the object's containing SceneRegion" (§Visibility
/// Contract, L2577). The same applies to SceneRegion and SceneAvatar
/// results (L2606).
///
/// `query_changes` is not filtered per caller: visibility filtering
/// "does not change the JMAP state model: each data type has one state
/// string per account ... and `/changes` and `/queryChanges` report
/// changes for the account" (L2587). An id it reports that the caller
/// may not see, `/get` reports in `notFound`.
///
/// # Default implementation
///
/// Returns `Ok(true)` (fail-open, bd:JMAP-bghk); production backends
/// override it.
fn may_access_region(
&self,
caller: &Self::CallerCtx,
account_id: &jmap_types::Id,
region_id: &jmap_types::Id,
) -> impl std::future::Future<Output = Result<bool, Self::Error>> + Send {
let _ = (caller, account_id, region_id);
async { Ok(true) }
}
/// `true` if `object` is in the caller's visibility set: "The server
/// SHOULD apply visibility filtering to limit the objects returned
/// based on the authenticated user's avatar position within the
/// region. The specific visibility algorithm is deployment-defined"
/// (draft-atwood-jmap-scene-00 §Visibility Contract).
///
/// Consulted only for objects in a region the caller may access
/// ([`Self::may_access_region`]). `SceneObject/get` reports an object
/// outside the set as `notFound`, and `SceneObject/set` refuses an
/// update or destroy of it with `notFound`: "The server SHOULD NOT
/// return `forbidden`, as that would confirm the object still exists"
/// (L2589). `query_objects` should omit such objects as well;
/// `query_changes` reports changes for the account (L2587).
///
/// # Default implementation
///
/// Returns `Ok(true)`: "A simple deployment MAY return all objects in
/// the region."
fn is_object_visible(
&self,
caller: &Self::CallerCtx,
account_id: &jmap_types::Id,
object: &SceneObject,
) -> impl std::future::Future<Output = Result<bool, Self::Error>> + Send {
let _ = (caller, account_id, object);
async { Ok(true) }
}
/// `true` if `user_id` is blocked on the caller's own contact list
/// (draft-atwood-jmap-scene-00 at 33702a5 §Blocked-Contact Spatial
/// Presence, L2672): "SceneAvatar records belonging to a blocked
/// ChatContact SHOULD be excluded from `SceneAvatar/get` responses and
/// `SceneAvatar/query` results delivered to the blocking user".
///
/// The list is the caller's, whatever account the request names: the
/// server "removes any SceneAvatar records whose `userId` corresponds
/// to a ChatContact with `blocked: true` on the requesting user's
/// contact list" (L2676). A request on a shared region names the
/// region's hosting account, which holds the host's contacts, not the
/// requester's, so the hook takes no account id; an implementation
/// resolves the caller's own account from `caller`.
///
/// Consulted only for avatars in a region the caller may access:
/// "Blocked-contact filtering is applied AFTER the visibility
/// filtering". `SceneAvatar/get` reports such an avatar exactly as a
/// missing one, in `notFound` ("The server SHOULD NOT return an error,
/// a filtered-result indicator, or any other signal", L2674);
/// `query_objects` should omit it as well, while `query_changes`
/// reports changes for the account (§Visibility Contract). The
/// handlers leave `activeAvatarCount` the true count, which deployments
/// "SHOULD prefer" (L2678).
///
/// [`crate::should_deliver`] asks this at delivery time with the
/// recipient as the caller, since suppression consults "the
/// recipient's ChatContact records" (draft-atwood-jmap-scene-wss-00 at
/// 33702a5, L793-795).
///
/// The Chat lookup (`ChatContact.blocked`) lives in the binding crate:
/// "Without `urn:ietf:params:jmap:chat`, there is no blocked-contact
/// list and this filtering does not apply."
///
/// # Default implementation
///
/// Returns `Ok(false)`: no one is blocked. This is the workspace's
/// fail-open posture for policy hooks (bd:JMAP-bghk).
fn is_user_blocked(
&self,
caller: &Self::CallerCtx,
user_id: &str,
) -> impl std::future::Future<Output = Result<bool, Self::Error>> + Send {
let _ = (caller, user_id);
async { Ok(false) }
}
/// `true` if the caller may see the SceneAvatar records of region
/// `region_id` (draft-atwood-jmap-scene-00 at 6bcd9d8, L2654): "When a
/// SceneRegion's `activeCallId` references a VTCCall with
/// `e2eeEnabled` set to `true`, the server SHOULD NOT expose the
/// region's SceneAvatar records to users who are not participants in
/// the bound VTCCall: for such users it SHOULD return `notFound` for
/// `SceneAvatar/get`, exclude the records from `SceneAvatar/query`, and
/// suppress `SceneAvatarEvent` ... delivery (`entered`, `left`, and
/// `ejected`)."
///
/// Consulted only for avatars in a region the caller may access
/// ([`Self::may_access_region`]). `SceneAvatar/get` reports the avatars
/// of a region answering `false` in `notFound`, and
/// [`crate::should_deliver`] drops their `SceneAvatarEvent`s;
/// `query_objects` should omit them as well, while `query_changes`
/// reports changes for the account (§Visibility Contract).
///
/// The VTC lookup (`VTCCall.e2eeEnabled` and the call's participants)
/// lives in the binding crate, `jmap-scene-vtc-server`.
///
/// # Default implementation
///
/// Returns `Ok(true)`: no region hides its avatars. This is the
/// workspace's fail-open posture for policy hooks (bd:JMAP-bghk); a
/// deployment without it exposes the call's participant presence, the
/// limitation the draft's SHOULD leaves to it.
fn may_see_region_avatars(
&self,
caller: &Self::CallerCtx,
account_id: &jmap_types::Id,
region_id: &jmap_types::Id,
) -> impl std::future::Future<Output = Result<bool, Self::Error>> + Send {
let _ = (caller, account_id, region_id);
async { Ok(true) }
}
/// Accept an interaction that passed the `SceneObject/interact`
/// checks, or refuse it for its rate (draft-atwood-jmap-scene-00
/// §SceneObject/interact).
///
/// `event` carries the interaction and the caller's userId from
/// [`Self::caller_user_id`]. `Ok(false)` means "The caller has exceeded
/// a deployment-defined interaction rate" and the handler reports
/// `rateLimit`; draft-atwood-jmap-scene-wss-00 §Rate Limiting suggests
/// "no more than five events per user per region per second".
/// `Ok(true)` accepts it: count it against the rate and, when the
/// WebSocket capability is supported, hand `event` to the transport,
/// which "delivers a `SceneInteractionEvent` carrying the interaction
/// and the caller's userId to the WebSocket subscribers of the region",
/// filtered per recipient by [`crate::should_deliver`]. Counting and
/// delivering in this one call keeps them atomic.
///
/// # Default implementation
///
/// Returns `Ok(true)` and delivers nothing: no rate limit (fail-open,
/// bd:JMAP-bghk) and no WebSocket transport.
fn accept_interaction(
&self,
caller: &Self::CallerCtx,
account_id: &jmap_types::Id,
event: &SceneInteractionEvent,
) -> impl std::future::Future<Output = Result<bool, Self::Error>> + Send {
let _ = (caller, account_id, event);
async { Ok(true) }
}
/// Per-backend capability probe: `true` if this backend supports the
/// JMAP object type `O` for `account_id`. Not called by the handlers;
/// consumers use it when assembling their Session capabilities
/// ("Deployments ... MAY omit support for SceneAsset methods").
fn supports_type<O: JmapObject>(
&self,
caller: &Self::CallerCtx,
account_id: &jmap_types::Id,
) -> bool;
}