pub struct Draft {
pub timeline_event_type: TimelineEventType,
pub content: Box<RawValue>,
pub state_key: Option<String>,
pub(crate) sender: OwnedUserId,
pub(crate) redacts: Option<OwnedEventId>,
}Expand description
State representing a draft event containing only user intent.
A draft is the initial state of an event,
Fields§
§timeline_event_type: TimelineEventTypeMatrix timeline event type.
content: Box<RawValue>Raw JSON event content.
state_key: Option<String>State key for state events (Some), or None for message-like
events. State events may carry an empty-string state key (e.g.
m.room.create).
sender: OwnedUserIdThe user that sent the event
redacts: Option<OwnedEventId>Redacted event id for redaction events
Implementations§
Source§impl Draft
impl Draft
Sourcepub fn new(
event_type: TimelineEventType,
content: Box<RawValue>,
state_key: Option<String>,
sender: OwnedUserId,
redacts: Option<OwnedEventId>,
) -> Result<Self, Error>
pub fn new( event_type: TimelineEventType, content: Box<RawValue>, state_key: Option<String>, sender: OwnedUserId, redacts: Option<OwnedEventId>, ) -> Result<Self, Error>
Sourcepub(crate) fn from_signed(
event_type: TimelineEventType,
content: Box<RawValue>,
state_key: Option<String>,
sender: OwnedUserId,
redacts: Option<OwnedEventId>,
) -> Result<Self, Error>
pub(crate) fn from_signed( event_type: TimelineEventType, content: Box<RawValue>, state_key: Option<String>, sender: OwnedUserId, redacts: Option<OwnedEventId>, ) -> Result<Self, Error>
Initializes a Draft from the content of a federation PDU, tolerating
redacted content.
Unlike Draft::new, empty ({}) message-like content is accepted
rather than rejected, since a redacted event may have had its content
stripped to {}. This is only appropriate for already-signed events
received over federation, never for client-originated content, which
must go through Draft::new.
This constructor lives on Draft rather than on Signed because it
runs while a PDU is being parsed into a Signed, before that value
exists.
§Errors
Returns a serde_json::Error if the content does not have the format
expected of the event_type.
Sourcefn build(
event_type: TimelineEventType,
content: Box<RawValue>,
state_key: Option<String>,
sender: OwnedUserId,
redacts: Option<OwnedEventId>,
allow_redacted_content: bool,
) -> Result<Self, Error>
fn build( event_type: TimelineEventType, content: Box<RawValue>, state_key: Option<String>, sender: OwnedUserId, redacts: Option<OwnedEventId>, allow_redacted_content: bool, ) -> Result<Self, Error>
Shared constructor validating content shape.
When allow_redacted_content is set, empty ({}) message-like content
is accepted instead of being validated, to allow loading redacted
events.
Sourcepub fn redact(&mut self, redacted_content: Box<RawValue>) -> Result<(), Error>
pub fn redact(&mut self, redacted_content: Box<RawValue>) -> Result<(), Error>
Initialize a new Draft state, assuming it has been redacted.
This function assumes that the event content is correct event content,
which has passed through the Draft::new, and subsequently the
redaction module. Therefore, no explicit verification is made
§Errors
Returns a serde_json::Error if, for a room-create event, the redacted
content cannot be parsed as m.room.create content.
Sourcepub(crate) fn content_to_map(&self) -> Map<String, Value>
pub(crate) fn content_to_map(&self) -> Map<String, Value>
Get the event content as a JSON object map.
§Panics
Panics if the content is not a valid JSON object.
crate::states::Draft::new guarantees that the content is valid, so
this is only reachable for events constructed bypassing that
constructor.