rust_rcs_client/messaging/
config.rs

1// Copyright 2023 宋昊文
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use crate::provisioning::rcs_application::RcsApplication;
16
17pub struct MessagingConfigs {
18    pub chat_auth: i32,
19    pub group_chat_auth: i32,
20    pub standalone_msg_auth: i32,
21
22    pub max_ad_hoc_group_size: usize,
23
24    pub conf_fcty_uri: Option<String>,
25
26    pub max_one_to_many_recipients: i32,
27    pub one_to_many_selected_technology: i32,
28
29    pub im_session_auto_accept: i32,
30    pub im_session_auto_accept_group_chat: i32,
31    pub im_session_timer: i32,
32
33    pub max_size_im: usize,
34
35    pub standalone_msg_max_size: usize,
36    pub standalone_msg_switch_over_size: usize,
37
38    pub exploder_uri: Option<String>,
39
40    pub chatbot_msg_tech: i32,
41}
42
43impl MessagingConfigs {
44    pub fn new() -> MessagingConfigs {
45        MessagingConfigs {
46            chat_auth: 0,
47            group_chat_auth: 0,
48            standalone_msg_auth: 0,
49
50            max_one_to_many_recipients: 0,
51            one_to_many_selected_technology: 0,
52
53            max_ad_hoc_group_size: 0,
54
55            conf_fcty_uri: None,
56
57            im_session_auto_accept: 1,
58            im_session_auto_accept_group_chat: 1,
59            im_session_timer: 0,
60
61            max_size_im: usize::max_value(),
62
63            standalone_msg_max_size: usize::max_value(),
64            standalone_msg_switch_over_size: 1300,
65
66            exploder_uri: None,
67
68            chatbot_msg_tech: 0,
69        }
70    }
71
72    pub fn update_configuration(&mut self, rcs_app: &RcsApplication) {
73        if let Some(services_config) = rcs_app.get_services_config() {
74            self.chat_auth = services_config.get_chat_auth();
75            self.group_chat_auth = services_config.get_group_chat_auth();
76            self.standalone_msg_auth = services_config.get_standalone_msg_auth();
77        }
78
79        if let Some(messaging_config) = rcs_app.get_messaging_config() {
80            self.max_one_to_many_recipients = messaging_config.get_max_one_to_many_recipients();
81            self.one_to_many_selected_technology =
82                messaging_config.get_one_to_many_selected_technology();
83
84            if let Some(chat_config) = messaging_config.get_chat_config() {
85                self.max_ad_hoc_group_size = chat_config.get_max_ad_hoc_group_size();
86                self.conf_fcty_uri = chat_config.get_conf_fcty_uri();
87                self.im_session_auto_accept = chat_config.get_im_session_auto_accept();
88                self.im_session_auto_accept_group_chat =
89                    chat_config.get_im_session_auto_accept_group_chat();
90                self.max_size_im = chat_config.get_max_size_im();
91            }
92
93            if let Some(standalone_config) = messaging_config.get_standalone_config() {
94                self.standalone_msg_max_size = standalone_config.get_max_size();
95                self.standalone_msg_switch_over_size = standalone_config.get_switch_over_size();
96                self.exploder_uri = standalone_config.get_exploder_uri();
97            }
98
99            if let Some(chatbot_config) = messaging_config.get_chat_bot_config() {
100                self.chatbot_msg_tech = chatbot_config.get_chatbot_msg_tech();
101            }
102        }
103    }
104}