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

View File

@ -29,6 +29,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,
@ -48,10 +49,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,