Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add scramble flag for development text scrambling #745

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions crates/notedeck_columns/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
subscriptions::{SubKind, Subscriptions},
support::Support,
timeline::{self, TimelineCache},
ui::{self, DesktopSidePanel},
ui::{self, note::NoteOptions, DesktopSidePanel},
unknowns,
view_state::ViewState,
Result,
Expand Down Expand Up @@ -50,7 +50,7 @@ pub struct Damus {
pub tmp_columns: bool,
pub debug: bool,
pub since_optimize: bool,
pub textmode: bool,
pub note_options: NoteOptions,

pub unrecognized_args: BTreeSet<String>,
}
Expand Down Expand Up @@ -422,14 +422,18 @@ impl Damus {

let debug = ctx.args.debug;
let support = Support::new(ctx.path);
let mut note_options = NoteOptions::default();
note_options.set_textmode(parsed_args.textmode);
note_options.set_scramble_text(parsed_args.scramble);
note_options.set_hide_media(parsed_args.no_media);

Self {
subscriptions: Subscriptions::default(),
since_optimize: parsed_args.since_optimize,
timeline_cache,
drafts: Drafts::default(),
state: DamusState::Initializing,
textmode: parsed_args.textmode,
note_options,
//frame_history: FrameHistory::default(),
view_state: ViewState::default(),
tmp_columns,
Expand Down Expand Up @@ -473,7 +477,7 @@ impl Damus {
timeline_cache: TimelineCache::default(),
drafts: Drafts::default(),
state: DamusState::Initializing,
textmode: false,
note_options: NoteOptions::default(),
tmp_columns: true,
//frame_history: FrameHistory::default(),
view_state: ViewState::default(),
Expand Down
8 changes: 8 additions & 0 deletions crates/notedeck_columns/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub struct ColumnsArgs {
pub columns: Vec<ArgColumn>,
pub since_optimize: bool,
pub textmode: bool,
pub scramble: bool,
pub no_media: bool,
}

impl ColumnsArgs {
Expand All @@ -17,6 +19,8 @@ impl ColumnsArgs {
columns: vec![],
since_optimize: true,
textmode: false,
scramble: false,
no_media: false,
};

let mut i = 0;
Expand All @@ -28,6 +32,10 @@ impl ColumnsArgs {
res.textmode = true;
} else if arg == "--no-since-optimize" {
res.since_optimize = false;
} else if arg == "--scramble" {
res.scramble = true;
} else if arg == "--no-media" {
res.no_media = true;
} else if arg == "--filter" {
i += 1;
let filter = if let Some(next_arg) = args.get(i) {
Expand Down
5 changes: 4 additions & 1 deletion crates/notedeck_columns/src/nav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ fn render_nav_body(
ctx.accounts,
kind,
col,
app.textmode,
app.note_options,
depth,
ui,
),
Expand Down Expand Up @@ -310,6 +310,7 @@ fn render_nav_body(
ctx.img_cache,
&note,
inner_rect,
app.note_options,
)
.id_source(id)
.show(ui)
Expand Down Expand Up @@ -345,6 +346,7 @@ fn render_nav_body(
draft,
&note,
inner_rect,
app.note_options,
)
.id_source(id)
.show(ui)
Expand All @@ -366,6 +368,7 @@ fn render_nav_body(
ctx.note_cache,
kp,
inner_rect,
app.note_options,
)
.ui(&txn, ui);

Expand Down
16 changes: 8 additions & 8 deletions crates/notedeck_columns/src/timeline/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ pub fn render_timeline_route(
accounts: &mut Accounts,
kind: &TimelineKind,
col: usize,
textmode: bool,
mut note_options: NoteOptions,
depth: usize,
ui: &mut egui::Ui,
) -> Option<RenderNavAction> {
let note_options = {
let mut options = NoteOptions::new(kind == &TimelineKind::Universe);
options.set_textmode(textmode);
options
};
if kind == &TimelineKind::Universe {
note_options.set_hide_media(true);
}

match kind {
TimelineKind::List(_)
Expand Down Expand Up @@ -63,6 +61,7 @@ pub fn render_timeline_route(
col,
ui,
&accounts.mutefun(),
note_options,
)
} else {
// we render profiles like timelines if they are at the root
Expand All @@ -88,7 +87,7 @@ pub fn render_timeline_route(
unknown_ids,
img_cache,
id.selected_or_root(),
textmode,
note_options,
&accounts.mutefun(),
)
.id_source(egui::Id::new(("threadscroll", col)))
Expand All @@ -109,6 +108,7 @@ pub fn render_profile_route(
col: usize,
ui: &mut egui::Ui,
is_muted: &MuteFun,
note_options: NoteOptions,
) -> Option<RenderNavAction> {
let action = ProfileView::new(
pubkey,
Expand All @@ -120,7 +120,7 @@ pub fn render_profile_route(
img_cache,
unknown_ids,
is_muted,
NoteOptions::default(),
note_options,
)
.ui(ui);

Expand Down
30 changes: 27 additions & 3 deletions crates/notedeck_columns/src/ui/note/contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ impl egui::Widget for &mut NoteContents<'_> {

/// Render an inline note preview with a border. These are used when
/// notes are references within a note
#[allow(clippy::too_many_arguments)]
pub fn render_note_preview(
ui: &mut egui::Ui,
ndb: &Ndb,
Expand All @@ -75,6 +76,7 @@ pub fn render_note_preview(
txn: &Transaction,
id: &[u8; 32],
parent: NoteKey,
note_options: NoteOptions,
) -> NoteResponse {
#[cfg(feature = "profiling")]
puffin::profile_function!();
Expand Down Expand Up @@ -112,7 +114,7 @@ pub fn render_note_preview(
ui.visuals().noninteractive().bg_stroke.color,
))
.show(ui, |ui| {
ui::NoteView::new(ndb, note_cache, img_cache, &note)
ui::NoteView::new(ndb, note_cache, img_cache, &note, note_options)
.actionbar(false)
.small_pfp(true)
.wide(true)
Expand Down Expand Up @@ -225,7 +227,11 @@ fn render_note_contents(
BlockType::Text => {
#[cfg(feature = "profiling")]
puffin::profile_scope!("text contents");
ui.add(egui::Label::new(block.as_str()).selectable(selectable));
if options.has_scramble_text() {
ui.add(egui::Label::new(rot13(block.as_str())).selectable(selectable));
} else {
ui.add(egui::Label::new(block.as_str()).selectable(selectable));
}
}

_ => {
Expand All @@ -236,7 +242,7 @@ fn render_note_contents(
});

let preview_note_action = if let Some((id, _block_str)) = inline_note {
render_note_preview(ui, ndb, note_cache, img_cache, txn, id, note_key).action
render_note_preview(ui, ndb, note_cache, img_cache, txn, id, note_key, options).action
} else {
None
};
Expand All @@ -253,6 +259,24 @@ fn render_note_contents(
NoteResponse::new(response.response).with_action(note_action)
}

fn rot13(input: &str) -> String {
input
.chars()
.map(|c| {
if c.is_ascii_lowercase() {
// Rotate lowercase letters
(((c as u8 - b'a' + 13) % 26) + b'a') as char
} else if c.is_ascii_uppercase() {
// Rotate uppercase letters
(((c as u8 - b'A' + 13) % 26) + b'A') as char
} else {
// Leave other characters unchanged
c
}
})
.collect()
}

fn image_carousel(
ui: &mut egui::Ui,
img_cache: &mut ImageCache,
Expand Down
21 changes: 14 additions & 7 deletions crates/notedeck_columns/src/ui/note/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ impl<'a> NoteView<'a> {
note_cache: &'a mut NoteCache,
img_cache: &'a mut ImageCache,
note: &'a nostrdb::Note<'a>,
mut flags: NoteOptions,
) -> Self {
let flags = NoteOptions::actionbar | NoteOptions::note_previews;
flags.set_actionbar(true);
flags.set_note_previews(true);

let parent: Option<NoteKey> = None;
Self {
ndb,
Expand All @@ -89,11 +92,6 @@ impl<'a> NoteView<'a> {
}
}

pub fn note_options(mut self, options: NoteOptions) -> Self {
*self.options_mut() = options;
self
}

pub fn textmode(mut self, enable: bool) -> Self {
self.options_mut().set_textmode(enable);
self
Expand Down Expand Up @@ -287,7 +285,14 @@ impl<'a> NoteView<'a> {
.text_style(style.text_style()),
);
});
NoteView::new(self.ndb, self.note_cache, self.img_cache, &note_to_repost).show(ui)
NoteView::new(
self.ndb,
self.note_cache,
self.img_cache,
&note_to_repost,
self.flags,
)
.show(ui)
} else {
self.show_standard(ui)
}
Expand Down Expand Up @@ -393,6 +398,7 @@ impl<'a> NoteView<'a> {
self.ndb,
self.img_cache,
self.note_cache,
self.flags,
)
})
.inner;
Expand Down Expand Up @@ -464,6 +470,7 @@ impl<'a> NoteView<'a> {
self.ndb,
self.img_cache,
self.note_cache,
self.flags,
);

if action.is_some() {
Expand Down
4 changes: 4 additions & 0 deletions crates/notedeck_columns/src/ui/note/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ bitflags! {
const textmode = 0b0000000001000000;
const options_button = 0b0000000010000000;
const hide_media = 0b0000000100000000;

/// Scramble text so that its not distracting during development
const scramble_text = 0b0000001000000000;
}
}

Expand Down Expand Up @@ -52,6 +55,7 @@ impl NoteOptions {
create_bit_methods!(set_wide, has_wide, wide);
create_bit_methods!(set_options_button, has_options_button, options_button);
create_bit_methods!(set_hide_media, has_hide_media, hide_media);
create_bit_methods!(set_scramble_text, has_scramble_text, scramble_text);

pub fn new(is_universe_timeline: bool) -> Self {
let mut options = NoteOptions::default();
Expand Down
8 changes: 7 additions & 1 deletion crates/notedeck_columns/src/ui/note/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::media_upload::{nostrbuild_nip96_upload, MediaPath};
use crate::post::{downcast_post_buffer, MentionType, NewPost};
use crate::profile::get_display_name;
use crate::ui::search_results::SearchResultsView;
use crate::ui::{self, Preview, PreviewConfig};
use crate::ui::{self, note::NoteOptions, Preview, PreviewConfig};
use crate::Result;
use egui::text::{CCursorRange, LayoutJob};
use egui::text_edit::TextEditOutput;
Expand All @@ -27,6 +27,7 @@ pub struct PostView<'a> {
poster: FilledKeypair<'a>,
id_source: Option<egui::Id>,
inner_rect: egui::Rect,
note_options: NoteOptions,
}

#[derive(Clone)]
Expand Down Expand Up @@ -82,6 +83,7 @@ pub struct PostResponse {
}

impl<'a> PostView<'a> {
#[allow(clippy::too_many_arguments)]
pub fn new(
ndb: &'a Ndb,
draft: &'a mut Draft,
Expand All @@ -90,6 +92,7 @@ impl<'a> PostView<'a> {
note_cache: &'a mut NoteCache,
poster: FilledKeypair<'a>,
inner_rect: egui::Rect,
note_options: NoteOptions,
) -> Self {
let id_source: Option<egui::Id> = None;
PostView {
Expand All @@ -101,6 +104,7 @@ impl<'a> PostView<'a> {
id_source,
post_type,
inner_rect,
note_options,
}
}

Expand Down Expand Up @@ -302,6 +306,7 @@ impl<'a> PostView<'a> {
txn,
id.bytes(),
nostrdb::NoteKey::new(0),
self.note_options,
);
});
});
Expand Down Expand Up @@ -686,6 +691,7 @@ mod preview {
app.note_cache,
self.poster.to_filled(),
ui.available_rect_before_wrap(),
NoteOptions::default(),
)
.ui(&txn, ui);
}
Expand Down
Loading
Loading