p2panda_auth/group/message.rs
1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3#[cfg(any(test, feature = "serde"))]
4use serde::{Deserialize, Serialize};
5
6use crate::group::GroupAction;
7
8/// Control messages which are processed in order to update group state.
9///
10/// There are two variants, one containing a group action and the ID of the group to which the
11/// action should be applied. The other is a special message which can be used to "undo" a message which
12/// has been previously applied to the group.
13#[derive(Clone, PartialEq, Eq, Debug)]
14#[cfg_attr(any(test, feature = "serde"), derive(Deserialize, Serialize))]
15pub struct GroupControlMessage<ID, C> {
16 pub group_id: ID,
17 pub action: GroupAction<ID, C>,
18}
19
20impl<ID, C> GroupControlMessage<ID, C>
21where
22 ID: Copy,
23{
24 /// Return `true` if this is a create control message.
25 pub fn is_create(&self) -> bool {
26 matches!(
27 self,
28 GroupControlMessage {
29 action: GroupAction::Create { .. },
30 ..
31 }
32 )
33 }
34
35 /// Return the ID of the group this message should be applied to.
36 pub fn group_id(&self) -> ID {
37 self.group_id
38 }
39}