Skip to main content

communitas_ui_api/
lib.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! Shared UI-facing models for Communitas front-ends.
4
5// Security: Enforce no-panic policy in production code
6#![cfg_attr(
7    not(test),
8    deny(clippy::unwrap_used, clippy::expect_used, clippy::panic)
9)]
10// Allow these in tests for convenience
11#![cfg_attr(test, allow(clippy::unwrap_used, clippy::expect_used, clippy::panic))]
12
13pub mod canvas;
14pub mod drive;
15pub mod kanban;
16pub mod messaging;
17pub mod sync;
18
19pub use canvas::{
20    CanvasElement, CanvasInfo, CanvasSnapshot, CanvasState, ElementType, HistoryActionType,
21    HistoryEntry, Layer, OfflineOperation, OfflineStatus, OperationType, Point, RemoteCursor,
22    ToolType, Transform,
23};
24pub use drive::{
25    DirectoryEntry, DiskInfo, DiskType, DownloadProgress, DownloadState, FileMetadata, FilePreview,
26    QuotaInfo, UploadProgress, UploadState,
27};
28pub use kanban::{
29    ActivityEntry, AttachmentView, BoardSettings, BoardSummary, BoardView, CardDetail, CardState,
30    CardView, ChecklistProgress, ColumnView, CommentView, PriorityView, StepView, SwimlaneMode,
31    TagView,
32};
33pub use messaging::{
34    ContactWithPresence, Message, MessageReaction, MessageSendStatus, PendingMessage,
35    PresenceStatus, SearchResult, ThreadSummary,
36};
37pub use sync::{SyncMetadata, SyncProgress, SyncState, SyncSummary};
38
39/// Small helper used by the Dioxus prototype to display generated identity words.
40#[derive(Debug, Clone, PartialEq, Eq)]
41pub struct SampleWords {
42    words: String,
43}
44
45impl SampleWords {
46    /// Create a new sample words value, accepting anything convertible into `String`.
47    pub fn new(words: impl Into<String>) -> Self {
48        Self {
49            words: words.into(),
50        }
51    }
52
53    /// Returns the raw words payload for display.
54    pub fn as_str(&self) -> &str {
55        self.words.as_str()
56    }
57}
58
59/// Snapshot of identity metadata shown in nav bars and headers.
60#[derive(Debug, Clone, PartialEq, Eq, Default)]
61pub struct UnifiedIdentity {
62    pub display_name: String,
63    pub four_words: String,
64}
65
66/// Logical classification for organization-style entities.
67#[derive(Debug, Clone, Copy, PartialEq, Eq)]
68pub enum OrganizationCategory {
69    Organization,
70    Community,
71}
72
73/// Entity type enumeration used by UI layers.
74#[derive(Debug, Clone, Copy, PartialEq, Eq)]
75pub enum UnifiedEntityType {
76    Organization,
77    Project,
78    Group,
79    Channel,
80    Person,
81}
82
83/// View-model for entities shown across navigation, home, and detail screens.
84#[derive(Debug, Clone, PartialEq, Eq)]
85pub struct UnifiedEntity {
86    pub id: String,
87    pub entity_type: UnifiedEntityType,
88    pub name: String,
89    pub description: String,
90    pub member_count: u64,
91    pub parent_id: Option<String>,
92    pub category: Option<OrganizationCategory>,
93}
94
95impl UnifiedEntity {
96    pub fn is_personal_group(&self) -> bool {
97        matches!(self.entity_type, UnifiedEntityType::Group) && self.parent_id.is_none()
98    }
99}
100
101/// Simplified contact view rendered in navigation and contact lists.
102#[derive(Debug, Clone, PartialEq, Eq)]
103pub struct UnifiedContact {
104    pub id: String,
105    pub display_name: String,
106    pub status: String,
107    pub presence: PresenceStatus,
108}