rust_rcs_client/conference/
subscription.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 std::ffi::CString;
16
17enum MultiConferenceEventInner {
18    UserJoin(String),
19    UserLeft(String),
20    ConferenceEnd,
21}
22
23pub struct MultiConferenceEvent {
24    inner: MultiConferenceEventInner,
25}
26
27impl MultiConferenceEvent {
28    pub fn conference_end() -> MultiConferenceEvent {
29        MultiConferenceEvent {
30            inner: MultiConferenceEventInner::ConferenceEnd,
31        }
32    }
33
34    pub fn get_event_type(&self) -> u16 {
35        match self.inner {
36            MultiConferenceEventInner::UserJoin(_) => 0,
37            MultiConferenceEventInner::UserLeft(_) => 1,
38            MultiConferenceEventInner::ConferenceEnd => 2,
39        }
40    }
41
42    pub fn get_user_joined(&self) -> Result<CString, ()> {
43        if let MultiConferenceEventInner::UserJoin(user) = &self.inner {
44            if let Ok(user) = CString::new(user.as_str()) {
45                return Ok(user);
46            }
47        }
48
49        Err(())
50    }
51
52    pub fn get_user_left(&self) -> Result<CString, ()> {
53        if let MultiConferenceEventInner::UserLeft(user) = &self.inner {
54            if let Ok(user) = CString::new(user.as_str()) {
55                return Ok(user);
56            }
57        }
58
59        Err(())
60    }
61}
62
63pub struct MultiConferenceSubscriber {}