From 226dbca6e05407a863ccaf62ec98229c9a1fd64a Mon Sep 17 00:00:00 2001 From: Bob Bobs Date: Sat, 10 Feb 2024 16:33:17 -0700 Subject: [PATCH] fix(core/models): use IndexMap for reactions --- crates/core/database/src/util/bridge/v0.rs | 13 ++----------- crates/core/models/Cargo.toml | 2 +- crates/core/models/src/v0/messages.rs | 12 +++++------- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/crates/core/database/src/util/bridge/v0.rs b/crates/core/database/src/util/bridge/v0.rs index 6bc6880e..f436f402 100644 --- a/crates/core/database/src/util/bridge/v0.rs +++ b/crates/core/database/src/util/bridge/v0.rs @@ -341,11 +341,7 @@ impl From for Message { embeds: value.embeds, mentions: value.mentions, replies: value.replies, - reactions: value - .reactions - .into_iter() - .map(|(k, v)| (k, v.into_iter().collect())) - .collect(), + reactions: value.reactions, interactions: value.interactions.into(), masquerade: value.masquerade.map(|masq| masq.into()), } @@ -369,12 +365,7 @@ impl From for PartialMessage { embeds: value.embeds, mentions: value.mentions, replies: value.replies, - reactions: value.reactions.map(|reactions| { - reactions - .into_iter() - .map(|(k, v)| (k, v.into_iter().collect())) - .collect() - }), + reactions: value.reactions, interactions: value.interactions.map(|interactions| interactions.into()), masquerade: value.masquerade.map(|masq| masq.into()), } diff --git a/crates/core/models/Cargo.toml b/crates/core/models/Cargo.toml index ef843bb9..f64612a1 100644 --- a/crates/core/models/Cargo.toml +++ b/crates/core/models/Cargo.toml @@ -32,7 +32,7 @@ serde = { version = "1", features = ["derive"], optional = true } iso8601-timestamp = { version = "0.2.11", features = ["schema", "bson"] } # Spec Generation -schemars = { version = "0.8.8", optional = true } +schemars = { version = "0.8.8", optional = true, features = ["indexmap1"] } # Validation validator = { version = "0.16.0", optional = true, features = ["derive"] } diff --git a/crates/core/models/src/v0/messages.rs b/crates/core/models/src/v0/messages.rs index 90dc39fc..f97595f9 100644 --- a/crates/core/models/src/v0/messages.rs +++ b/crates/core/models/src/v0/messages.rs @@ -1,8 +1,6 @@ -use std::{ - collections::{HashMap, HashSet}, - time::SystemTime, -}; +use std::time::SystemTime; +use indexmap::{IndexMap, IndexSet}; use once_cell::sync::Lazy; use regex::Regex; use revolt_config::config; @@ -55,8 +53,8 @@ auto_derived_partial!( #[serde(skip_serializing_if = "Option::is_none")] pub replies: Option>, /// Hashmap of emoji IDs to array of user IDs - #[serde(skip_serializing_if = "HashMap::is_empty", default)] - pub reactions: HashMap>, + #[serde(skip_serializing_if = "IndexMap::is_empty", default)] + pub reactions: IndexMap>, /// Information about how this message should be interacted with #[serde(skip_serializing_if = "Interactions::is_default", default)] pub interactions: Interactions, @@ -119,7 +117,7 @@ auto_derived!( pub struct Interactions { /// Reactions which should always appear and be distinct #[serde(skip_serializing_if = "Option::is_none", default)] - pub reactions: Option>, + pub reactions: Option>, /// Whether reactions should be restricted to the given list /// /// Can only be set to true if reactions list is of at least length 1