notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

options.rs (2489B)


      1 use crate::ProfilePic;
      2 use bitflags::bitflags;
      3 
      4 bitflags! {
      5     // Attributes can be applied to flags types
      6     #[repr(transparent)]
      7     #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
      8     pub struct NoteOptions: u64 {
      9         const ActionBar       = 1 << 0;
     10         const HasNotePreviews = 1 << 1;
     11         const SmallPfp        = 1 << 2;
     12         const MediumPfp       = 1 << 3;
     13         const Wide            = 1 << 4;
     14         const SelectableText  = 1 << 5;
     15         const Textmode        = 1 << 6;
     16         const OptionsButton   = 1 << 7;
     17         const HideMedia       = 1 << 8;
     18         /// Scramble text so that its not distracting during development
     19         const ScrambleText    = 1 << 9;
     20         /// Is this a note preview?
     21         const IsPreview       = 1 << 10;
     22         /// Is the content truncated? If the length is over a certain size it
     23         /// will end with a ... and a "Show more" button.
     24         const Truncate        = 1 << 11;
     25         /// Show note's client in the note content
     26         const ClientName  = 1 << 12;
     27 
     28         const RepliesNewestFirst = 1 << 13;
     29 
     30         /// Show note's full created at date at the bottom
     31         const FullCreatedDate  = 1 << 14;
     32 
     33         /// Note has a framed border
     34         const Framed = 1 << 15;
     35 
     36         /// Note has an unread reply indicator
     37         const UnreadIndicator = 1 << 16;
     38 
     39         /// no animation override (accessibility)
     40         const NoAnimations = 1 << 17;
     41 
     42         /// The note should be displayed as a preview of the underlying note of a composite unit
     43         const NotificationPreview = 1 << 18;
     44 
     45         /// The note is a notification
     46         const Notification = 1 << 19;
     47 
     48         /// There is enough trust to show media in this note
     49         const TrustMedia = 1 << 20;
     50     }
     51 }
     52 
     53 impl Default for NoteOptions {
     54     fn default() -> NoteOptions {
     55         NoteOptions::OptionsButton
     56             | NoteOptions::HasNotePreviews
     57             | NoteOptions::ActionBar
     58             | NoteOptions::Truncate
     59     }
     60 }
     61 
     62 impl NoteOptions {
     63     pub fn new(is_universe_timeline: bool) -> Self {
     64         let mut options = NoteOptions::default();
     65         options.set(NoteOptions::HideMedia, is_universe_timeline);
     66         options
     67     }
     68 
     69     pub fn pfp_size(&self) -> i8 {
     70         if self.contains(NoteOptions::SmallPfp) {
     71             ProfilePic::small_size()
     72         } else if self.contains(NoteOptions::MediumPfp) {
     73             ProfilePic::medium_size()
     74         } else {
     75             ProfilePic::default_size()
     76         }
     77     }
     78 }