From 4b31fb4ec7e6e459dc45ec0afb6490df8191c59c Mon Sep 17 00:00:00 2001 From: Flori Weber Date: Thu, 22 Jun 2023 18:55:26 +0200 Subject: [PATCH 1/4] Reflect changes to Channel::modify() in test --- tests/channel.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/channel.rs b/tests/channel.rs index 002ee43..b37ea3d 100644 --- a/tests/channel.rs +++ b/tests/channel.rs @@ -31,6 +31,7 @@ async fn delete_channel() { #[tokio::test] async fn modify_channel() { let mut bundle = common::setup().await; + let channel = &mut bundle.channel; let modify_data: types::ChannelModifySchema = types::ChannelModifySchema { name: Some("beepboop".to_string()), channel_type: None, @@ -50,10 +51,10 @@ async fn modify_channel() { default_thread_rate_limit_per_user: None, video_quality_mode: None, }; - let result = Channel::modify(modify_data, bundle.channel.id, &mut bundle.user) + Channel::modify(channel, modify_data, channel.id, &mut bundle.user) .await .unwrap(); - assert_eq!(result.name, Some("beepboop".to_string())); + assert_eq!(channel.name, Some("beepboop".to_string())); let permission_override = PermissionFlags::from_vec(Vec::from([ PermissionFlags::MANAGE_CHANNELS, From 1e0783e30ef15cd7eb675f596fb609cb2b6c5a9e Mon Sep 17 00:00:00 2001 From: Flori Weber Date: Thu, 22 Jun 2023 18:56:16 +0200 Subject: [PATCH 2/4] Make Channel::modify() take &mut self --- src/api/channels/channels.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/api/channels/channels.rs b/src/api/channels/channels.rs index 08a6617..2c286dd 100644 --- a/src/api/channels/channels.rs +++ b/src/api/channels/channels.rs @@ -70,10 +70,11 @@ impl Channel { /// /// A `Result` that contains a `Channel` object if the request was successful, or an `ChorusLibError` if an error occurred during the request. pub async fn modify( + &mut self, modify_data: ChannelModifySchema, channel_id: Snowflake, user: &mut UserMeta, - ) -> ChorusResult { + ) -> ChorusResult<()> { let request = Client::new() .patch(format!( "{}/channels/{}/", @@ -82,12 +83,18 @@ impl Channel { )) .bearer_auth(user.token()) .body(to_string(&modify_data).unwrap()); - common::deserialize_response::( + let new_channel = match common::deserialize_response::( request, user, crate::api::limits::LimitType::Channel, ) .await + { + Ok(channel) => channel, + Err(e) => return Err(e), + }; + let _ = std::mem::replace(self, new_channel); + Ok(()) } pub async fn messages( From f55424414374e9b559aae3af8b8d29b4f15cfd0e Mon Sep 17 00:00:00 2001 From: Flori <39242991+bitfl0wer@users.noreply.github.com> Date: Thu, 22 Jun 2023 19:42:07 +0200 Subject: [PATCH 3/4] Update src/api/channels/channels.rs Co-authored-by: SpecificProtagonist --- src/api/channels/channels.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/api/channels/channels.rs b/src/api/channels/channels.rs index 2c286dd..d7f83c8 100644 --- a/src/api/channels/channels.rs +++ b/src/api/channels/channels.rs @@ -88,11 +88,7 @@ impl Channel { user, crate::api::limits::LimitType::Channel, ) - .await - { - Ok(channel) => channel, - Err(e) => return Err(e), - }; + .await?; let _ = std::mem::replace(self, new_channel); Ok(()) } From 0aac291a3cf5f0d8e1742b1d3481e75abcbe6191 Mon Sep 17 00:00:00 2001 From: Flori Weber Date: Thu, 22 Jun 2023 19:54:39 +0200 Subject: [PATCH 4/4] Remove wrongful match statement --- src/api/channels/channels.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/channels/channels.rs b/src/api/channels/channels.rs index d7f83c8..a9e8344 100644 --- a/src/api/channels/channels.rs +++ b/src/api/channels/channels.rs @@ -83,7 +83,7 @@ impl Channel { )) .bearer_auth(user.token()) .body(to_string(&modify_data).unwrap()); - let new_channel = match common::deserialize_response::( + let new_channel = common::deserialize_response::( request, user, crate::api::limits::LimitType::Channel,