use std::collections::HashMap;
use steamid::SteamID;
use super::super::{GasError, GasSteamUser};
use crate::types::{CommunitySearchResult, FriendDetails, FriendListPage, PendingFriendList};
impl GasSteamUser {
pub async fn add_friend(&self, steam_id: SteamID) -> Result<(), GasError> {
let id = steam_id.steam_id64().to_string();
self.call_void("add_friend", &[("steamId64", &id)]).await
}
pub async fn remove_friend(&self, steam_id: SteamID) -> Result<(), GasError> {
let id = steam_id.steam_id64().to_string();
self.call_void("remove_friend", &[("steamId64", &id)]).await
}
pub async fn accept_friend_request(&self, steam_id: SteamID) -> Result<(), GasError> {
let id = steam_id.steam_id64().to_string();
self.call_void("accept_friend_request", &[("steamId64", &id)]).await
}
pub async fn ignore_friend_request(&self, steam_id: SteamID) -> Result<(), GasError> {
let id = steam_id.steam_id64().to_string();
self.call_void("ignore_friend_request", &[("steamId64", &id)]).await
}
pub async fn block_user(&self, steam_id: SteamID) -> Result<(), GasError> {
let id = steam_id.steam_id64().to_string();
self.call_void("block_user", &[("steamId64", &id)]).await
}
pub async fn unblock_user(&self, steam_id: SteamID) -> Result<(), GasError> {
let id = steam_id.steam_id64().to_string();
self.call_void("unblock_user", &[("steamId64", &id)]).await
}
pub async fn get_friends_list(&self) -> Result<HashMap<SteamID, i32>, GasError> {
self.call("get_friends_list", &[]).await
}
pub async fn get_friends_details(&self) -> Result<FriendListPage, GasError> {
self.call("get_friends_details", &[]).await
}
pub async fn get_friends_details_of_user(&self, steam_id: SteamID) -> Result<FriendListPage, GasError> {
let id = steam_id.steam_id64().to_string();
self.call("get_friends_details_of_user", &[("steamId64", &id)]).await
}
pub async fn search_users(&self, query: &str, page: u32) -> Result<CommunitySearchResult, GasError> {
let p = page.to_string();
self.call("search_users", &[("query", query), ("page", &p)]).await
}
pub async fn create_instant_invite(&self) -> Result<String, GasError> {
self.call("create_instant_invite", &[]).await
}
pub async fn follow_user(&self, steam_id: SteamID) -> Result<(), GasError> {
let id = steam_id.steam_id64().to_string();
self.call_void("follow_user", &[("steamId64", &id)]).await
}
pub async fn unfollow_user(&self, steam_id: SteamID) -> Result<(), GasError> {
let id = steam_id.steam_id64().to_string();
self.call_void("unfollow_user", &[("steamId64", &id)]).await
}
pub async fn get_following_list(&self) -> Result<FriendListPage, GasError> {
self.call("get_following_list", &[]).await
}
pub async fn get_following_list_of_user(&self, steam_id: SteamID) -> Result<FriendListPage, GasError> {
let id = steam_id.steam_id64().to_string();
self.call("get_following_list_of_user", &[("steamId64", &id)]).await
}
pub async fn get_my_friends_id_list(&self) -> Result<Vec<SteamID>, GasError> {
self.call("get_my_friends_id_list", &[]).await
}
pub async fn get_pending_friend_list(&self) -> Result<PendingFriendList, GasError> {
self.call("get_pending_friend_list", &[]).await
}
pub async fn remove_friends(&self, steam_ids: &[SteamID]) -> Result<(), GasError> {
let id_values: Vec<u64> = steam_ids.iter().map(|id| id.steam_id64()).collect();
let ids = serde_json::to_string(&id_values).map_err(GasError::Json)?;
self.call_void("remove_friends", &[("steamIds", &ids)]).await
}
pub async fn unfollow_users(&self, steam_ids: &[SteamID]) -> Result<(), GasError> {
let id_values: Vec<u64> = steam_ids.iter().map(|id| id.steam_id64()).collect();
let ids = serde_json::to_string(&id_values).map_err(GasError::Json)?;
self.call_void("unfollow_users", &[("steamIds", &ids)]).await
}
pub async fn cancel_friend_request(&self, steam_id: SteamID) -> Result<(), GasError> {
let id = steam_id.steam_id64().to_string();
self.call_void("cancel_friend_request", &[("steamId64", &id)]).await
}
pub async fn get_friends_in_common(&self, steam_id: SteamID) -> Result<Vec<FriendDetails>, GasError> {
let id = steam_id.steam_id64().to_string();
self.call("get_friends_in_common", &[("steamId64", &id)]).await
}
}