matrix_sdk_ffi/timeline/
reply.rs

1// Copyright 2023 The Matrix.org Foundation C.I.C.
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 matrix_sdk_ui::timeline::TimelineDetails;
16
17use super::{content::TimelineItemContent, ProfileDetails};
18
19#[derive(Clone, uniffi::Object)]
20pub struct InReplyToDetails {
21    event_id: String,
22    event: RepliedToEventDetails,
23}
24
25impl InReplyToDetails {
26    pub(crate) fn new(event_id: String, event: RepliedToEventDetails) -> Self {
27        Self { event_id, event }
28    }
29}
30
31#[matrix_sdk_ffi_macros::export]
32impl InReplyToDetails {
33    pub fn event_id(&self) -> String {
34        self.event_id.clone()
35    }
36
37    pub fn event(&self) -> RepliedToEventDetails {
38        self.event.clone()
39    }
40}
41
42impl From<matrix_sdk_ui::timeline::InReplyToDetails> for InReplyToDetails {
43    fn from(inner: matrix_sdk_ui::timeline::InReplyToDetails) -> Self {
44        let event_id = inner.event_id.to_string();
45        let event = match &inner.event {
46            TimelineDetails::Unavailable => RepliedToEventDetails::Unavailable,
47            TimelineDetails::Pending => RepliedToEventDetails::Pending,
48            TimelineDetails::Ready(event) => RepliedToEventDetails::Ready {
49                content: event.content().clone().into(),
50                sender: event.sender().to_string(),
51                sender_profile: event.sender_profile().into(),
52            },
53            TimelineDetails::Error(err) => {
54                RepliedToEventDetails::Error { message: err.to_string() }
55            }
56        };
57
58        Self { event_id, event }
59    }
60}
61
62#[derive(Clone, uniffi::Enum)]
63pub enum RepliedToEventDetails {
64    Unavailable,
65    Pending,
66    Ready { content: TimelineItemContent, sender: String, sender_profile: ProfileDetails },
67    Error { message: String },
68}