p2panda_auth/group/
message.rs

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