diff --git a/backend/canisters/community/impl/src/lib.rs b/backend/canisters/community/impl/src/lib.rs index 6191904f57..738e3e9999 100644 --- a/backend/canisters/community/impl/src/lib.rs +++ b/backend/canisters/community/impl/src/lib.rs @@ -324,23 +324,23 @@ fn init_instruction_counts_log() -> InstructionCountsLog { #[derive(Serialize, Deserialize)] struct Data { - #[serde(deserialize_with = "deserialize_maybe_timestamped")] + #[serde(deserialize_with = "deserialize_to_timestamped")] is_public: Timestamped, - #[serde(deserialize_with = "deserialize_maybe_timestamped")] + #[serde(deserialize_with = "deserialize_to_timestamped")] name: Timestamped, - #[serde(deserialize_with = "deserialize_maybe_timestamped")] + #[serde(deserialize_with = "deserialize_to_timestamped")] description: Timestamped, - #[serde(deserialize_with = "deserialize_maybe_timestamped")] + #[serde(deserialize_with = "deserialize_to_timestamped")] rules: Timestamped, - #[serde(deserialize_with = "deserialize_optional_document")] + #[serde(deserialize_with = "deserialize_to_timestamped")] avatar: Timestamped>, - #[serde(deserialize_with = "deserialize_optional_document")] + #[serde(deserialize_with = "deserialize_to_timestamped")] banner: Timestamped>, - #[serde(deserialize_with = "deserialize_maybe_timestamped")] + #[serde(deserialize_with = "deserialize_to_timestamped")] permissions: Timestamped, - #[serde(deserialize_with = "deserialize_maybe_timestamped")] + #[serde(deserialize_with = "deserialize_to_timestamped")] gate_config: Timestamped>, - #[serde(deserialize_with = "deserialize_maybe_timestamped")] + #[serde(deserialize_with = "deserialize_to_timestamped")] primary_language: Timestamped, user_index_canister_id: CanisterId, local_user_index_canister_id: CanisterId, @@ -355,9 +355,9 @@ struct Data { channels: Channels, events: CommunityEvents, invited_users: InvitedUsers, - #[serde(deserialize_with = "deserialize_maybe_timestamped")] + #[serde(deserialize_with = "deserialize_to_timestamped")] invite_code: Timestamped>, - #[serde(deserialize_with = "deserialize_maybe_timestamped")] + #[serde(deserialize_with = "deserialize_to_timestamped")] invite_code_enabled: Timestamped, frozen: Timestamped>, timer_jobs: TimerJobs, @@ -386,27 +386,6 @@ struct Data { bot_permissions: BTreeMap, } -fn deserialize_maybe_timestamped<'de, D: Deserializer<'de>, T: Deserialize<'de>>(d: D) -> Result, D::Error> { - let maybe_timestamped = MaybeTimestamped::deserialize(d)?; - Ok(maybe_timestamped.into()) -} - -#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)] -#[serde(untagged)] -pub enum MaybeTimestamped { - Timestamped(Timestamped), - Value(T), -} - -impl From> for Timestamped { - fn from(value: MaybeTimestamped) -> Self { - match value { - MaybeTimestamped::Timestamped(ts) => ts, - MaybeTimestamped::Value(value) => Timestamped::new(value, now_millis()), - } - } -} - impl Data { #[allow(clippy::too_many_arguments)] fn new( @@ -966,7 +945,7 @@ pub struct AddUsersToChannelResult { pub users_limit_reached: Vec, } -fn deserialize_optional_document<'de, D: Deserializer<'de>>(d: D) -> Result>, D::Error> { - let document = Option::deserialize(d)?; - Ok(Timestamped::new(document, now_millis())) +fn deserialize_to_timestamped<'de, D: Deserializer<'de>, T: Deserialize<'de>>(d: D) -> Result, D::Error> { + let value = T::deserialize(d)?; + Ok(Timestamped::new(value, now_millis())) }