use crate::common::*;
use crate::user::{self, UserID};
use crate::{auth, links};
use super::*;
pub async fn show(id: u64, token: &auth::Token) -> Result<Response<DirectMessage>, error::Error> {
let params = ParamList::default().add_param("id", id.to_string());
let req = get(links::direct::SHOW, token, Some(¶ms));
let resp: Response<raw::SingleEvent> = request_with_json_response(req).await?;
Ok(Response::into(resp))
}
pub fn list(token: &auth::Token) -> Timeline {
Timeline::new(links::direct::LIST, token.clone())
}
pub async fn delete(id: u64, token: &auth::Token) -> Result<Response<()>, error::Error> {
let params = ParamList::new().add_param("id", id.to_string());
let req = auth::raw::delete(links::direct::DELETE, token, Some(¶ms));
request_with_empty_response(req).await
}
pub async fn mark_read(
id: u64,
sender: impl Into<UserID>,
token: &auth::Token,
) -> Result<Response<()>, error::Error> {
let recipient_id = match sender.into() {
UserID::ID(id) => id,
UserID::ScreenName(name) => {
let user = user::show(name, token).await?;
user.id
}
};
let params = ParamList::new()
.add_param("last_read_event_id", id.to_string())
.add_param("recipient_id", recipient_id.to_string());
let req = post(links::direct::MARK_READ, token, Some(¶ms));
request_with_empty_response(req).await
}
pub async fn indicate_typing(
recipient: impl Into<UserID>,
token: &auth::Token,
) -> Result<Response<()>, error::Error> {
let recipient_id = match recipient.into() {
UserID::ID(id) => id,
UserID::ScreenName(name) => {
let user = user::show(name, token).await?;
user.id
}
};
let params = ParamList::new().add_param("recipient_id", recipient_id.to_string());
let req = post(links::direct::INDICATE_TYPING, token, Some(¶ms));
request_with_empty_response(req).await
}