use crate::tables::messages::message::Message;
#[derive(Debug, PartialEq, Eq)]
pub enum GroupAction<'a> {
ParticipantAdded(i32),
ParticipantRemoved(i32),
NameChange(&'a str),
ParticipantLeft,
GroupIconChanged,
GroupIconRemoved,
ChatBackgroundChanged,
ChatBackgroundRemoved,
PhoneNumberChanged(i32),
}
impl<'a> GroupAction<'a> {
#[must_use]
pub(crate) fn from_message(message: &'a Message) -> Option<Self> {
match (
message.item_type,
message.group_action_type,
message.other_handle,
&message.group_title,
) {
(1, 0, Some(who), _) if message.handle_id == Some(who) => {
Some(Self::PhoneNumberChanged(who))
}
(1, 0, Some(who), _) => Some(Self::ParticipantAdded(who)),
(1, 1, Some(who), _) => Some(Self::ParticipantRemoved(who)),
(2, _, _, Some(name)) => Some(Self::NameChange(name)),
(3, 0, _, _) => Some(Self::ParticipantLeft),
(3, 1, _, _) => Some(Self::GroupIconChanged),
(3, 2, _, _) => Some(Self::GroupIconRemoved),
(3, 4, _, _) => Some(Self::ChatBackgroundChanged),
(3, 6, _, _) => Some(Self::ChatBackgroundRemoved),
_ => None,
}
}
}