1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use actix::{Context, Handler, Message};
use actors::TelegramApi;
use futures::Future;
use std::num::{NonZeroU16, NonZeroU8};
use std::time::Duration;
use types::{Update, UpdateId};
#[derive(Serialize, Debug)]
pub struct OptimizedGetUpdates {
#[serde(skip_serializing_if = "Option::is_none")]
offset: Option<UpdateId>,
#[serde(skip_serializing_if = "Option::is_none")]
limit: Option<NonZeroU8>,
#[serde(skip_serializing_if = "Option::is_none")]
timeout: Option<NonZeroU16>,
#[serde(skip_serializing_if = "Option::is_none")]
allowed_updates: Option<Vec<String>>,
}
impl OptimizedGetUpdates {
pub fn new(timeout: u16, offset: Option<UpdateId>) -> Self {
let timeout = unsafe { Some(NonZeroU16::new_unchecked(timeout)) };
let allowed_updates = None;
let limit = None;
Self {
offset,
timeout,
allowed_updates,
limit,
}
}
}
impl Message for OptimizedGetUpdates {
type Result = Result<Vec<Update>, ()>;
}
impl Handler<OptimizedGetUpdates> for TelegramApi {
type Result = Box<Future<Item = Vec<Update>, Error = ()>>;
fn handle(&mut self, msg: OptimizedGetUpdates, _ctx: &mut Context<Self>) -> Self::Result {
let timeout = msg.timeout.map_or(self.timeout, |timeout| {
Duration::from_secs(u64::from(timeout.get()) + 5)
});
Self::send_request(&self.token, "getUpdates", timeout, &msg)
}
}