acter_core/events/
comments.rs

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
use derive_builder::Builder;
use derive_getters::Getters;
use matrix_sdk_base::ruma::events::{macros::EventContent, room::message::TextMessageEventContent};
use serde::{Deserialize, Serialize};

use super::{BelongsTo, References, Update};
use crate::Result;

/// Comment Event
#[derive(Clone, Debug, Deserialize, Serialize, EventContent, Builder, Getters)]
#[ruma_event(type = "global.acter.dev.comment", kind = MessageLike)]
#[builder(name = "CommentBuilder", derive(Debug))]
pub struct CommentEventContent {
    #[builder(setter(into))]
    #[serde(rename = "m.relates_to")]
    pub on: BelongsTo,

    #[builder(setter(into), default)]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub reply_to: Option<References>,

    pub content: TextMessageEventContent,
}

/// The Comment Update Event
#[derive(Clone, Debug, Deserialize, Serialize, EventContent, Builder)]
#[ruma_event(type = "global.acter.dev.comment.update", kind = MessageLike)]
#[builder(name = "CommentUpdateBuilder", derive(Debug))]
pub struct CommentUpdateEventContent {
    #[builder(setter(into))]
    #[serde(rename = "m.relates_to")]
    pub comment: Update,

    pub content: TextMessageEventContent,
}

impl CommentUpdateEventContent {
    pub fn apply(&self, task: &mut CommentEventContent) -> Result<bool> {
        task.content = self.content.clone();
        Ok(true)
    }
}