deserialize empty string to none for avatar_url
This commit is contained in:
parent
92ee92ad7e
commit
9cfa3b075c
@ -45,6 +45,10 @@ pub struct PublicRoomsChunk {
|
|||||||
|
|
||||||
/// The URL for the room's avatar, if one is set.
|
/// The URL for the room's avatar, if one is set.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "compat",
|
||||||
|
serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
|
||||||
|
)]
|
||||||
pub avatar_url: Option<String>,
|
pub avatar_url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +55,10 @@ pub struct RoomMember {
|
|||||||
|
|
||||||
/// The mxc avatar url of the user.
|
/// The mxc avatar url of the user.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "compat",
|
||||||
|
serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
|
||||||
|
)]
|
||||||
pub avatar_url: Option<String>,
|
pub avatar_url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,10 @@ ruma_api! {
|
|||||||
response: {
|
response: {
|
||||||
/// The user's avatar URL, if set.
|
/// The user's avatar URL, if set.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "compat",
|
||||||
|
serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
|
||||||
|
)]
|
||||||
pub avatar_url: Option<String>
|
pub avatar_url: Option<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,10 @@ ruma_api! {
|
|||||||
response: {
|
response: {
|
||||||
/// The user's avatar URL, if set.
|
/// The user's avatar URL, if set.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "compat",
|
||||||
|
serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
|
||||||
|
)]
|
||||||
pub avatar_url: Option<String>,
|
pub avatar_url: Option<String>,
|
||||||
|
|
||||||
/// The user's display name, if set.
|
/// The user's display name, if set.
|
||||||
|
@ -437,6 +437,10 @@ impl SearchResult {
|
|||||||
pub struct UserProfile {
|
pub struct UserProfile {
|
||||||
/// The user's avatar URL, if set.
|
/// The user's avatar URL, if set.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "compat",
|
||||||
|
serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
|
||||||
|
)]
|
||||||
pub avatar_url: Option<String>,
|
pub avatar_url: Option<String>,
|
||||||
|
|
||||||
/// The user's display name, if set.
|
/// The user's display name, if set.
|
||||||
|
@ -79,5 +79,9 @@ pub struct User {
|
|||||||
|
|
||||||
/// The avatar url, as an MXC, if one exists.
|
/// The avatar url, as an MXC, if one exists.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "compat",
|
||||||
|
serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
|
||||||
|
)]
|
||||||
pub avatar_url: Option<String>,
|
pub avatar_url: Option<String>,
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,10 @@ pub struct PublicRoomsChunk {
|
|||||||
|
|
||||||
/// The URL for the room's avatar, if one is set.
|
/// The URL for the room's avatar, if one is set.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "compat",
|
||||||
|
serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
|
||||||
|
)]
|
||||||
pub avatar_url: Option<String>,
|
pub avatar_url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,10 @@ pub struct PresenceEvent {
|
|||||||
pub struct PresenceEventContent {
|
pub struct PresenceEventContent {
|
||||||
/// The current avatar URL for this user.
|
/// The current avatar URL for this user.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "compat",
|
||||||
|
serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
|
||||||
|
)]
|
||||||
pub avatar_url: Option<String>,
|
pub avatar_url: Option<String>,
|
||||||
|
|
||||||
/// Whether or not the user is currently active.
|
/// Whether or not the user is currently active.
|
||||||
@ -119,5 +123,33 @@ mod tests {
|
|||||||
&& sender == "@example:localhost"
|
&& sender == "@example:localhost"
|
||||||
&& last_active_ago == uint!(2_478_593)
|
&& last_active_ago == uint!(2_478_593)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#[cfg(feature = "compat")]
|
||||||
|
assert_matches!(
|
||||||
|
from_json_value::<PresenceEvent>(json!({
|
||||||
|
"content": {
|
||||||
|
"avatar_url": "",
|
||||||
|
"currently_active": false,
|
||||||
|
"last_active_ago": 2_478_593,
|
||||||
|
"presence": "online",
|
||||||
|
"status_msg": "Making cupcakes"
|
||||||
|
},
|
||||||
|
"sender": "@example:localhost",
|
||||||
|
"type": "m.presence"
|
||||||
|
})).unwrap(),
|
||||||
|
PresenceEvent {
|
||||||
|
content: PresenceEventContent {
|
||||||
|
avatar_url: None,
|
||||||
|
currently_active: Some(false),
|
||||||
|
displayname: None,
|
||||||
|
last_active_ago: Some(last_active_ago),
|
||||||
|
presence: PresenceState::Online,
|
||||||
|
status_msg: Some(status_msg),
|
||||||
|
},
|
||||||
|
sender,
|
||||||
|
} if status_msg == "Making cupcakes"
|
||||||
|
&& sender == "@example:localhost"
|
||||||
|
&& last_active_ago == uint!(2_478_593)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,10 @@ pub type MemberEvent = StateEvent<MemberEventContent>;
|
|||||||
pub struct MemberEventContent {
|
pub struct MemberEventContent {
|
||||||
/// The avatar URL for this user, if any. This is added by the homeserver.
|
/// The avatar URL for this user, if any. This is added by the homeserver.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "compat",
|
||||||
|
serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
|
||||||
|
)]
|
||||||
pub avatar_url: Option<String>,
|
pub avatar_url: Option<String>,
|
||||||
|
|
||||||
/// The display name for this user, if any. This is added by the homeserver.
|
/// The display name for this user, if any. This is added by the homeserver.
|
||||||
@ -502,5 +506,80 @@ mod tests {
|
|||||||
}
|
}
|
||||||
&& token == "abc123"
|
&& token == "abc123"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#[cfg(feature = "compat")]
|
||||||
|
assert_matches!(
|
||||||
|
from_json_value::<Raw<StateEvent<MemberEventContent>>>(json!({
|
||||||
|
"type": "m.room.member",
|
||||||
|
"content": {
|
||||||
|
"membership": "join"
|
||||||
|
},
|
||||||
|
"event_id": "$143273582443PhrSn:example.org",
|
||||||
|
"origin_server_ts": 233,
|
||||||
|
"prev_content": {
|
||||||
|
"avatar_url": "",
|
||||||
|
"displayname": "Alice Margatroid",
|
||||||
|
"is_direct": true,
|
||||||
|
"membership": "invite",
|
||||||
|
"third_party_invite": {
|
||||||
|
"display_name": "alice",
|
||||||
|
"signed": {
|
||||||
|
"mxid": "@alice:example.org",
|
||||||
|
"signatures": {
|
||||||
|
"magic.forest": {
|
||||||
|
"ed25519:3": "foobar"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"token": "abc123"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"room_id": "!jEsUZKDJdhlrceRyVU:example.org",
|
||||||
|
"sender": "@alice:example.org",
|
||||||
|
"state_key": "@alice:example.org"
|
||||||
|
}))
|
||||||
|
.unwrap()
|
||||||
|
.deserialize()
|
||||||
|
.unwrap(),
|
||||||
|
StateEvent::<MemberEventContent> {
|
||||||
|
content: MemberEventContent {
|
||||||
|
avatar_url: None,
|
||||||
|
displayname: None,
|
||||||
|
is_direct: None,
|
||||||
|
membership: MembershipState::Join,
|
||||||
|
third_party_invite: None,
|
||||||
|
},
|
||||||
|
event_id,
|
||||||
|
origin_server_ts,
|
||||||
|
room_id,
|
||||||
|
sender,
|
||||||
|
state_key,
|
||||||
|
unsigned,
|
||||||
|
prev_content: Some(MemberEventContent {
|
||||||
|
avatar_url: None,
|
||||||
|
displayname: Some(displayname),
|
||||||
|
is_direct: Some(true),
|
||||||
|
membership: MembershipState::Invite,
|
||||||
|
third_party_invite: Some(ThirdPartyInvite {
|
||||||
|
display_name: third_party_displayname,
|
||||||
|
signed: SignedContent { mxid, signatures, token },
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
} if event_id == "$143273582443PhrSn:example.org"
|
||||||
|
&& origin_server_ts == UNIX_EPOCH + Duration::from_millis(233)
|
||||||
|
&& room_id == "!jEsUZKDJdhlrceRyVU:example.org"
|
||||||
|
&& sender == "@alice:example.org"
|
||||||
|
&& state_key == "@alice:example.org"
|
||||||
|
&& unsigned.is_empty()
|
||||||
|
&& displayname == "Alice Margatroid"
|
||||||
|
&& third_party_displayname == "alice"
|
||||||
|
&& mxid == "@alice:example.org"
|
||||||
|
&& signatures == btreemap! {
|
||||||
|
server_name!("magic.forest") => btreemap! {
|
||||||
|
server_signing_key_id!("ed25519:3") => "foobar".to_owned()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&& token == "abc123"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,10 @@ ruma_api! {
|
|||||||
|
|
||||||
/// Avatar URL for the user's avatar.
|
/// Avatar URL for the user's avatar.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "compat",
|
||||||
|
serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
|
||||||
|
)]
|
||||||
pub avatar_url: Option<String>,
|
pub avatar_url: Option<String>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user