common: Use new owned ID types in non-event modules

This commit is contained in:
Jonas Platte 2022-04-06 18:37:43 +02:00 committed by Jonas Platte
parent d855ec33d6
commit 026ccd7e5b
4 changed files with 34 additions and 29 deletions

View File

@ -2,7 +2,10 @@
use std::fmt; use std::fmt;
use crate::serde::{Incoming, StringEnum}; use crate::{
serde::{Incoming, StringEnum},
OwnedRoomAliasId, OwnedRoomId,
};
use js_int::UInt; use js_int::UInt;
use serde::{ use serde::{
de::{Error, MapAccess, Visitor}, de::{Error, MapAccess, Visitor},
@ -11,7 +14,7 @@ use serde::{
}; };
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
use crate::{MxcUri, PrivOwnedStr, RoomAliasId, RoomId, RoomName}; use crate::{MxcUri, PrivOwnedStr, RoomName};
/// A chunk of a room list response, describing one room. /// A chunk of a room list response, describing one room.
/// ///
@ -26,7 +29,7 @@ pub struct PublicRoomsChunk {
feature = "compat", feature = "compat",
serde(default, deserialize_with = "crate::serde::empty_string_as_none") serde(default, deserialize_with = "crate::serde::empty_string_as_none")
)] )]
pub canonical_alias: Option<Box<RoomAliasId>>, pub canonical_alias: Option<OwnedRoomAliasId>,
/// The name of the room, if any. /// The name of the room, if any.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -36,7 +39,7 @@ pub struct PublicRoomsChunk {
pub num_joined_members: UInt, pub num_joined_members: UInt,
/// The ID of the room. /// The ID of the room.
pub room_id: Box<RoomId>, pub room_id: OwnedRoomId,
/// The topic of the room, if any. /// The topic of the room, if any.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -77,7 +80,7 @@ pub struct PublicRoomsChunkInit {
pub num_joined_members: UInt, pub num_joined_members: UInt,
/// The ID of the room. /// The ID of the room.
pub room_id: Box<RoomId>, pub room_id: OwnedRoomId,
/// Whether the room may be viewed by guest users without joining. /// Whether the room may be viewed by guest users without joining.
pub world_readable: bool, pub world_readable: bool,

View File

