talk_api_internal/
friend.rs

1use reqwest::Method;
2use serde::{Deserialize, Serialize};
3
4use crate::{client::ApiClient, read_structured_response, ApiResult};
5
6#[derive(Debug, Clone, Deserialize)]
7pub struct DiffFriend {
8    #[serde(rename = "userId")]
9    pub user_id: u64,
10
11    #[serde(rename = "nickName")]
12    pub nickname: String,
13
14    #[serde(rename = "type")]
15    pub user_type: i32,
16
17    #[serde(rename = "userType")]
18    pub user_category: i32,
19
20    #[serde(rename = "statusMessage")]
21    pub status_message: String,
22
23    #[serde(rename = "profileImageUrl")]
24    pub profile_image_url: String,
25
26    #[serde(rename = "fullProfileImageUrl")]
27    pub full_profile_image_url: String,
28
29    #[serde(rename = "originalProfileImageUrl")]
30    pub original_profile_image_url: String,
31}
32
33#[derive(Debug, Clone, Deserialize)]
34pub struct FriendsDiff {
35    pub total_count: u32,
36    pub deleted_ids: Vec<u64>,
37    pub added_friends: Vec<DiffFriend>,
38}
39
40impl FriendsDiff {
41    pub async fn request(client: ApiClient<'_>, ids: &[u64]) -> ApiResult<Self> {
42        #[derive(Serialize)]
43        struct Form<'a> {
44            friend_ids: &'a str,
45            #[serde(rename = "type")]
46            ty: &'a str,
47        }
48
49        read_structured_response(
50            client
51                .request(Method::POST, "friends/diff.json")?
52                .form(&Form {
53                    friend_ids: &serde_json::to_string(ids).unwrap(),
54                    ty: "a",
55                }),
56        )
57        .await
58    }
59}