Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
//! Domain events emitted by channel mutation workflows.
use crate::domain::{
access_requests::ChannelAccessRequest,
models::{
ChannelMetadata, ChannelParticipant, ChannelType, EntityMention, MutatedMessage, Sender,
},
};
use channel_sender::ChannelSender;
use macro_user_id::user_id::MacroUserIdStr;
use messages::domain::models::{PostMessageNotificationPolicy, SimpleMention};
use uuid::Uuid;
/// Context needed to notify a channel message author about a reaction.
#[derive(Debug, Clone)]
pub struct ReactionNotificationContext {
/// Emoji that was added.
pub emoji: String,
/// Author of the reacted-to message.
pub message_sender: Sender,
/// Root thread id when the reacted-to message is a reply.
pub thread_id: Option<Uuid>,
/// Reacted-to message body.
pub message_content: String,
/// Channel display metadata.
pub metadata: ChannelMetadata,
}
/// Events emitted after durable channel state changes.
#[derive(Debug, Clone)]
pub enum ChannelEvent {
/// A channel picture was set, replaced, or removed.
PictureChanged {
/// User who changed the picture.
actor: MacroUserIdStr<'static>,
/// Channel whose picture changed.
channel_id: Uuid,
/// Active participants whose sessions should refresh the picture.
recipients: Vec<MacroUserIdStr<'static>>,
},
/// A channel was created.
ChannelCreated {
/// Created channel id.
channel_id: Uuid,
/// Actor that created the channel.
actor: ChannelSender<'static>,
/// User the actor created the channel for, when the actor is a bot.
on_behalf_of: Option<MacroUserIdStr<'static>>,
/// Type of channel that was created.
channel_type: ChannelType,
/// Stored channel name; `None` for direct message / unnamed channels.
channel_name: Option<String>,
/// Active participants after creation.
participant_user_ids: Vec<MacroUserIdStr<'static>>,
},
/// A channel was deleted.
ChannelDeleted {
/// Deleted channel id.
channel_id: Uuid,
/// Actor that deleted the channel.
actor: ChannelSender<'static>,
},
/// A message was posted.
MessagePosted {
/// Channel containing the message.
channel_id: Uuid,
/// Resolved channel metadata for downstream side effects.
metadata: ChannelMetadata,
/// Active channel participants at publish time.
participants: Vec<ChannelParticipant>,
/// Persisted message payload.
message: MutatedMessage,
/// Mentions attached to the message.
mentions: Vec<SimpleMention>,
/// Whether the message contains attachments.
has_attachments: bool,
/// Internal notification policy for this post.
notification_policy: PostMessageNotificationPolicy,
},
/// A user added a reaction to a message by another user.
ReactionAdded {
/// Channel containing the message.
channel_id: Uuid,
/// Actor that added the reaction.
actor: Sender,
/// Message that received the reaction.
message_id: Uuid,
/// Data used to format the author notification.
notification: ReactionNotificationContext,
},
/// Participants were explicitly added to a channel.
ParticipantsAdded {
/// Channel receiving new participants.
channel_id: Uuid,
/// Type of channel that received participants.
channel_type: ChannelType,
/// Active participants after the addition.
active_participant_user_ids: Vec<MacroUserIdStr<'static>>,
/// Actor who initiated the add.
invited_by: Sender,
/// Newly added recipients.
recipient_user_ids: Vec<MacroUserIdStr<'static>>,
/// Resolved channel metadata for notification copy.
metadata: ChannelMetadata,
/// Optional message content associated with the invite.
message_content: Option<String>,
},
/// A user joined a channel.
ParticipantJoined {
/// Channel that was joined.
channel_id: Uuid,
/// Type of channel that was joined.
channel_type: ChannelType,
/// Actor that joined the channel.
user_id: Sender,
/// Active participants after the join.
active_participant_user_ids: Vec<MacroUserIdStr<'static>>,
},
/// Channel metadata was updated (rename).
ChannelUpdated {
/// Updated channel id.
channel_id: Uuid,
/// The user who updated the channel.
actor: MacroUserIdStr<'static>,
/// Stored channel name before the update.
previous_name: Option<String>,
/// New channel name.
channel_name: Option<String>,
},
/// Participants were removed from a channel (admin removal or self-leave).
ParticipantsRemoved {
/// Channel the participants were removed from.
channel_id: Uuid,
/// Type of channel the participants were removed from.
channel_type: ChannelType,
/// The user who removed the participants; equals the sole removed
/// user for a self-service leave.
actor: MacroUserIdStr<'static>,
/// Users removed by this mutation.
removed_user_ids: Vec<MacroUserIdStr<'static>>,
},
/// Someone outside a channel asked to join it.
AccessRequested {
/// The new attempt.
request: ChannelAccessRequest,
/// Active participants, any of whom may answer it.
participant_user_ids: Vec<MacroUserIdStr<'static>>,
/// Resolved channel metadata for notification copy.
metadata: ChannelMetadata,
},
/// A request to join was approved, denied, or withdrawn.
AccessRequestResolved {
/// The attempt after resolution.
request: ChannelAccessRequest,
/// Active participants, whose notifications about it are now done.
participant_user_ids: Vec<MacroUserIdStr<'static>>,
},
/// A generic entity mention (e.g. a doc mentioning another entity) was recorded.
EntityMentionCreated {
/// The persisted mention row.
mention: EntityMention,
},
/// A generic entity mention was removed.
EntityMentionDeleted {
/// The mention row that was deleted.
mention: EntityMention,
},
}