Implement better fmt::Debug for pdu::Builder.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::{collections::BTreeMap, fmt};
|
||||||
|
|
||||||
use ruma::{
|
use ruma::{
|
||||||
MilliSecondsSinceUnixEpoch, OwnedEventId,
|
MilliSecondsSinceUnixEpoch, OwnedEventId,
|
||||||
@@ -10,7 +10,7 @@ use serde_json::value::{RawValue as RawJsonValue, to_raw_value};
|
|||||||
use super::StateKey;
|
use super::StateKey;
|
||||||
|
|
||||||
/// Build the start of a PDU in order to add it to the Database.
|
/// Build the start of a PDU in order to add it to the Database.
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct Builder {
|
pub struct Builder {
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub event_type: TimelineEventType,
|
pub event_type: TimelineEventType,
|
||||||
@@ -30,6 +30,19 @@ pub struct Builder {
|
|||||||
|
|
||||||
type Unsigned = BTreeMap<String, serde_json::Value>;
|
type Unsigned = BTreeMap<String, serde_json::Value>;
|
||||||
|
|
||||||
|
impl Default for Builder {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
event_type: "m.room.message".into(),
|
||||||
|
content: Box::<RawJsonValue>::default(),
|
||||||
|
unsigned: None,
|
||||||
|
state_key: None,
|
||||||
|
redacts: None,
|
||||||
|
timestamp: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Builder {
|
impl Builder {
|
||||||
pub fn state<S, T>(state_key: S, content: &T) -> Self
|
pub fn state<S, T>(state_key: S, content: &T) -> Self
|
||||||
where
|
where
|
||||||
@@ -58,15 +71,30 @@ impl Builder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Builder {
|
impl fmt::Debug for Builder {
|
||||||
fn default() -> Self {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
Self {
|
let mut d = f.debug_struct("Builder");
|
||||||
event_type: "m.room.message".into(),
|
|
||||||
content: Box::<RawJsonValue>::default(),
|
d.field("type", &self.event_type);
|
||||||
unsigned: None,
|
|
||||||
state_key: None,
|
if let Some(state_key) = self.state_key.as_ref() {
|
||||||
redacts: None,
|
d.field("state_key", state_key);
|
||||||
timestamp: None,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(redacts) = self.redacts.as_ref() {
|
||||||
|
d.field("redacts", redacts);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(timestamp) = self.timestamp.as_ref() {
|
||||||
|
d.field("ts", timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(unsigned) = self.unsigned.as_ref() {
|
||||||
|
d.field("unsigned", unsigned);
|
||||||
|
}
|
||||||
|
|
||||||
|
d.field("content", &self.content);
|
||||||
|
|
||||||
|
d.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,12 @@ use super::RoomMutexGuard;
|
|||||||
/// takes a roomid_mutex_state, meaning that only this function is able to
|
/// takes a roomid_mutex_state, meaning that only this function is able to
|
||||||
/// mutate the room state.
|
/// mutate the room state.
|
||||||
#[implement(super::Service)]
|
#[implement(super::Service)]
|
||||||
#[tracing::instrument(skip(self, state_lock), level = "debug", ret)]
|
#[tracing::instrument(
|
||||||
|
name = "build_and_append"
|
||||||
|
level = "debug",
|
||||||
|
skip(self, state_lock),
|
||||||
|
ret,
|
||||||
|
)]
|
||||||
pub async fn build_and_append_pdu(
|
pub async fn build_and_append_pdu(
|
||||||
&self,
|
&self,
|
||||||
pdu_builder: PduBuilder,
|
pdu_builder: PduBuilder,
|
||||||
|
|||||||
Reference in New Issue
Block a user