Skip to content

Commit

Permalink
Merge branch 'unstable'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedilger committed Dec 10, 2023
2 parents 0383258 + 4232fbb commit cb939e4
Show file tree
Hide file tree
Showing 68 changed files with 4,003 additions and 1,863 deletions.
6 changes: 6 additions & 0 deletions debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

cargo build --features=lang-cjk,video-ffmpeg --release && \
RUST_BACKTRACE=1 RUST_LOG="info,gossip_lib=debug" ./target/release/gossip "$@" \
| tee gossip.log.txt

48 changes: 48 additions & 0 deletions docs/SETUP_AND_SHUTDOWN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Setup and Shutdown

This may change, but this is approximately the order of events.

- bin::main()
- setup logging
- lib::init()
- storage::init()
- trigger database into existence
- migrate
- signer::init()
- load from settings in storage
- deletation init
- setup wait-for-login state
- setup async runtime
- optionally handle command-line command and exit, else
- spawn (two threads as below)

- spawn-thread
- lib::run()
- overlord::run()
- maybe wait-for-login (the UI has to do it)
- start fetcher
- start People tasks
- start relay picker
- pick relays
- subscribe discover
- subscribe outbox
- subscribe inbox
- loop
- Get and handle messages
- or if shutdown variable is set, exit this loop
- storage::sync()
- set shutdown variable
- message minions to shutdown
- wait for minions to shutdown
- end of spawn-thread

- main-thread
- ui::run()
- Setup and run the UI
- if wait-for-login, prompt for password and login
- once logged in, indicate such so the overlord can start, and run UI as normal
- If shutdown variable is set, exit
- Signal overlord to shutdown
- Wait for spawn-thread to end
- lib::shutdown()
- storage::sync()
30 changes: 20 additions & 10 deletions gossip-bin/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use bech32::FromBase32;
use gossip_lib::PersonList;
use gossip_lib::PersonRelay;
use gossip_lib::GLOBALS;
use gossip_lib::{Error, ErrorKind};
use gossip_lib::{PersonList, PersonListMetadata};
use nostr_types::{
Event, EventAddr, EventKind, Id, NostrBech32, NostrUrl, PrivateKey, PublicKey, RelayUrl,
UncheckedUrl, Unixtime,
Expand Down Expand Up @@ -269,7 +269,13 @@ pub fn add_person_list(cmd: Command, mut args: env::Args) -> Result<(), Error> {
None => return cmd.usage("Missing listname parameter".to_string()),
};

let _list = PersonList::allocate(&listname, None)?;
let metadata = PersonListMetadata {
dtag: listname.clone(),
title: listname.clone(),
..Default::default()
};

let _list = GLOBALS.storage.allocate_person_list(&metadata, None)?;
Ok(())
}

Expand Down Expand Up @@ -503,9 +509,9 @@ pub fn print_muted(_cmd: Command) -> Result<(), Error> {
}

