Merge pull request #107 from polyphony-chat/feature/relationships
Feature/relationships
This commit is contained in:
commit
85846cd0a0
|
@ -1,6 +1,12 @@
|
|||
use reqwest::Client;
|
||||
use serde_json::to_string;
|
||||
|
||||
use crate::{api::deserialize_response, errors::ChorusLibError, instance::UserMeta, types};
|
||||
use crate::{
|
||||
api::{deserialize_response, handle_request_as_option},
|
||||
errors::ChorusLibError,
|
||||
instance::UserMeta,
|
||||
types,
|
||||
};
|
||||
|
||||
impl UserMeta {
|
||||
/// Retrieves the mutual relationships between the authenticated user and the specified user.
|
||||
|
@ -30,4 +36,24 @@ impl UserMeta {
|
|||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Sends a friend request to a user.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `schema` - A [`FriendRequestSendSchema`] struct that holds the information about the friend request to be sent.
|
||||
///
|
||||
/// # Returns
|
||||
/// This function returns an [`Option`] that holds a [`ChorusLibError`] if the request fails.
|
||||
pub async fn send_friend_request(
|
||||
&mut self,
|
||||
schema: types::FriendRequestSendSchema,
|
||||
) -> Option<ChorusLibError> {
|
||||
let belongs_to = self.belongs_to.borrow();
|
||||
let url = format!("{}/users/@me/relationships/", belongs_to.urls.get_api());
|
||||
drop(belongs_to);
|
||||
let body = to_string(&schema).unwrap();
|
||||
let request = Client::new().post(url).bearer_auth(self.token()).body(body);
|
||||
handle_request_as_option(request, self, crate::api::limits::LimitType::Global).await
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,3 +30,9 @@ pub enum RelationshipType {
|
|||
Friends = 1,
|
||||
None = 0,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
pub struct FriendRequestSendSchema {
|
||||
pub username: String,
|
||||
pub discriminator: Option<String>,
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
use chorus::types;
|
||||
|
||||
mod common;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_get_mutual_relationships() {
|
||||
let register_schema = types::RegisterSchema::new(
|
||||
"integrationtestuser2".to_string(),
|
||||
None,
|
||||
true,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
Some("2000-01-01".to_string()),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let bundle = common::setup().await;
|
||||
let mut belongs_to = bundle.instance;
|
||||
let mut user = bundle.user;
|
||||
let other_user = belongs_to.register_account(®ister_schema).await.unwrap();
|
||||
let relationships = user
|
||||
.get_mutual_relationships(&other_user.object.id.to_string())
|
||||
.await
|
||||
.unwrap();
|
||||
println!("{:?}", relationships.unwrap());
|
||||
}
|
Loading…
Reference in New Issue