-
Notifications
You must be signed in to change notification settings - Fork 590
Expand file tree
/
Copy pathinternal_metadata.rs
More file actions
833 lines (739 loc) · 27.5 KB
/
Copy pathinternal_metadata.rs
File metadata and controls
833 lines (739 loc) · 27.5 KB
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
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
/*
* This file is licensed under the Affero General Public License (AGPL) version 3.
*
* Copyright (C) 2024 New Vector, Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* See the GNU Affero General Public License for more details:
* <https://www.gnu.org/licenses/agpl-3.0.html>.
*
* Originally licensed under the Apache License, Version 2.0:
* <http://www.apache.org/licenses/LICENSE-2.0>.
*
* [This file includes modifications made by New Vector Limited]
*
*/
//! Implements the internal metadata class attached to events.
//!
//! The internal metadata is a bit like a `TypedDict`, in that most of
//! it is stored as a JSON dict in the DB (the exceptions being `outlier`
//! and `stream_ordering` which have their own columns in the database).
//! Most events have zero, or only a few, of these keys
//! set. Therefore, since we care more about memory size than performance here,
//! we store these fields in a mapping.
//!
//! We want to store (most) of the fields as Rust objects, so we implement the
//! mapping by using a vec of enums. This is less efficient than using
//! attributes, but for small number of keys is actually faster than using a
//! hash or btree map.
use std::{
num::NonZeroI64,
ops::Deref,
sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard},
};
use anyhow::Context;
use log::warn;
use pyo3::{
exceptions::{PyAttributeError, PyRuntimeError},
pybacked::PyBackedStr,
pyclass, pymethods,
types::{PyAnyMethods, PyDict, PyDictMethods, PyString},
Bound, IntoPyObject, Py, PyAny, PyResult, Python,
};
use crate::UnwrapInfallible;
/// Definitions of the various fields of the internal metadata.
#[derive(Clone)]
enum EventInternalMetadataData {
OutOfBandMembership(bool),
SendOnBehalfOf(Box<str>),
RecheckRedaction(bool),
SoftFailed(bool),
ProactivelySend(bool),
PolicyServerSpammy(bool),
SpamCheckerSpammy(bool),
Redacted(bool),
TxnId(Box<str>),
DelayId(Box<str>),
TokenId(i64),
DeviceId(Box<str>),
CalculatedAuthEventIDs(Vec<String>), // MSC4242: State DAGs
}
impl EventInternalMetadataData {
/// Convert the field to its name and python object.
fn to_python_pair<'a>(&self, py: Python<'a>) -> (&'a Bound<'a, PyString>, Bound<'a, PyAny>) {
match self {
EventInternalMetadataData::OutOfBandMembership(o) => (
pyo3::intern!(py, "out_of_band_membership"),
o.into_pyobject(py)
.unwrap_infallible()
.to_owned()
.into_any(),
),
EventInternalMetadataData::SendOnBehalfOf(o) => (
pyo3::intern!(py, "send_on_behalf_of"),
o.into_pyobject(py).unwrap_infallible().into_any(),
),
EventInternalMetadataData::RecheckRedaction(o) => (
pyo3::intern!(py, "recheck_redaction"),
o.into_pyobject(py)
.unwrap_infallible()
.to_owned()
.into_any(),
),
EventInternalMetadataData::SoftFailed(o) => (
pyo3::intern!(py, "soft_failed"),
o.into_pyobject(py)
.unwrap_infallible()
.to_owned()
.into_any(),
),
EventInternalMetadataData::ProactivelySend(o) => (
pyo3::intern!(py, "proactively_send"),
o.into_pyobject(py)
.unwrap_infallible()
.to_owned()
.into_any(),
),
EventInternalMetadataData::PolicyServerSpammy(o) => (
pyo3::intern!(py, "policy_server_spammy"),
o.into_pyobject(py)
.unwrap_infallible()
.to_owned()
.into_any(),
),
EventInternalMetadataData::SpamCheckerSpammy(o) => (
pyo3::intern!(py, "spam_checker_spammy"),
o.into_pyobject(py)
.unwrap_infallible()
.to_owned()
.into_any(),
),
EventInternalMetadataData::Redacted(o) => (
pyo3::intern!(py, "redacted"),
o.into_pyobject(py)
.unwrap_infallible()
.to_owned()
.into_any(),
),
EventInternalMetadataData::TxnId(o) => (
pyo3::intern!(py, "txn_id"),
o.into_pyobject(py).unwrap_infallible().into_any(),
),
EventInternalMetadataData::DelayId(o) => (
pyo3::intern!(py, "delay_id"),
o.into_pyobject(py).unwrap_infallible().into_any(),
),
EventInternalMetadataData::TokenId(o) => (
pyo3::intern!(py, "token_id"),
o.into_pyobject(py).unwrap_infallible().into_any(),
),
EventInternalMetadataData::DeviceId(o) => (
pyo3::intern!(py, "device_id"),
o.into_pyobject(py).unwrap_infallible().into_any(),
),
EventInternalMetadataData::CalculatedAuthEventIDs(o) => (
pyo3::intern!(py, "calculated_auth_event_ids"),
o.into_pyobject(py).unwrap().into_any(),
),
}
}
/// Converts from python key/values to the field.
///
/// Returns `None` if the key is a valid but unrecognized string.
fn from_python_pair(
key: &Bound<'_, PyAny>,
value: &Bound<'_, PyAny>,
) -> PyResult<Option<Self>> {
let key_str: PyBackedStr = key.extract()?;
let e = match &*key_str {
"out_of_band_membership" => EventInternalMetadataData::OutOfBandMembership(
value
.extract()
.with_context(|| format!("'{key_str}' has invalid type"))?,
),
"send_on_behalf_of" => EventInternalMetadataData::SendOnBehalfOf(
value
.extract()
.map(String::into_boxed_str)
.with_context(|| format!("'{key_str}' has invalid type"))?,
),
"recheck_redaction" => EventInternalMetadataData::RecheckRedaction(
value
.extract()
.with_context(|| format!("'{key_str}' has invalid type"))?,
),
"soft_failed" => EventInternalMetadataData::SoftFailed(
value
.extract()
.with_context(|| format!("'{key_str}' has invalid type"))?,
),
"proactively_send" => EventInternalMetadataData::ProactivelySend(
value
.extract()
.with_context(|| format!("'{key_str}' has invalid type"))?,
),
"policy_server_spammy" => EventInternalMetadataData::PolicyServerSpammy(
value
.extract()
.with_context(|| format!("'{key_str}' has invalid type"))?,
),
"spam_checker_spammy" => EventInternalMetadataData::SpamCheckerSpammy(
value
.extract()
.with_context(|| format!("'{key_str}' has invalid type"))?,
),
"redacted" => EventInternalMetadataData::Redacted(
value
.extract()
.with_context(|| format!("'{key_str}' has invalid type"))?,
),
"txn_id" => EventInternalMetadataData::TxnId(
value
.extract()
.map(String::into_boxed_str)
.with_context(|| format!("'{key_str}' has invalid type"))?,
),
"delay_id" => EventInternalMetadataData::DelayId(
value
.extract()
.map(String::into_boxed_str)
.with_context(|| format!("'{key_str}' has invalid type"))?,
),
"token_id" => EventInternalMetadataData::TokenId(
value
.extract()
.with_context(|| format!("'{key_str}' has invalid type"))?,
),
"device_id" => EventInternalMetadataData::DeviceId(
value
.extract()
.map(String::into_boxed_str)
.with_context(|| format!("'{key_str}' has invalid type"))?,
),
"calculated_auth_event_ids" => EventInternalMetadataData::CalculatedAuthEventIDs(
value
.extract()
.with_context(|| format!("'{key_str}' has invalid type"))?,
),
_ => return Ok(None),
};
Ok(Some(e))
}
}
/// Helper macro to find the given field in internal metadata, returning None if
/// not found.
macro_rules! get_property_opt {
($self:expr, $name:ident) => {
$self.data.iter().find_map(|entry| {
if let EventInternalMetadataData::$name(data) = entry {
Some(data)
} else {
None
}
})
};
}
/// Helper macro to set the give field.
macro_rules! set_property {
($self:expr, $name:ident, $obj:expr) => {
for entry in &mut $self.data {
if let EventInternalMetadataData::$name(data) = entry {
*data = $obj;
return;
}
}
$self.data.push(EventInternalMetadataData::$name($obj))
};
}
/// The inner data for `EventInternalMetadata`, containing all fields and
/// business logic with pure Rust types.
#[derive(Clone)]
struct EventInternalMetadataInner {
/// The fields of internal metadata. This functions as a mapping.
data: Vec<EventInternalMetadataData>,
/// The stream ordering of this event. None, until it has been persisted.
pub stream_ordering: Option<NonZeroI64>,
pub instance_name: Option<String>,
/// The event ID of the redaction event, if this event has been redacted.
/// This is set dynamically at load time and is not persisted to the database.
pub redacted_by: Option<String>,
/// whether this event is an outlier (ie, whether we have the state at that
/// point in the DAG)
pub outlier: bool,
}
impl EventInternalMetadataInner {
pub fn is_outlier(&self) -> bool {
self.outlier
}
/// Whether this event is an out-of-band membership.
///
/// OOB memberships are a special case of outlier events: they are
/// membership events for federated rooms that we aren't full members of.
/// Examples include invites received over federation, and rejections for
/// such invites.
///
/// The concept of an OOB membership is needed because these events need to
/// be processed as if they're new regular events (e.g. updating membership
/// state in the database, relaying to clients via /sync, etc) despite being
/// outliers.
///
/// See also
/// https://element-hq.github.io/synapse/develop/development/room-dag-concepts.html#out-of-band-membership-events.
///
/// (Added in synapse 0.99.0, so may be unreliable for events received
/// before that)
pub fn is_out_of_band_membership(&self) -> bool {
get_property_opt!(self, OutOfBandMembership)
.copied()
.unwrap_or(false)
}
/// Whether this server should send the event on behalf of another server.
/// This is used by the federation "send_join" API to forward the initial
/// join event for a server in the room.
///
/// returns a str with the name of the server this event is sent on behalf
/// of.
pub fn get_send_on_behalf_of(&self) -> Option<&str> {
get_property_opt!(self, SendOnBehalfOf).map(|a| a.deref())
}
/// Whether the redaction event needs to be rechecked when fetching
/// from the database.
///
/// Starting in room v3 redaction events are accepted up front, and later
/// checked to see if the redacter and redactee's domains match.
///
/// If the sender of the redaction event is allowed to redact any event
/// due to auth rules, then this will always return false.
pub fn need_to_check_redaction(&self) -> bool {
get_property_opt!(self, RecheckRedaction)
.copied()
.unwrap_or(false)
}
/// Whether the event has been soft failed.
///
/// Soft failed events should be handled as usual, except:
/// 1. They should not go down sync or event streams, or generally sent to
/// clients.
/// 2. They should not be added to the forward extremities (and therefore
/// not to current state).
pub fn is_soft_failed(&self) -> bool {
get_property_opt!(self, SoftFailed)
.copied()
.unwrap_or(false)
}
/// Whether the event, if ours, should be sent to other clients and servers.
///
/// This is used for sending dummy events internally. Servers and clients
/// can still explicitly fetch the event.
pub fn should_proactively_send(&self) -> bool {
get_property_opt!(self, ProactivelySend)
.copied()
.unwrap_or(true)
}
/// Whether the event has been redacted.
///
/// This is used for efficiently checking whether an event has been marked
/// as redacted without needing to make another database call.
pub fn is_redacted(&self) -> bool {
get_property_opt!(self, Redacted).copied().unwrap_or(false)
}
/// Whether this event can trigger a push notification
pub fn is_notifiable(&self) -> bool {
!self.outlier || self.is_out_of_band_membership()
}
pub fn get_out_of_band_membership(&self) -> Option<bool> {
get_property_opt!(self, OutOfBandMembership).copied()
}
pub fn get_recheck_redaction(&self) -> Option<bool> {
get_property_opt!(self, RecheckRedaction).copied()
}
pub fn get_soft_failed(&self) -> Option<bool> {
get_property_opt!(self, SoftFailed).copied()
}
pub fn get_proactively_send(&self) -> Option<bool> {
get_property_opt!(self, ProactivelySend).copied()
}
pub fn get_policy_server_spammy(&self) -> bool {
get_property_opt!(self, PolicyServerSpammy)
.copied()
.unwrap_or(false)
}
pub fn get_redacted(&self) -> Option<bool> {
get_property_opt!(self, Redacted).copied()
}
pub fn get_txn_id(&self) -> Option<&str> {
get_property_opt!(self, TxnId).map(|s| s.deref())
}
pub fn get_delay_id(&self) -> Option<&str> {
get_property_opt!(self, DelayId).map(|s| s.deref())
}
pub fn get_calculated_auth_event_ids(&self) -> Option<&Vec<String>> {
get_property_opt!(self, CalculatedAuthEventIDs)
}
pub fn get_token_id(&self) -> Option<i64> {
get_property_opt!(self, TokenId).copied()
}
pub fn get_device_id(&self) -> Option<&str> {
get_property_opt!(self, DeviceId).map(|s| s.deref())
}
pub fn set_out_of_band_membership(&mut self, obj: bool) {
set_property!(self, OutOfBandMembership, obj);
}
pub fn set_send_on_behalf_of(&mut self, obj: String) {
set_property!(self, SendOnBehalfOf, obj.into_boxed_str());
}
pub fn set_recheck_redaction(&mut self, obj: bool) {
set_property!(self, RecheckRedaction, obj);
}
pub fn set_soft_failed(&mut self, obj: bool) {
set_property!(self, SoftFailed, obj);
}
pub fn set_proactively_send(&mut self, obj: bool) {
set_property!(self, ProactivelySend, obj);
}
pub fn set_policy_server_spammy(&mut self, obj: bool) {
set_property!(self, PolicyServerSpammy, obj);
}
fn get_spam_checker_spammy(&self) -> bool {
get_property_opt!(self, SpamCheckerSpammy)
.copied()
.unwrap_or(false)
}
fn set_spam_checker_spammy(&mut self, obj: bool) {
set_property!(self, SpamCheckerSpammy, obj);
}
pub fn set_redacted(&mut self, obj: bool) {
set_property!(self, Redacted, obj);
}
pub fn set_txn_id(&mut self, obj: String) {
set_property!(self, TxnId, obj.into_boxed_str());
}
pub fn set_delay_id(&mut self, obj: String) {
set_property!(self, DelayId, obj.into_boxed_str());
}
pub fn set_token_id(&mut self, obj: i64) {
set_property!(self, TokenId, obj);
}
pub fn set_device_id(&mut self, obj: String) {
set_property!(self, DeviceId, obj.into_boxed_str());
}
pub fn set_calculated_auth_event_ids(&mut self, obj: Vec<String>) {
set_property!(self, CalculatedAuthEventIDs, obj);
}
}
#[pyclass(frozen, skip_from_py_object)]
#[derive(Clone)]
pub struct EventInternalMetadata {
inner: Arc<RwLock<EventInternalMetadataInner>>,
}
impl EventInternalMetadata {
fn read_inner(&self) -> PyResult<RwLockReadGuard<'_, EventInternalMetadataInner>> {
self.inner
.read()
.map_err(|_| PyRuntimeError::new_err("EventInternalMetadata lock poisoned"))
}
/// Get a write lock on the inner data.
///
/// Note that callers should be careful not to panic while holding the write
/// lock, as this will poison the lock.q
fn write_inner(&self) -> PyResult<RwLockWriteGuard<'_, EventInternalMetadataInner>> {
self.inner
.write()
.map_err(|_| PyRuntimeError::new_err("EventInternalMetadata lock poisoned"))
}
/// The event ID of the redaction event, if this event has been redacted.
pub fn redacted_by(&self) -> PyResult<Option<String>> {
Ok(self.read_inner()?.redacted_by.clone())
}
/// The transaction ID, if set when the event was created.
///
/// The transaction ID comes from the `txn_id` path parameter of the
/// client-server API request used to send the event.
pub fn txn_id(&self) -> PyResult<Option<String>> {
Ok(self.read_inner()?.get_txn_id().map(|s| s.to_owned()))
}
/// The device ID of the sender, if set.
pub fn device_id(&self) -> PyResult<Option<String>> {
Ok(self.read_inner()?.get_device_id().map(|s| s.to_owned()))
}
/// The access token ID of the sender, if set.
pub fn token_id(&self) -> PyResult<Option<i64>> {
Ok(self.read_inner()?.get_token_id())
}
/// The delay ID, set only if the event was a delayed event.
pub fn delay_id(&self) -> PyResult<Option<String>> {
Ok(self.read_inner()?.get_delay_id().map(|s| s.to_owned()))
}
/// Whether the event has been soft failed.
pub fn soft_failed(&self) -> PyResult<bool> {
Ok(self.read_inner()?.is_soft_failed())
}
/// Whether the policy server marked this event as spammy.
pub fn policy_server_spammy(&self) -> PyResult<bool> {
Ok(self.read_inner()?.get_policy_server_spammy())
}
}
/// Helper to convert `None` to an `AttributeError` for a property getter.
fn attr_err<T>(val: Option<T>, name: &str) -> PyResult<T> {
val.ok_or_else(|| {
PyAttributeError::new_err(format!("'EventInternalMetadata' has no attribute '{name}'",))
})
}
#[pymethods]
impl EventInternalMetadata {
#[new]
pub fn new(dict: &Bound<'_, PyDict>) -> PyResult<Self> {
let mut data = Vec::with_capacity(dict.len());
for (key, value) in dict.iter() {
match EventInternalMetadataData::from_python_pair(&key, &value) {
Ok(Some(entry)) => data.push(entry),
Ok(None) => {}
Err(err) => {
warn!("Ignoring internal metadata field '{key}', as failed to convert to Rust due to {err}")
}
}
}
data.shrink_to_fit();
Ok(EventInternalMetadata {
inner: Arc::new(RwLock::new(EventInternalMetadataInner {
data,
stream_ordering: None,
instance_name: None,
redacted_by: None,
outlier: false,
})),
})
}
/// Create a deep copy of this `EventInternalMetadata` to allow modification
/// without affecting other references to the same metadata. This is needed
/// when we clone an event.
pub fn deep_copy(&self) -> PyResult<Self> {
let guard = self.read_inner()?;
Ok(EventInternalMetadata {
inner: Arc::new(RwLock::new(guard.clone())),
})
}
/// Get a dict holding the data stored in the `internal_metadata` column in
/// the database.
///
/// Note that `outlier` and `stream_ordering` are stored in separate columns
/// so are not returned here.
fn get_dict(&self, py: Python<'_>) -> PyResult<Py<PyAny>> {
let guard = self.read_inner()?;
let dict = PyDict::new(py);
for entry in &guard.data {
let (key, value) = entry.to_python_pair(py);
dict.set_item(key, value)?;
}
Ok(dict.into())
}
pub fn is_outlier(&self) -> PyResult<bool> {
Ok(self.read_inner()?.is_outlier())
}
fn is_out_of_band_membership(&self) -> PyResult<bool> {
Ok(self.read_inner()?.is_out_of_band_membership())
}
fn get_send_on_behalf_of(&self) -> PyResult<Option<String>> {
Ok(self
.read_inner()?
.get_send_on_behalf_of()
.map(|s| s.to_owned()))
}
fn need_to_check_redaction(&self) -> PyResult<bool> {
Ok(self.read_inner()?.need_to_check_redaction())
}
fn is_soft_failed(&self) -> PyResult<bool> {
Ok(self.read_inner()?.is_soft_failed())
}
fn should_proactively_send(&self) -> PyResult<bool> {
Ok(self.read_inner()?.should_proactively_send())
}
fn is_redacted(&self) -> PyResult<bool> {
Ok(self.read_inner()?.is_redacted())
}
fn is_notifiable(&self) -> PyResult<bool> {
Ok(self.read_inner()?.is_notifiable())
}
#[getter]
fn get_stream_ordering(&self) -> PyResult<Option<NonZeroI64>> {
Ok(self.read_inner()?.stream_ordering)
}
#[setter]
fn set_stream_ordering(&self, val: Option<NonZeroI64>) -> PyResult<()> {
self.write_inner()?.stream_ordering = val;
Ok(())
}
#[getter]
fn get_instance_name(&self) -> PyResult<Option<String>> {
Ok(self.read_inner()?.instance_name.clone())
}
#[setter]
fn set_instance_name(&self, val: Option<String>) -> PyResult<()> {
self.write_inner()?.instance_name = val;
Ok(())
}
#[getter]
fn get_redacted_by(&self) -> PyResult<Option<String>> {
Ok(self.read_inner()?.redacted_by.clone())
}
#[setter]
fn set_redacted_by(&self, val: Option<String>) -> PyResult<()> {
self.write_inner()?.redacted_by = val;
Ok(())
}
#[getter]
fn get_outlier(&self) -> PyResult<bool> {
Ok(self.read_inner()?.outlier)
}
#[setter]
fn set_outlier(&self, val: bool) -> PyResult<()> {
self.write_inner()?.outlier = val;
Ok(())
}
#[getter]
fn get_out_of_band_membership(&self) -> PyResult<bool> {
attr_err(
self.read_inner()?.get_out_of_band_membership(),
"out_of_band_membership",
)
}
#[setter]
fn set_out_of_band_membership(&self, obj: bool) -> PyResult<()> {
self.write_inner()?.set_out_of_band_membership(obj);
Ok(())
}
#[getter(send_on_behalf_of)]
fn getter_send_on_behalf_of(&self) -> PyResult<String> {
let guard = self.read_inner()?;
attr_err(
guard.get_send_on_behalf_of().map(|s| s.to_owned()),
"send_on_behalf_of",
)
}
#[setter]
fn set_send_on_behalf_of(&self, obj: String) -> PyResult<()> {
self.write_inner()?.set_send_on_behalf_of(obj);
Ok(())
}
#[getter]
fn get_recheck_redaction(&self) -> PyResult<bool> {
attr_err(
self.read_inner()?.get_recheck_redaction(),
"recheck_redaction",
)
}
#[setter]
fn set_recheck_redaction(&self, obj: bool) -> PyResult<()> {
self.write_inner()?.set_recheck_redaction(obj);
Ok(())
}
#[getter]
fn get_soft_failed(&self) -> PyResult<bool> {
attr_err(self.read_inner()?.get_soft_failed(), "soft_failed")
}
#[setter]
fn set_soft_failed(&self, obj: bool) -> PyResult<()> {
self.write_inner()?.set_soft_failed(obj);
Ok(())
}
#[getter]
fn get_proactively_send(&self) -> PyResult<bool> {
attr_err(
self.read_inner()?.get_proactively_send(),
"proactively_send",
)
}
#[setter]
fn set_proactively_send(&self, obj: bool) -> PyResult<()> {
self.write_inner()?.set_proactively_send(obj);
Ok(())
}
#[getter]
fn get_policy_server_spammy(&self) -> PyResult<bool> {
Ok(self.read_inner()?.get_policy_server_spammy())
}
#[setter]
fn set_policy_server_spammy(&self, obj: bool) -> PyResult<()> {
self.write_inner()?.set_policy_server_spammy(obj);
Ok(())
}
#[getter]
fn get_spam_checker_spammy(&self) -> PyResult<bool> {
Ok(self.read_inner()?.get_spam_checker_spammy())
}
#[setter]
fn set_spam_checker_spammy(&self, obj: bool) -> PyResult<()> {
self.write_inner()?.set_spam_checker_spammy(obj);
Ok(())
}
#[getter]
fn get_redacted(&self) -> PyResult<bool> {
attr_err(self.read_inner()?.get_redacted(), "redacted")
}
#[setter]
pub fn set_redacted(&self, obj: bool) -> PyResult<()> {
self.write_inner()?.set_redacted(obj);
Ok(())
}
/// The transaction ID, if it was set when the event was created.
#[getter]
fn get_txn_id(&self) -> PyResult<String> {
let guard = self.read_inner()?;
attr_err(guard.get_txn_id().map(|s| s.to_owned()), "txn_id")
}
#[setter]
fn set_txn_id(&self, obj: String) -> PyResult<()> {
self.write_inner()?.set_txn_id(obj);
Ok(())
}
/// The calculated auth event IDs, if it was set when the event was created.
#[getter]
pub fn get_calculated_auth_event_ids(&self) -> PyResult<Vec<String>> {
let guard = self.read_inner()?;
attr_err(
guard.get_calculated_auth_event_ids().cloned(),
"calculated_auth_event_ids",
)
}
#[setter]
fn set_calculated_auth_event_ids(&self, obj: Vec<String>) -> PyResult<()> {
self.write_inner()?.set_calculated_auth_event_ids(obj);
Ok(())
}
/// The delay ID, set only if the event was a delayed event.
#[getter]
fn get_delay_id(&self) -> PyResult<String> {
let guard = self.read_inner()?;
attr_err(guard.get_delay_id().map(|s| s.to_owned()), "delay_id")
}
#[setter]
fn set_delay_id(&self, obj: String) -> PyResult<()> {
self.write_inner()?.set_delay_id(obj);
Ok(())
}
/// The access token ID of the user who sent this event, if any.
#[getter]
fn get_token_id(&self) -> PyResult<i64> {
attr_err(self.read_inner()?.get_token_id(), "token_id")
}
#[setter]
fn set_token_id(&self, obj: i64) -> PyResult<()> {
self.write_inner()?.set_token_id(obj);
Ok(())
}
/// The device ID of the user who sent this event, if any.
#[getter]
fn get_device_id(&self) -> PyResult<String> {
let guard = self.read_inner()?;
attr_err(guard.get_device_id().map(|s| s.to_owned()), "device_id")
}
#[setter]
fn set_device_id(&self, obj: String) -> PyResult<()> {
self.write_inner()?.set_device_id(obj);
Ok(())
}
}