pub fn print_person_lists(_cmd: Command) -> Result<(), Error> {
let lists = PersonList::all_lists();
for (list, name) in lists.iter() {
println!("LIST {}: {}", u8::from(*list), name);
let all = GLOBALS.storage.get_all_person_list_metadata()?;
for (list, metadata) in all.iter() {
println!("LIST {}: {}", u8::from(*list), metadata.title);
let members = GLOBALS.storage.get_people_in_list(*list)?;
for (pk, public) in &members {
if let Some(person) = GLOBALS.storage.read_person(pk)? {
Expand Down Expand Up @@ -720,11 +726,15 @@ pub fn rename_person_list(cmd: Command, mut args: env::Args) -> Result<(), Error
None => return cmd.usage("Missing newname parameter".to_string()),
};

if let Some(list) = PersonList::from_number(number) {
list.rename(&newname, None)?;
} else {
println!("No list with number={}", number);
}
let list = match PersonList::from_number(number) {
Some(list) => list,
None => {
println!("No list with number={}", number);
return Ok(());
}
};

GLOBALS.storage.rename_person_list(list, newname, None)?;

Ok(())
}
Expand Down
8 changes: 8 additions & 0 deletions gossip-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod ui;
use gossip_lib::comms::ToOverlordMessage;
use gossip_lib::Error;
use gossip_lib::GLOBALS;
use std::sync::atomic::Ordering;
use std::{env, thread};
use tracing_subscriber::filter::{EnvFilter, LevelFilter};

Expand Down Expand Up @@ -74,6 +75,13 @@ fn main() -> Result<(), Error> {
tracing::error!("{}", e);
}

// Make sure the overlord knows to shut down
GLOBALS.shutting_down.store(true, Ordering::Relaxed);

// Make sure the overlord isn't stuck on waiting for login
GLOBALS.wait_for_login.store(false, Ordering::Relaxed);
GLOBALS.wait_for_login_notify.notify_one();

// Tell the async parties to close down
if let Err(e) = initiate_shutdown() {
tracing::error!("{}", e);
Expand Down
8 changes: 7 additions & 1 deletion gossip-bin/src/ui/feed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram

match feed_kind {
FeedKind::List(list, with_replies) => {
let metadata = GLOBALS
.storage
.get_person_list_metadata(list)
.unwrap_or_default()
.unwrap_or_default();

let feed = GLOBALS.feed.get_followed();
let id = format!(
"{} {}",
Expand All @@ -65,7 +71,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
egui::Layout::left_to_right(egui::Align::Center),
|ui| {
add_left_space(ui);
ui.heading(list.name());
ui.heading(metadata.title);
recompute_btn(app, ui);

ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
Expand Down
10 changes: 5 additions & 5 deletions gossip-bin/src/ui/feed/note/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub(super) fn render_note(
let skip = ((note_data.muted() && app.settings.hide_mutes_entirely)
&& !matches!(app.page, Page::Feed(FeedKind::DmChat(_)))
&& !matches!(app.page, Page::Feed(FeedKind::Person(_))))
|| (note_data.deletion.is_some() && !app.settings.show_deleted_events);
|| (!note_data.deletions.is_empty() && !app.settings.show_deleted_events);

if skip {
return;
Expand Down Expand Up @@ -379,7 +379,7 @@ fn render_note_inner(
_ => {}
}

if note.deletion.is_some() {
if !note.deletions.is_empty() {
let color = app.theme.warning_marker_text_color();
ui.label(
RichText::new("DELETED")
Expand Down Expand Up @@ -507,7 +507,7 @@ fn render_note_inner(
GLOBALS.dismissed.blocking_write().push(note.event.id);
}
if Some(note.event.pubkey) == app.settings.public_key
&& note.deletion.is_none()
&& note.deletions.is_empty()
{
if ui.button("Delete").clicked() {
let _ = GLOBALS
Expand Down Expand Up @@ -636,13 +636,13 @@ fn render_note_inner(
ui,
ctx,
note_ref.clone(),
note.deletion.is_some(),
!note.deletions.is_empty(),
content_margin_left,
content_pull_top,
);

// deleted?
if let Some(delete_reason) = &note.deletion {
for delete_reason in &note.deletions {
Frame::none()
.inner_margin(Margin {
left: footer_margin_left,
Expand Down
8 changes: 4 additions & 4 deletions gossip-bin/src/ui/feed/notedata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ pub(super) struct NoteData {
/// Lists the author is on
pub lists: HashMap<PersonList, bool>,

/// Deletion reason if any
pub deletion: Option<String>,
/// Deletion reasons if any
pub deletions: Vec<String>,

/// Do we consider this note as being a repost of another?
pub repost: Option<RepostType>,
Expand Down Expand Up @@ -85,7 +85,7 @@ impl NoteData {

let delegation = event.delegation();

let deletion = GLOBALS.storage.get_deletion(event.id).unwrap_or(None);
let deletions = GLOBALS.storage.get_deletions(&event).unwrap_or_default();

let (reactions, self_already_reacted) = GLOBALS
.storage
Expand Down Expand Up @@ -234,7 +234,7 @@ impl NoteData {
delegation,
author,
lists,
deletion,
deletions,
repost,
embedded_event,
mentions,
Expand Down
Loading

0 comments on commit cb939e4

Please sign in to comment.