concord 2.4.3

A terminal user interface client for Discord
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
use crate::discord::ids::{
    Id,
    marker::{ChannelMarker, GuildMarker, MessageMarker, UserMarker},
};
use crate::discord::{
    AttachmentDownloadId, AttachmentMediaType, ChannelState, ChannelUnreadState, DiscordAction,
    GuildFolder, GuildState, MuteDuration, PresenceStatus, ReactionEmoji, ReactionInfo,
    VoiceParticipantState,
};
use ratatui_image::protocol::Protocol;

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ChannelSwitcherItem {
    pub channel_id: Id<ChannelMarker>,
    pub guild_id: Option<Id<GuildMarker>>,
    pub guild_name: Option<String>,
    pub group_label: String,
    pub parent_label: Option<String>,
    pub channel_label: String,
    pub unread: ChannelUnreadState,
    pub unread_message_count: usize,
    pub search_name: String,
    pub depth: usize,
    pub group_order: usize,
    pub original_index: usize,
}

#[cfg(test)]
#[allow(dead_code)]
impl ChannelSwitcherItem {
    pub(crate) fn test(channel_id: Id<ChannelMarker>) -> Self {
        Self {
            channel_id,
            guild_id: None,
            guild_name: None,
            group_label: String::new(),
            parent_label: None,
            channel_label: String::new(),
            unread: ChannelUnreadState::Seen,
            unread_message_count: 0,
            search_name: String::new(),
            depth: 0,
            group_order: 0,
            original_index: 0,
        }
    }
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum FocusPane {
    Guilds,
    Channels,
    Messages,
    Members,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AttachmentDownloadProgressView {
    pub id: AttachmentDownloadId,
    pub filename: String,
    pub downloaded_bytes: u64,
    pub total_bytes: Option<u64>,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum MessageActionKind {
    CopyContent,
    OpenReactionPicker,
    Reply,
    OpenDeleteConfirmation,
    Edit,
    OpenUrl,
    RemoveEmbeds,
    PlayMedia,
    ViewAttachment,
    ShowProfile,
    OpenPinConfirmation,
    OpenThread,
    ShowReactionUsers,
    OpenPollVotePicker,
    GoToReferencedMessage,
}

impl MessageActionKind {
    pub(crate) const fn discord_action(self) -> Option<DiscordAction> {
        match self {
            Self::OpenReactionPicker => Some(DiscordAction::AddReaction),
            Self::Reply => Some(DiscordAction::SendMessage),
            Self::OpenDeleteConfirmation => Some(DiscordAction::DeleteMessage),
            Self::Edit => Some(DiscordAction::EditMessage),
            Self::RemoveEmbeds => Some(DiscordAction::RemoveMessageEmbeds),
            Self::OpenPinConfirmation => Some(DiscordAction::PinMessage),
            Self::OpenPollVotePicker => Some(DiscordAction::VotePoll),
            Self::CopyContent
            | Self::OpenUrl
            | Self::PlayMedia
            | Self::ViewAttachment
            | Self::ShowProfile
            | Self::OpenThread
            | Self::ShowReactionUsers
            | Self::GoToReferencedMessage => None,
        }
    }
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ActionAvailability {
    Enabled,
    Disabled(String),
}

impl From<Option<String>> for ActionAvailability {
    fn from(disabled_reason: Option<String>) -> Self {
        match disabled_reason {
            Some(reason) => Self::Disabled(reason),
            None => Self::Enabled,
        }
    }
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ActionItem<K> {
    pub kind: K,
    pub label: String,
    availability: ActionAvailability,
}

impl<K> ActionItem<K> {
    pub(crate) fn new(
        kind: K,
        label: impl Into<String>,
        availability: impl Into<ActionAvailability>,
    ) -> Self {
        Self {
            kind,
            label: label.into(),
            availability: availability.into(),
        }
    }

    pub fn is_enabled(&self) -> bool {
        matches!(self.availability, ActionAvailability::Enabled)
    }

    pub fn disabled_reason(&self) -> Option<&str> {
        match &self.availability {
            ActionAvailability::Enabled => None,
            ActionAvailability::Disabled(reason) => Some(reason),
        }
    }
}

pub type MessageActionItem = ActionItem<MessageActionKind>;

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MessageUrlItem {
    pub url: String,
    pub label: String,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SearchFieldView {
    pub label: String,
    pub value: String,
    pub placeholder: String,
    pub active: bool,
    pub cursor: usize,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MessageSearchResultItem {
    pub channel_id: Id<ChannelMarker>,
    pub message_id: Id<MessageMarker>,
    pub channel_label: String,
    pub author: String,
    pub content: String,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MemberSearchResultItem {
    pub user_id: Id<UserMarker>,
    pub guild_id: Option<Id<GuildMarker>>,
    pub display_name: String,
    pub username: Option<String>,
    pub status: PresenceStatus,
    pub is_bot: bool,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ChannelSearchSuggestionItem {
    pub channel_id: Id<ChannelMarker>,
    pub channel_label: String,
    pub guild_label: Option<String>,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum SearchSuggestionItem {
    Member(MemberSearchResultItem),
    Channel(ChannelSearchSuggestionItem),
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum SearchResultItem {
    Message(MessageSearchResultItem),
    Member(MemberSearchResultItem),
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum SearchPopupMode {
    Message,
    Member,
}

impl SearchPopupMode {
    pub fn title(self) -> &'static str {
        match self {
            Self::Message => "Message Search",
            Self::Member => "Member Search",
        }
    }
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SearchPopupView {
    pub mode: SearchPopupMode,
    pub fields: Vec<SearchFieldView>,
    pub suggestions: Vec<SearchSuggestionItem>,
    pub selected_suggestion: usize,
    pub suggestion_scroll: usize,
    pub results: Vec<SearchResultItem>,
    pub selected: usize,
    pub scroll: usize,
    pub loading: bool,
    pub error: Option<String>,
    pub total_results: Option<usize>,
    pub has_more: bool,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ForumPostComposerField {
    Title,
    Body,
    Attachments,
    Tags,
    Submit,
    Cancel,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ForumPostComposerTagView {
    pub name: String,
    /// Unicode emoji shown inline. `None` for a custom or emoji-less tag.
    pub unicode_emoji: Option<String>,
    /// CDN url of a custom tag emoji, overlaid as an image on a reserved gap.
    pub custom_emoji_url: Option<String>,
    /// Resolved `:name:` text fallback shown until the custom emoji image loads.
    pub custom_emoji_label: Option<String>,
    pub selected: bool,
    pub active: bool,
    /// Whether this tag can still be toggled on. `false` for unselected tags
    /// once the five-tag cap is reached, so the renderer can dim them.
    pub selectable: bool,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ForumPostComposerAttachmentView {
    pub filename: String,
    pub size_bytes: u64,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ForumPostComposerView {
    pub channel_label: String,
    pub active_field: ForumPostComposerField,
    pub editing_field: Option<ForumPostComposerField>,
    pub title: String,
    pub title_cursor: usize,
    pub body: String,
    pub body_cursor: usize,
    pub attachments: Vec<ForumPostComposerAttachmentView>,
    pub tags: Vec<ForumPostComposerTagView>,
    pub tag_scroll: usize,
    pub requires_tag: bool,
    pub paste_pending: bool,
    pub status: Option<String>,
}

/// Focusable cells in the thread edit popup. A leaner mirror of
/// [`ForumPostComposerField`]: there is no body or attachments, and the
/// slow-mode and auto-archive selectors replace them. The Tags cell only
/// applies to forum posts and is hidden for regular threads.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ThreadEditField {
    Title,
    Tags,
    SlowMode,
    AutoArchive,
    Submit,
    Cancel,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ThreadEditTagView {
    pub name: String,
    /// Unicode emoji shown inline. `None` for a custom or emoji-less tag.
    pub unicode_emoji: Option<String>,
    /// CDN url of a custom tag emoji, overlaid as an image on a reserved gap.
    pub custom_emoji_url: Option<String>,
    /// Resolved `:name:` text fallback shown until the custom emoji image loads.
    pub custom_emoji_label: Option<String>,
    pub selected: bool,
    pub active: bool,
    /// Whether this tag can still be toggled on. `false` for unselected tags
    /// once the five-tag cap is reached, so the renderer can dim them.
    pub selectable: bool,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ThreadEditView {
    pub channel_label: String,
    pub active_field: ThreadEditField,
    pub editing_title: bool,
    pub editing_tags: bool,
    pub title: String,
    pub title_cursor: usize,
    /// Whether the edited thread is a forum post. Only forum posts have tags, so
    /// the renderer omits the Tags row entirely when this is `false`.
    pub is_forum_post: bool,
    pub tags: Vec<ThreadEditTagView>,
    pub tag_scroll: usize,
    pub requires_tag: bool,
    /// Display label for the current slow-mode option, e.g. "5s" or "Off".
    pub slow_mode_label: String,
    /// Whether the slow-mode selector can be changed (manage-channel permission).
    pub can_set_slow_mode: bool,
    /// Display label for the current auto-archive option, e.g. "1 day".
    pub auto_archive_label: String,
    pub status: Option<String>,
}

pub enum LocalUploadPreviewView<'a> {
    Loading { filename: String },
    Ready { protocol: &'a Protocol },
    Failed { filename: String, message: String },
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AttachmentViewerItem {
    pub index: usize,
    pub total: usize,
    pub filename: String,
    pub url: Option<String>,
    pub size_bytes: u64,
    pub media_type: Option<AttachmentMediaType>,
}

#[cfg(test)]
#[allow(dead_code)]
impl AttachmentViewerItem {
    pub(crate) fn test() -> Self {
        Self {
            index: 0,
            total: 0,
            filename: String::new(),
            url: None,
            size_bytes: 0,
            media_type: None,
        }
    }
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum ChannelActionKind {
    JoinVoice,
    LeaveVoice,
    ShowPinnedMessages,
    ShowThreads,
    MarkAsRead,
    ToggleMute,
}

pub type ChannelActionItem = ActionItem<ChannelActionKind>;

/// Actions on a thread (a regular thread or a forum post). Mirrors Discord's
/// thread/forum-post right-click menu. `Pin` only applies to forum posts. The
/// rest apply to every thread (see `selected_thread_action_items`).
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum ThreadActionKind {
    MarkAsRead,
    ToggleFollow,
    Close,
    Lock,
    Edit,
    CopyLink,
    ToggleMute,
    NotificationSettings,
    Pin,
    Delete,
    CopyId,
}

impl ThreadActionKind {
    pub(crate) const fn discord_action(self) -> Option<DiscordAction> {
        match self {
            Self::ToggleFollow => Some(DiscordAction::ChangeThreadMembership),
            Self::Lock => Some(DiscordAction::ChangeThreadLock),
            Self::Edit => Some(DiscordAction::EditThread),
            Self::Pin => Some(DiscordAction::PinForumPost),
            Self::Delete => Some(DiscordAction::DeleteThread),
            Self::MarkAsRead
            | Self::Close
            | Self::CopyLink
            | Self::ToggleMute
            | Self::NotificationSettings
            | Self::CopyId => None,
        }
    }
}

pub type ThreadActionItem = ActionItem<ThreadActionKind>;

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum GuildActionKind {
    NoActionsYet,
    MarkAsRead,
    ToggleMute,
    LeaveServer,
    FolderSettings,
}

pub type GuildActionItem = ActionItem<GuildActionKind>;

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct MuteActionDurationItem {
    pub label: &'static str,
    pub duration: MuteDuration,
}

/// A single row in the thread notification-settings submenu. The label already
/// includes the `[x]`/`[ ]` radio prefix so the renderer needs no extra logic.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ThreadNotificationItem {
    pub label: String,
    pub flags: u64,
}

impl ThreadNotificationItem {
    pub(crate) fn new(raw_label: &str, flags: u64, current_flags: u64) -> Self {
        let prefix = if flags == current_flags {
            "[x] "
        } else {
            "[ ] "
        };
        Self {
            label: format!("{prefix}{raw_label}"),
            flags,
        }
    }
}

pub const MUTE_ACTION_DURATIONS: [MuteActionDurationItem; 6] = [
    MuteActionDurationItem {
        label: "15 minutes",
        duration: MuteDuration::Minutes(15),
    },
    MuteActionDurationItem {
        label: "1 hour",
        duration: MuteDuration::Minutes(60),
    },
    MuteActionDurationItem {
        label: "3 hours",
        duration: MuteDuration::Minutes(180),
    },
    MuteActionDurationItem {
        label: "8 hours",
        duration: MuteDuration::Minutes(480),
    },
    MuteActionDurationItem {
        label: "24 hours",
        duration: MuteDuration::Minutes(1_440),
    },
    MuteActionDurationItem {
        label: "Permanently",
        duration: MuteDuration::Permanent,
    },
];

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum MemberActionKind {
    ShowProfile,
}

pub type MemberActionItem = ActionItem<MemberActionKind>;

const FORUM_POST_CARD_HEIGHT: usize = 6;

/// A forum tag applied to a post, resolved into display-ready form. At most one
/// emoji field is set: a unicode character, or a custom emoji's CDN image url.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AppliedForumTag {
    pub name: String,
    pub unicode_emoji: Option<String>,
    pub custom_emoji_url: Option<String>,
}

#[cfg(test)]
#[allow(dead_code)]
impl AppliedForumTag {
    pub(crate) fn test(name: impl Into<String>) -> Self {
        Self {
            name: name.into(),
            unicode_emoji: None,
            custom_emoji_url: None,
        }
    }
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ChannelThreadItem {
    pub channel_id: Id<ChannelMarker>,
    pub section_label: Option<String>,
    pub label: String,
    pub archived: bool,
    pub locked: bool,
    pub pinned: bool,
    pub preview_author_id: Option<Id<UserMarker>>,
    pub preview_author: Option<String>,
    pub preview_author_color: Option<u32>,
    pub preview_content: Option<String>,
    pub applied_tags: Vec<AppliedForumTag>,
    pub preview_reactions: Vec<ReactionInfo>,
    pub comment_count: Option<u64>,
    pub new_message_count: usize,
    pub last_activity_message_id: Option<Id<MessageMarker>>,
}

impl ChannelThreadItem {
    pub fn rendered_height(&self) -> usize {
        self.card_height() + usize::from(self.section_label.is_some())
    }

    /// Card body height. The tags row is dropped entirely when the post has no
    /// tags, so an untagged post (and every regular thread) is one row shorter.
    pub fn card_height(&self) -> usize {
        FORUM_POST_CARD_HEIGHT - usize::from(self.applied_tags.is_empty())
    }
}

#[cfg(test)]
#[allow(dead_code)]
impl ChannelThreadItem {
    pub(crate) fn test(channel_id: Id<ChannelMarker>) -> Self {
        Self {
            channel_id,
            section_label: None,
            label: String::new(),
            archived: false,
            locked: false,
            pinned: false,
            preview_author_id: None,
            preview_author: None,
            preview_author_color: None,
            preview_content: None,
            applied_tags: Vec::new(),
            preview_reactions: Vec::new(),
            comment_count: None,
            new_message_count: 0,
            last_activity_message_id: None,
        }
    }
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct EmojiReactionItem {
    pub emoji: ReactionEmoji,
    pub label: String,
}

impl EmojiReactionItem {
    pub fn custom_image_url(&self) -> Option<String> {
        self.emoji.custom_image_url()
    }
}

#[cfg(test)]
#[allow(dead_code)]
impl EmojiReactionItem {
    pub(crate) fn test(emoji: ReactionEmoji) -> Self {
        Self {
            emoji,
            label: String::new(),
        }
    }
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct PollVotePickerItem {
    pub answer_id: u8,
    pub label: String,
    pub selected: bool,
}

#[cfg(test)]
#[allow(dead_code)]
impl PollVotePickerItem {
    pub(crate) fn test(answer_id: u8) -> Self {
        Self {
            answer_id,
            label: String::new(),
            selected: false,
        }
    }
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ThreadSummary {
    pub channel_id: Id<ChannelMarker>,
    pub name: String,
    pub message_count: Option<u64>,
    pub total_message_sent: Option<u64>,
    pub archived: Option<bool>,
    pub locked: Option<bool>,
    pub latest_message_id: Option<Id<MessageMarker>>,
    pub latest_message_preview: Option<ThreadMessagePreview>,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ThreadMessagePreview {
    pub author: String,
    pub content: String,
}

#[derive(Debug, Clone)]
pub enum ChannelPaneEntry<'a> {
    CategoryHeader {
        state: &'a ChannelState,
        collapsed: bool,
    },
    Channel {
        state: &'a ChannelState,
        branch: ChannelBranch,
    },
    Thread {
        state: &'a ChannelState,
        parent_branch: ChannelBranch,
        branch: ChannelBranch,
    },
    VoiceParticipant {
        participant: VoiceParticipantState,
        parent_branch: ChannelBranch,
    },
}

impl ChannelPaneEntry<'_> {
    pub fn channel_state(&self) -> Option<&ChannelState> {
        match self {
            Self::Channel { state, .. } | Self::Thread { state, .. } => Some(state),
            Self::CategoryHeader { .. } | Self::VoiceParticipant { .. } => None,
        }
    }

    pub fn channel_id(&self) -> Option<Id<ChannelMarker>> {
        self.channel_state().map(|state| state.id)
    }

    pub fn display_name(&self) -> &str {
        match self {
            Self::CategoryHeader { state, .. }
            | Self::Channel { state, .. }
            | Self::Thread { state, .. } => state.name.as_str(),
            Self::VoiceParticipant { participant, .. } => participant.display_name.as_str(),
        }
    }

    pub(super) fn is_selectable(&self) -> bool {
        matches!(
            self,
            Self::CategoryHeader { .. } | Self::Channel { .. } | Self::Thread { .. }
        )
    }
}

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum ChannelBranch {
    None,
    Middle,
    Last,
}

impl ChannelBranch {
    pub fn prefix(self) -> &'static str {
        match self {
            Self::None => "",
            Self::Middle => "",
            Self::Last => "",
        }
    }

    pub fn participant_prefix(self) -> &'static str {
        match self {
            Self::None => "  ",
            Self::Middle => "",
            Self::Last => "  ",
        }
    }

    pub(super) fn is_category_child(self) -> bool {
        !matches!(self, Self::None)
    }
}

#[derive(Debug, Clone, Copy)]
pub enum GuildPaneEntry<'a> {
    DirectMessages,
    FolderHeader {
        folder: &'a GuildFolder,
        collapsed: bool,
    },
    Guild {
        state: &'a GuildState,
        branch: GuildBranch,
    },
}

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum GuildBranch {
    None,
    Middle,
    Last,
}

impl GuildBranch {
    pub fn prefix(self) -> &'static str {
        match self {
            Self::None => "",
            Self::Middle => "",
            Self::Last => "",
        }
    }

    pub(super) fn is_folder_child(self) -> bool {
        !matches!(self, Self::None)
    }
}

impl GuildPaneEntry<'_> {
    pub fn guild_state(&self) -> Option<&GuildState> {
        match self {
            Self::Guild { state, .. } => Some(state),
            Self::DirectMessages | Self::FolderHeader { .. } => None,
        }
    }

    pub fn guild_id(&self) -> Option<Id<GuildMarker>> {
        self.guild_state().map(|state| state.id)
    }

    pub fn label(&self) -> &str {
        match self {
            Self::DirectMessages => "Direct Messages",
            Self::FolderHeader { folder, .. } => folder.name.as_deref().unwrap_or("Folder"),
            Self::Guild { state, .. } => state.name.as_str(),
        }
    }
}