common: Use new owned ID types in non-event modules
This commit is contained in:
parent
d855ec33d6
commit
026ccd7e5b
@ -2,7 +2,10 @@
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use crate::serde::{Incoming, StringEnum};
|
||||
use crate::{
|
||||
serde::{Incoming, StringEnum},
|
||||
OwnedRoomAliasId, OwnedRoomId,
|
||||
};
|
||||
use js_int::UInt;
|
||||
use serde::{
|
||||
de::{Error, MapAccess, Visitor},
|
||||
@ -11,7 +14,7 @@ use serde::{
|
||||
};
|
||||
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.
|
||||
///
|
||||
@ -26,7 +29,7 @@ pub struct PublicRoomsChunk {
|
||||
feature = "compat",
|
||||
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.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@ -36,7 +39,7 @@ pub struct PublicRoomsChunk {
|
||||
pub num_joined_members: UInt,
|
||||
|
||||
/// The ID of the room.
|
||||
pub room_id: Box<RoomId>,
|
||||
pub room_id: OwnedRoomId,
|
||||
|
||||
/// The topic of the room, if any.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@ -77,7 +80,7 @@ pub struct PublicRoomsChunkInit {
|
||||
pub num_joined_members: UInt,
|
||||
|
||||
/// 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.
|
||||
pub world_readable: bool,
|
||||
|
@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
serde::{Base64, StringEnum},
|
||||
DeviceId, DeviceKeyId, EventEncryptionAlgorithm, PrivOwnedStr, UserId,
|
||||
EventEncryptionAlgorithm, OwnedDeviceId, OwnedDeviceKeyId, OwnedUserId, PrivOwnedStr,
|
||||
};
|
||||
|
||||
/// Identity keys for a device.
|
||||
@ -18,21 +18,21 @@ pub struct DeviceKeys {
|
||||
/// The ID of the user the device belongs to.
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// 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.
|
||||
pub algorithms: Vec<EventEncryptionAlgorithm>,
|
||||
|
||||
/// Public identity keys.
|
||||
pub keys: BTreeMap<Box<DeviceKeyId>, String>,
|
||||
pub keys: BTreeMap<OwnedDeviceKeyId, String>,
|
||||
|
||||
/// 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
|
||||
/// 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
|
||||
/// signatures.
|
||||
pub fn new(
|
||||
user_id: Box<UserId>,
|
||||
device_id: Box<DeviceId>,
|
||||
user_id: OwnedUserId,
|
||||
device_id: OwnedDeviceId,
|
||||
algorithms: Vec<EventEncryptionAlgorithm>,
|
||||
keys: BTreeMap<Box<DeviceKeyId>, String>,
|
||||
signatures: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>>,
|
||||
keys: BTreeMap<OwnedDeviceKeyId, String>,
|
||||
signatures: BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceKeyId, String>>,
|
||||
) -> Self {
|
||||
Self { user_id, device_id, algorithms, keys, signatures, unsigned: Default::default() }
|
||||
}
|
||||
@ -76,7 +76,7 @@ impl UnsignedDeviceInfo {
|
||||
}
|
||||
|
||||
/// 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
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@ -118,14 +118,14 @@ pub enum OneTimeKey {
|
||||
}
|
||||
|
||||
/// 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.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub struct CrossSigningKey {
|
||||
/// The ID of the user the key belongs to.
|
||||
pub user_id: Box<UserId>,
|
||||
pub user_id: OwnedUserId,
|
||||
|
||||
/// What the key is used for.
|
||||
pub usage: Vec<KeyUsage>,
|
||||
@ -133,7 +133,7 @@ pub struct CrossSigningKey {
|
||||
/// The public key.
|
||||
///
|
||||
/// The object must have exactly one property.
|
||||
pub keys: BTreeMap<Box<DeviceKeyId>, String>,
|
||||
pub keys: BTreeMap<OwnedDeviceKeyId, String>,
|
||||
|
||||
/// Signatures of the key.
|
||||
///
|
||||
@ -145,9 +145,9 @@ pub struct CrossSigningKey {
|
||||
impl CrossSigningKey {
|
||||
/// Creates a new `CrossSigningKey` with the given user ID, usage, keys and signatures.
|
||||
pub fn new(
|
||||
user_id: Box<UserId>,
|
||||
user_id: OwnedUserId,
|
||||
usage: Vec<KeyUsage>,
|
||||
keys: BTreeMap<Box<DeviceKeyId>, String>,
|
||||
keys: BTreeMap<OwnedDeviceKeyId, String>,
|
||||
signatures: CrossSigningKeySignatures,
|
||||
) -> Self {
|
||||
Self { user_id, usage, keys, signatures }
|
||||
|
@ -6,7 +6,9 @@ use std::collections::BTreeMap;
|
||||
|
||||
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.
|
||||
///
|
||||
@ -175,7 +177,7 @@ impl From<FieldTypeInit> for FieldType {
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub struct Location {
|
||||
/// 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.
|
||||
pub protocol: String,
|
||||
@ -187,7 +189,7 @@ pub struct Location {
|
||||
impl Location {
|
||||
/// Creates a new `Location` with the given alias, protocol and fields.
|
||||
pub fn new(
|
||||
alias: Box<RoomAliasId>,
|
||||
alias: OwnedRoomAliasId,
|
||||
protocol: String,
|
||||
fields: BTreeMap<String, String>,
|
||||
) -> Self {
|
||||
@ -200,7 +202,7 @@ impl Location {
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub struct 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.
|
||||
pub protocol: String,
|
||||
@ -211,7 +213,7 @@ pub struct User {
|
||||
|
||||
impl User {
|
||||
/// 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 }
|
||||
}
|
||||
}
|
||||
|
@ -12,14 +12,14 @@ use serde::{
|
||||
Deserialize, Deserializer, Serialize, Serializer,
|
||||
};
|
||||
|
||||
use crate::DeviceId;
|
||||
use crate::OwnedDeviceId;
|
||||
|
||||
/// Represents one or all of a user's devices.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[allow(clippy::exhaustive_enums)]
|
||||
pub enum DeviceIdOrAllDevices {
|
||||
/// Represents a device Id for one of a user's devices.
|
||||
DeviceId(Box<DeviceId>),
|
||||
DeviceId(OwnedDeviceId),
|
||||
|
||||
/// Represents all devices for a user.
|
||||
AllDevices,
|
||||
@ -34,8 +34,8 @@ impl Display for DeviceIdOrAllDevices {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Box<DeviceId>> for DeviceIdOrAllDevices {
|
||||
fn from(d: Box<DeviceId>) -> Self {
|
||||
impl From<OwnedDeviceId> for DeviceIdOrAllDevices {
|
||||
fn from(d: OwnedDeviceId) -> Self {
|
||||
DeviceIdOrAllDevices::DeviceId(d)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user