Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

2.2 KB
Raw Blame
//! GraphQL arguments for an existing notification edge.

use async_graphql::InputObject;
use notification::domain::models::entity_query::EntityNotificationQuery;
use notification_state::graphql::GraphqlNotificationState;

/// Filters applied before the per-entity notification limit.
#[derive(Default, Clone, InputObject)]
pub struct GraphqlNotificationFilter {
    /// Exact states to include; omitted means active (unseen and seen).
    /// An empty list matches no notifications.
    pub states: Option<Vec<GraphqlNotificationState>>,
    /// Event names to include; omitted or empty means every event type.
    pub event_types: Option<Vec<String>>,
    /// Only notifications about top-level channel messages, including mentions but excluding reactions.
    pub top_level_messages_only: Option<bool>,
    /// Scope channel edges to their feed row rather than thread/mention stacks.
    /// Scoping includes active seen reasons. Other entity edges are unchanged.
    /// Applied before the edge limit.
    pub channel_feed_only: Option<bool>,
}

impl GraphqlNotificationFilter {
    /// Decode transport arguments and delegate bounds to the domain query.
    pub(crate) fn into_query(
        self,
        limit: Option<i32>,
    ) -> async_graphql::Result<EntityNotificationQuery> {
        let mut query = EntityNotificationQuery::default();
        if let Some(states) = self.states {
            query.states = states.into_iter().map(Into::into).collect();
        }
        query.event_types = self.event_types.unwrap_or_default();
        query.top_level_messages_only = self.top_level_messages_only.unwrap_or_default();
        query.channel_feed_only = self.channel_feed_only.unwrap_or_default();
        query.limit = limit
            .map(u32::try_from)
            .transpose()
            .map_err(|_| async_graphql::Error::new("notification edge limit must be positive"))?;
        query
            .validate()
            .map_err(|error| async_graphql::Error::new(error.to_string()))?;
        // Equivalent selections share a DataLoader batch, regardless of argument order.
        query.states.sort_by_key(|state| *state as u8);
        query.states.dedup();
        query.event_types.sort();
        query.event_types.dedup();
        Ok(query)
    }
}