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
use super::*;

#[derive(Clone, Debug, Default)]
pub struct Query {
    pub chat_type: Option<String>,
    pub owner_id: Option<String>,
    pub group_id: Option<String>,
    pub sender_id: Option<String>,
    pub sender_name: Option<String>,
    pub keyword: Option<String>,
    pub before: Option<i64>,
    pub after: Option<i64>,
    pub offset: Option<u64>,
    pub limit: Option<u32>,
}

impl Query {
    pub fn get_chat_type(&self) -> &str {
        self.chat_type.as_deref().unwrap_or("%%")
    }

    pub fn get_owner_id(&self) -> &str {
        self.owner_id.as_deref().unwrap_or("%%")
    }

    pub fn get_group_id(&self) -> &str {
        self.group_id.as_deref().unwrap_or("%%")
    }

    pub fn get_sender_id(&self) -> &str {
        self.sender_id.as_deref().unwrap_or("%%")
    }

    pub fn get_sender_name(&self) -> &str {
        self.sender_name.as_deref().unwrap_or("%%")
    }

    pub fn get_offset(&self) -> i64 {
        self.offset
            .unwrap_or_default()
            .try_into()
            .unwrap_or(i64::MAX)
    }

    pub fn get_limit(&self) -> i64 {
        self.limit.unwrap_or(50).into()
    }
}