Merge pull request #130 from polyphony-chat/refactor/change-channel-modify

Refactor/change channel modify
This commit is contained in:
Flori 2023-06-22 20:05:15 +02:00 committed by GitHub
commit fe0c09b0e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -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. /// 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( pub async fn modify(
&mut self,
modify_data: ChannelModifySchema, modify_data: ChannelModifySchema,
channel_id: Snowflake, channel_id: Snowflake,
user: &mut UserMeta, user: &mut UserMeta,
) -> ChorusResult<Channel> { ) -> ChorusResult<()> {
let request = Client::new() let request = Client::new()
.patch(format!( .patch(format!(
"{}/channels/{}/", "{}/channels/{}/",
@ -82,12 +83,14 @@ impl Channel {
)) ))
.bearer_auth(user.token()) .bearer_auth(user.token())
.body(to_string(&modify_data).unwrap()); .body(to_string(&modify_data).unwrap());
common::deserialize_response::<Channel>( let new_channel = common::deserialize_response::<Channel>(
request, request,
user, user,
crate::api::limits::LimitType::Channel, crate::api::limits::LimitType::Channel,
) )
.await .await?;
let _ = std::mem::replace(self, new_channel);
Ok(())
} }
pub async fn messages( pub async fn messages(

View File

@ -29,6 +29,7 @@ async fn delete_channel() {
#[tokio::test] #[tokio::test]
async fn modify_channel() { async fn modify_channel() {
let mut bundle = common::setup().await; let mut bundle = common::setup().await;
let channel = &mut bundle.channel;
let modify_data: types::ChannelModifySchema = types::ChannelModifySchema { let modify_data: types::ChannelModifySchema = types::ChannelModifySchema {
name: Some("beepboop".to_string()), name: Some("beepboop".to_string()),
channel_type: None, channel_type: None,
@ -48,10 +49,10 @@ async fn modify_channel() {
default_thread_rate_limit_per_user: None, default_thread_rate_limit_per_user: None,
video_quality_mode: 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 .await
.unwrap(); .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([ let permission_override = PermissionFlags::from_vec(Vec::from([
PermissionFlags::MANAGE_CHANNELS, PermissionFlags::MANAGE_CHANNELS,