refactor: jsonrpc rename change casing in names of jsonrpc structs/enums to comply with rust naming conventions. (#7324)

This commit is contained in:
Simon Laux
2025-10-21 13:49:16 +02:00
committed by GitHub
parent 9897ef2e9b
commit 347938a9f9
4 changed files with 24 additions and 24 deletions

View File

@@ -54,15 +54,15 @@ use types::events::Event;
use types::http::HttpResponse; use types::http::HttpResponse;
use types::message::{MessageData, MessageObject, MessageReadReceipt}; use types::message::{MessageData, MessageObject, MessageReadReceipt};
use types::provider_info::ProviderInfo; use types::provider_info::ProviderInfo;
use types::reactions::JSONRPCReactions; use types::reactions::JsonrpcReactions;
use types::webxdc::WebxdcMessageInfo; use types::webxdc::WebxdcMessageInfo;
use self::types::message::{MessageInfo, MessageLoadResult}; use self::types::message::{MessageInfo, MessageLoadResult};
use self::types::{ use self::types::{
chat::{BasicChat, JSONRPCChatVisibility, MuteDuration}, chat::{BasicChat, JsonrpcChatVisibility, MuteDuration},
location::JsonrpcLocation, location::JsonrpcLocation,
message::{ message::{
JSONRPCMessageListItem, MessageNotificationInfo, MessageSearchResult, MessageViewtype, JsonrpcMessageListItem, MessageNotificationInfo, MessageSearchResult, MessageViewtype,
}, },
}; };
use crate::api::types::chat_list::{get_chat_list_item_by_id, ChatListItemFetchResult}; use crate::api::types::chat_list::{get_chat_list_item_by_id, ChatListItemFetchResult};
@@ -1049,7 +1049,7 @@ impl CommandApi {
&self, &self,
account_id: u32, account_id: u32,
chat_id: u32, chat_id: u32,
visibility: JSONRPCChatVisibility, visibility: JsonrpcChatVisibility,
) -> Result<()> { ) -> Result<()> {
let ctx = self.get_context(account_id).await?; let ctx = self.get_context(account_id).await?;
@@ -1254,7 +1254,7 @@ impl CommandApi {
chat_id: u32, chat_id: u32,
info_only: bool, info_only: bool,
add_daymarker: bool, add_daymarker: bool,
) -> Result<Vec<JSONRPCMessageListItem>> { ) -> Result<Vec<JsonrpcMessageListItem>> {
let ctx = self.get_context(account_id).await?; let ctx = self.get_context(account_id).await?;
let msg = get_chat_msgs_ex( let msg = get_chat_msgs_ex(
&ctx, &ctx,
@@ -1268,7 +1268,7 @@ impl CommandApi {
Ok(msg Ok(msg
.iter() .iter()
.map(|chat_item| (*chat_item).into()) .map(|chat_item| (*chat_item).into())
.collect::<Vec<JSONRPCMessageListItem>>()) .collect::<Vec<JsonrpcMessageListItem>>())
} }
async fn get_message(&self, account_id: u32, msg_id: u32) -> Result<MessageObject> { async fn get_message(&self, account_id: u32, msg_id: u32) -> Result<MessageObject> {
@@ -2189,7 +2189,7 @@ impl CommandApi {
&self, &self,
account_id: u32, account_id: u32,
message_id: u32, message_id: u32,
) -> Result<Option<JSONRPCReactions>> { ) -> Result<Option<JsonrpcReactions>> {
let ctx = self.get_context(account_id).await?; let ctx = self.get_context(account_id).await?;
let reactions = get_msg_reactions(&ctx, MsgId::new(message_id)).await?; let reactions = get_msg_reactions(&ctx, MsgId::new(message_id)).await?;
if reactions.is_empty() { if reactions.is_empty() {

View File

@@ -252,18 +252,18 @@ impl MuteDuration {
#[derive(Clone, Serialize, Deserialize, TypeDef, schemars::JsonSchema)] #[derive(Clone, Serialize, Deserialize, TypeDef, schemars::JsonSchema)]
#[serde(rename = "ChatVisibility")] #[serde(rename = "ChatVisibility")]
pub enum JSONRPCChatVisibility { pub enum JsonrpcChatVisibility {
Normal, Normal,
Archived, Archived,
Pinned, Pinned,
} }
impl JSONRPCChatVisibility { impl JsonrpcChatVisibility {
pub fn into_core_type(self) -> ChatVisibility { pub fn into_core_type(self) -> ChatVisibility {
match self { match self {
JSONRPCChatVisibility::Normal => ChatVisibility::Normal, JsonrpcChatVisibility::Normal => ChatVisibility::Normal,
JSONRPCChatVisibility::Archived => ChatVisibility::Archived, JsonrpcChatVisibility::Archived => ChatVisibility::Archived,
JSONRPCChatVisibility::Pinned => ChatVisibility::Pinned, JsonrpcChatVisibility::Pinned => ChatVisibility::Pinned,
} }
} }
} }

View File

@@ -18,7 +18,7 @@ use typescript_type_def::TypeDef;
use super::color_int_to_hex_string; use super::color_int_to_hex_string;
use super::contact::ContactObject; use super::contact::ContactObject;
use super::reactions::JSONRPCReactions; use super::reactions::JsonrpcReactions;
#[derive(Serialize, TypeDef, schemars::JsonSchema)] #[derive(Serialize, TypeDef, schemars::JsonSchema)]
#[serde(rename_all = "camelCase", tag = "kind")] #[serde(rename_all = "camelCase", tag = "kind")]
@@ -102,7 +102,7 @@ pub struct MessageObject {
saved_message_id: Option<u32>, saved_message_id: Option<u32>,
reactions: Option<JSONRPCReactions>, reactions: Option<JsonrpcReactions>,
vcard_contact: Option<VcardContact>, vcard_contact: Option<VcardContact>,
} }
@@ -581,7 +581,7 @@ impl MessageSearchResult {
#[derive(Serialize, TypeDef, schemars::JsonSchema)] #[derive(Serialize, TypeDef, schemars::JsonSchema)]
#[serde(rename_all = "camelCase", rename = "MessageListItem", tag = "kind")] #[serde(rename_all = "camelCase", rename = "MessageListItem", tag = "kind")]
pub enum JSONRPCMessageListItem { pub enum JsonrpcMessageListItem {
Message { Message {
msg_id: u32, msg_id: u32,
}, },
@@ -594,13 +594,13 @@ pub enum JSONRPCMessageListItem {
}, },
} }
impl From<ChatItem> for JSONRPCMessageListItem { impl From<ChatItem> for JsonrpcMessageListItem {
fn from(item: ChatItem) -> Self { fn from(item: ChatItem) -> Self {
match item { match item {
ChatItem::Message { msg_id } => JSONRPCMessageListItem::Message { ChatItem::Message { msg_id } => JsonrpcMessageListItem::Message {
msg_id: msg_id.to_u32(), msg_id: msg_id.to_u32(),
}, },
ChatItem::DayMarker { timestamp } => JSONRPCMessageListItem::DayMarker { timestamp }, ChatItem::DayMarker { timestamp } => JsonrpcMessageListItem::DayMarker { timestamp },
} }
} }
} }

View File

@@ -8,7 +8,7 @@ use typescript_type_def::TypeDef;
/// A single reaction emoji. /// A single reaction emoji.
#[derive(Serialize, TypeDef, schemars::JsonSchema)] #[derive(Serialize, TypeDef, schemars::JsonSchema)]
#[serde(rename = "Reaction", rename_all = "camelCase")] #[serde(rename = "Reaction", rename_all = "camelCase")]
pub struct JSONRPCReaction { pub struct JsonrpcReaction {
/// Emoji. /// Emoji.
emoji: String, emoji: String,
@@ -22,14 +22,14 @@ pub struct JSONRPCReaction {
/// Structure representing all reactions to a particular message. /// Structure representing all reactions to a particular message.
#[derive(Serialize, TypeDef, schemars::JsonSchema)] #[derive(Serialize, TypeDef, schemars::JsonSchema)]
#[serde(rename = "Reactions", rename_all = "camelCase")] #[serde(rename = "Reactions", rename_all = "camelCase")]
pub struct JSONRPCReactions { pub struct JsonrpcReactions {
/// Map from a contact to it's reaction to message. /// Map from a contact to it's reaction to message.
reactions_by_contact: BTreeMap<u32, Vec<String>>, reactions_by_contact: BTreeMap<u32, Vec<String>>,
/// Unique reactions and their count, sorted in descending order. /// Unique reactions and their count, sorted in descending order.
reactions: Vec<JSONRPCReaction>, reactions: Vec<JsonrpcReaction>,
} }
impl From<Reactions> for JSONRPCReactions { impl From<Reactions> for JsonrpcReactions {
fn from(reactions: Reactions) -> Self { fn from(reactions: Reactions) -> Self {
let mut reactions_by_contact: BTreeMap<u32, Vec<String>> = BTreeMap::new(); let mut reactions_by_contact: BTreeMap<u32, Vec<String>> = BTreeMap::new();
@@ -56,7 +56,7 @@ impl From<Reactions> for JSONRPCReactions {
false false
}; };
let reaction = JSONRPCReaction { let reaction = JsonrpcReaction {
emoji, emoji,
count, count,
is_from_self, is_from_self,
@@ -64,7 +64,7 @@ impl From<Reactions> for JSONRPCReactions {
reactions_v.push(reaction) reactions_v.push(reaction)
} }
JSONRPCReactions { JsonrpcReactions {
reactions_by_contact, reactions_by_contact,
reactions: reactions_v, reactions: reactions_v,
} }