@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use crate::{ use crate::{
serde::{Base64, StringEnum}, serde::{Base64, StringEnum},
DeviceId, DeviceKeyId, EventEncryptionAlgorithm, PrivOwnedStr, UserId, EventEncryptionAlgorithm, OwnedDeviceId, OwnedDeviceKeyId, OwnedUserId, PrivOwnedStr,
}; };
/// Identity keys for a device. /// Identity keys for a device.
@ -18,21 +18,21 @@ pub struct DeviceKeys {
/// The ID of the user the device belongs to. /// The ID of the user the device belongs to.
/// ///
/// Must match the user ID used when logging in. /// Must match the user ID used when logging in.
pub user_id: Box<UserId>, pub user_id: OwnedUserId,
/// The ID of the device these keys belong to. /// The ID of the device these keys belong to.
/// ///
/// Must match the device ID used when logging in. /// Must match the device ID used when logging in.
pub device_id: Box<DeviceId>, pub device_id: OwnedDeviceId,
/// The encryption algorithms supported by this device. /// The encryption algorithms supported by this device.
pub algorithms: Vec<EventEncryptionAlgorithm>, pub algorithms: Vec<EventEncryptionAlgorithm>,
/// Public identity keys. /// Public identity keys.
pub keys: BTreeMap<Box<DeviceKeyId>, String>, pub keys: BTreeMap<OwnedDeviceKeyId, String>,
/// Signatures for the device key object. /// Signatures for the device key object.
pub signatures: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>>, pub signatures: BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceKeyId, String>>,
/// Additional data added to the device key information by intermediate servers, and /// Additional data added to the device key information by intermediate servers, and
/// not covered by the signatures. /// not covered by the signatures.
@ -44,11 +44,11 @@ impl DeviceKeys {
/// Creates a new `DeviceKeys` from the given user id, device id, algorithms, keys and /// Creates a new `DeviceKeys` from the given user id, device id, algorithms, keys and
/// signatures. /// signatures.
pub fn new( pub fn new(
user_id: Box<UserId>, user_id: OwnedUserId,
device_id: Box<DeviceId>, device_id: OwnedDeviceId,
algorithms: Vec<EventEncryptionAlgorithm>, algorithms: Vec<EventEncryptionAlgorithm>,
keys: BTreeMap<Box<DeviceKeyId>, String>, keys: BTreeMap<OwnedDeviceKeyId, String>,
signatures: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>>, signatures: BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceKeyId, String>>,
) -> Self { ) -> Self {
Self { user_id, device_id, algorithms, keys, signatures, unsigned: Default::default() } Self { user_id, device_id, algorithms, keys, signatures, unsigned: Default::default() }
} }
@ -76,7 +76,7 @@ impl UnsignedDeviceInfo {
} }
/// Signatures for a `SignedKey` object. /// Signatures for a `SignedKey` object.
pub type SignedKeySignatures = BTreeMap<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>>; pub type SignedKeySignatures = BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceKeyId, String>>;
/// A key for the SignedCurve25519 algorithm /// A key for the SignedCurve25519 algorithm
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
@ -118,14 +118,14 @@ pub enum OneTimeKey {
} }
/// Signatures for a `CrossSigningKey` object. /// Signatures for a `CrossSigningKey` object.
pub type CrossSigningKeySignatures = BTreeMap<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>>; pub type CrossSigningKeySignatures = BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceKeyId, String>>;
/// A cross signing key. /// A cross signing key.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct CrossSigningKey { pub struct CrossSigningKey {
/// The ID of the user the key belongs to. /// The ID of the user the key belongs to.
pub user_id: Box<UserId>, pub user_id: OwnedUserId,
/// What the key is used for. /// What the key is used for.
pub usage: Vec<KeyUsage>, pub usage: Vec<KeyUsage>,
@ -133,7 +133,7 @@ pub struct CrossSigningKey {
/// The public key. /// The public key.
/// ///
/// The object must have exactly one property. /// The object must have exactly one property.
pub keys: BTreeMap<Box<DeviceKeyId>, String>, pub keys: BTreeMap<OwnedDeviceKeyId, String>,
/// Signatures of the key. /// Signatures of the key.
/// ///
@ -145,9 +145,9 @@ pub struct CrossSigningKey {
impl CrossSigningKey { impl CrossSigningKey {
/// Creates a new `CrossSigningKey` with the given user ID, usage, keys and signatures. /// Creates a new `CrossSigningKey` with the given user ID, usage, keys and signatures.
pub fn new( pub fn new(
user_id: Box<UserId>, user_id: OwnedUserId,
usage: Vec<KeyUsage>, usage: Vec<KeyUsage>,
keys: BTreeMap<Box<DeviceKeyId>, String>, keys: BTreeMap<OwnedDeviceKeyId, String>,
signatures: CrossSigningKeySignatures, signatures: CrossSigningKeySignatures,
) -> Self { ) -> Self {
Self { user_id, usage, keys, signatures } Self { user_id, usage, keys, signatures }

View File

@ -6,7 +6,9 @@ use std::collections::BTreeMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{serde::StringEnum, MilliSecondsSinceUnixEpoch, PrivOwnedStr, RoomAliasId, UserId}; use crate::{
serde::StringEnum, MilliSecondsSinceUnixEpoch, OwnedRoomAliasId, OwnedUserId, PrivOwnedStr,
};
/// Metadata about a third party protocol. /// Metadata about a third party protocol.
/// ///
@ -175,7 +177,7 @@ impl From<FieldTypeInit> for FieldType {
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct Location { pub struct Location {
/// An alias for a matrix room. /// An alias for a matrix room.
pub alias: Box<RoomAliasId>, pub alias: OwnedRoomAliasId,
/// The protocol ID that the third party location is a part of. /// The protocol ID that the third party location is a part of.
pub protocol: String, pub protocol: String,
@ -187,7 +189,7 @@ pub struct Location {
impl Location { impl Location {
/// Creates a new `Location` with the given alias, protocol and fields. /// Creates a new `Location` with the given alias, protocol and fields.
pub fn new( pub fn new(
alias: Box<RoomAliasId>, alias: OwnedRoomAliasId,
protocol: String, protocol: String,
fields: BTreeMap<String, String>, fields: BTreeMap<String, String>,
) -> Self { ) -> Self {
@ -200,7 +202,7 @@ impl Location {
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct User { pub struct User {
/// A matrix user ID representing a third party user. /// A matrix user ID representing a third party user.
pub userid: Box<UserId>, pub userid: OwnedUserId,
/// The protocol ID that the third party user is a part of. /// The protocol ID that the third party user is a part of.
pub protocol: String, pub protocol: String,
@ -211,7 +213,7 @@ pub struct User {
impl User { impl User {
/// Creates a new `User` with the given userid, protocol and fields. /// Creates a new `User` with the given userid, protocol and fields.
pub fn new(userid: Box<UserId>, protocol: String, fields: BTreeMap<String, String>) -> Self { pub fn new(userid: OwnedUserId, protocol: String, fields: BTreeMap<String, String>) -> Self {
Self { userid, protocol, fields } Self { userid, protocol, fields }
} }
} }

View File

@ -12,14 +12,14 @@ use serde::{
Deserialize, Deserializer, Serialize, Serializer, Deserialize, Deserializer, Serialize, Serializer,
}; };
use crate::DeviceId; use crate::OwnedDeviceId;
/// Represents one or all of a user's devices. /// Represents one or all of a user's devices.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[allow(clippy::exhaustive_enums)] #[allow(clippy::exhaustive_enums)]
pub enum DeviceIdOrAllDevices { pub enum DeviceIdOrAllDevices {
/// Represents a device Id for one of a user's devices. /// Represents a device Id for one of a user's devices.
DeviceId(Box<DeviceId>), DeviceId(OwnedDeviceId),
/// Represents all devices for a user. /// Represents all devices for a user.
AllDevices, AllDevices,
@ -34,8 +34,8 @@ impl Display for DeviceIdOrAllDevices {
} }
} }
impl From<Box<DeviceId>> for DeviceIdOrAllDevices { impl From<OwnedDeviceId> for DeviceIdOrAllDevices {
fn from(d: Box<DeviceId>) -> Self { fn from(d: OwnedDeviceId) -> Self {
DeviceIdOrAllDevices::DeviceId(d) DeviceIdOrAllDevices::DeviceId(d)
} }
} }