Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedilger committed Dec 29, 2023
1 parent 42eb336 commit f55db80
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 58 deletions.
34 changes: 23 additions & 11 deletions gossip-bin/src/ui/people/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,12 @@ pub(in crate::ui) fn layout_list_title(
layout_job
}

fn render_add_contact_popup(ui: &mut Ui, app: &mut GossipUi, list: PersonList, metadata: &PersonListMetadata) {
fn render_add_contact_popup(
ui: &mut Ui,
app: &mut GossipUi,
list: PersonList,
metadata: &PersonListMetadata,
) {
const DLG_SIZE: Vec2 = vec2(400.0, 240.0);
let ret = crate::ui::widgets::modal_popup(ui, DLG_SIZE, DLG_SIZE, true, |ui| {
let enter_key;
Expand Down Expand Up @@ -415,17 +420,21 @@ fn render_add_contact_popup(ui: &mut Ui, app: &mut GossipUi, list: PersonList, m
if let Ok(pubkey) =
PublicKey::try_from_bech32_string(app.add_contact.trim(), true)
{
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::FollowPubkey(pubkey, list, !metadata.private));
let _ = GLOBALS.to_overlord.send(ToOverlordMessage::FollowPubkey(
pubkey,
list,
!metadata.private,
));
can_close = true;
mark_refresh(app);
} else if let Ok(pubkey) =
PublicKey::try_from_hex_string(app.add_contact.trim(), true)
{
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::FollowPubkey(pubkey, list, !metadata.private));
let _ = GLOBALS.to_overlord.send(ToOverlordMessage::FollowPubkey(
pubkey,
list,
!metadata.private,
));
can_close = true;
mark_refresh(app);
} else if let Ok(profile) =
Expand Down Expand Up @@ -667,11 +676,11 @@ pub(super) fn render_more_list_actions(
on_list: bool,
) {
if on_list {
app.theme.accent_button_1_style(ui.style_mut());
app.theme.accent_button_1_style(ui.style_mut());
}
let menu = widgets::MoreMenu::simple(ui, app)
.with_min_size(vec2(100.0, 0.0))
.with_max_size(vec2(160.0, f32::INFINITY));
.with_min_size(vec2(100.0, 0.0))
.with_max_size(vec2(160.0, f32::INFINITY));

menu.show(ui, |ui, is_open| {
ui.with_layout(egui::Layout::top_down_justified(egui::Align::LEFT), |ui| {
Expand Down Expand Up @@ -729,7 +738,10 @@ pub(super) fn render_more_list_actions(
*is_open = false;
}
}
if ui.add_enabled(count > 0, egui::Button::new("Clear All")).clicked() {
if ui
.add_enabled(count > 0, egui::Button::new("Clear All"))
.clicked()
{
app.people_list.clear_list_needs_confirm = true;
*is_open = false;
}
Expand Down
33 changes: 22 additions & 11 deletions gossip-bin/src/ui/people/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use egui_winit::egui::vec2;
use egui_winit::egui::InnerResponse;
use egui_winit::egui::Response;
use egui_winit::egui::Widget;
use gossip_lib::PersonList;
use gossip_lib::comms::ToOverlordMessage;
use gossip_lib::DmChannel;
use gossip_lib::FeedKind;
use gossip_lib::Person;
use gossip_lib::PersonList;
use gossip_lib::GLOBALS;
use nostr_types::{PublicKey, RelayUrl};
use serde_json::Value;
Expand Down Expand Up @@ -188,7 +188,7 @@ fn content(app: &mut GossipUi, ctx: &Context, ui: &mut Ui, pubkey: PublicKey, pe
}

ui.add_space(10.0);
ui.horizontal(|ui|{
ui.horizontal(|ui| {
ui.add_space(10.0);
ui.heading("User lists");
});
Expand All @@ -206,10 +206,14 @@ fn content(app: &mut GossipUi, ctx: &Context, ui: &mut Ui, pubkey: PublicKey, pe
let membership = membership_map.get(&list);
let mut inlist = membership.is_some();

if ui.add(widgets::Switch::onoff(&app.theme, &mut inlist)).clicked() {
if ui
.add(widgets::Switch::onoff(&app.theme, &mut inlist))
.clicked()
{
if !inlist {
let _ =
GLOBALS.storage.remove_person_from_list(&pubkey, list, None);
let _ = GLOBALS
.storage
.remove_person_from_list(&pubkey, list, None);
} else {
let _ = GLOBALS.storage.add_person_to_list(
&pubkey,
Expand All @@ -220,13 +224,15 @@ fn content(app: &mut GossipUi, ctx: &Context, ui: &mut Ui, pubkey: PublicKey, pe
}
}

let title_response = ui.add_enabled(inlist, egui::Label::new(metadata.title));
let title_response =
ui.add_enabled(inlist, egui::Label::new(metadata.title));

if inlist && list != PersonList::Followed {
ui.add_space(20.0);

let mut private = !membership.unwrap_or(&false);
let switch_response = ui.add(widgets::Switch::onoff(&app.theme, &mut private));
let switch_response =
ui.add(widgets::Switch::onoff(&app.theme, &mut private));
if switch_response.clicked() {
let _ = GLOBALS
.storage
Expand All @@ -235,19 +241,24 @@ fn content(app: &mut GossipUi, ctx: &Context, ui: &mut Ui, pubkey: PublicKey, pe
}
ui.add_enabled(private, egui::Label::new("Private"));

let color = if private { ui.visuals().text_color() } else { ui.visuals().weak_text_color() };
let color = if private {
ui.visuals().text_color()
} else {
ui.visuals().weak_text_color()
};
let left = title_response.rect.right_center();
let right = switch_response.rect.left_center();
let points = [left + vec2(10.0,0.0), right + vec2(-10.0, 0.0)];
ui.painter().line_segment(points, egui::Stroke::new(1.0, color));
let points = [left + vec2(10.0, 0.0), right + vec2(-10.0, 0.0)];
ui.painter()
.line_segment(points, egui::Stroke::new(1.0, color));
}
});
}
}
});

ui.add_space(10.0);
ui.horizontal(|ui|{
ui.horizontal(|ui| {
ui.add_space(10.0);
ui.heading("More details");
});
Expand Down
43 changes: 30 additions & 13 deletions gossip-bin/src/ui/widgets/more_menu.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use eframe::epaint::PathShape;
use egui_winit::egui::{self, vec2, AboveOrBelow, Color32, Id, Rect, TextureHandle, Ui, Vec2, Align2};
use egui_winit::egui::{
self, vec2, AboveOrBelow, Align2, Color32, Id, Rect, TextureHandle, Ui, Vec2,
};

use crate::ui::GossipUi;

Expand Down Expand Up @@ -96,9 +98,10 @@ impl MoreMenu {
MoreMenuStyle::Simple => {
let text = egui::RichText::new("=").size(13.0);
ui.add(egui::Button::new(text))
},
}
MoreMenuStyle::Bubble => {
let (response, painter) = ui.allocate_painter(vec2(20.0, 20.0), egui::Sense::click());
let (response, painter) =
ui.allocate_painter(vec2(20.0, 20.0), egui::Sense::click());
let btn_rect = response.rect;
let color = if response.hovered() {
self.accent_color
Expand All @@ -113,7 +116,7 @@ impl MoreMenu {
);
painter.add(egui::Shape::mesh(mesh));
response
},
}
};

let response = response.on_hover_cursor(egui::CursorIcon::PointingHand);
Expand All @@ -132,7 +135,9 @@ impl MoreMenu {
}

let pos = response.rect.center();
let above_or_below = self.above_or_below.unwrap_or(select_above_or_below(ui, pos));
let above_or_below = self
.above_or_below
.unwrap_or(select_above_or_below(ui, pos));
let bg_color = ui.visuals().window_fill();
let (pivot, fixed_pos, polygon) = match above_or_below {
AboveOrBelow::Above => {
Expand All @@ -143,12 +148,18 @@ impl MoreMenu {
Align2::RIGHT_BOTTOM => origin_pos + vec2(super::DROPDOWN_DISTANCE, -5.0),
Align2::LEFT_BOTTOM => origin_pos + vec2(-super::DROPDOWN_DISTANCE, -5.0),
_ => origin_pos,
}
},
MoreMenuStyle::Bubble => match pivot {
Align2::RIGHT_BOTTOM => origin_pos + vec2(2.0 * super::DROPDOWN_DISTANCE, -super::DROPDOWN_DISTANCE),
Align2::LEFT_BOTTOM => origin_pos + vec2(-2.0 * super::DROPDOWN_DISTANCE, -super::DROPDOWN_DISTANCE),
Align2::RIGHT_BOTTOM => {
origin_pos
+ vec2(2.0 * super::DROPDOWN_DISTANCE, -super::DROPDOWN_DISTANCE)
}
Align2::LEFT_BOTTOM => {
origin_pos
+ vec2(-2.0 * super::DROPDOWN_DISTANCE, -super::DROPDOWN_DISTANCE)
}
_ => origin_pos,
}
},
};
let path = PathShape::convex_polygon(
[
Expand All @@ -170,12 +181,18 @@ impl MoreMenu {
Align2::RIGHT_TOP => origin_pos + vec2(super::DROPDOWN_DISTANCE, 5.0),
Align2::LEFT_TOP => origin_pos + vec2(-super::DROPDOWN_DISTANCE, 5.0),
_ => origin_pos,
}
},
MoreMenuStyle::Bubble => match pivot {
Align2::RIGHT_TOP => origin_pos + vec2(2.0 * super::DROPDOWN_DISTANCE, super::DROPDOWN_DISTANCE),
Align2::LEFT_TOP => origin_pos + vec2(-2.0 * super::DROPDOWN_DISTANCE, super::DROPDOWN_DISTANCE),
Align2::RIGHT_TOP => {
origin_pos
+ vec2(2.0 * super::DROPDOWN_DISTANCE, super::DROPDOWN_DISTANCE)
}
Align2::LEFT_TOP => {
origin_pos
+ vec2(-2.0 * super::DROPDOWN_DISTANCE, super::DROPDOWN_DISTANCE)
}
_ => origin_pos,
}
},
};
let path = PathShape::convex_polygon(
[
Expand Down
37 changes: 14 additions & 23 deletions gossip-lib/src/overlord/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,17 +244,13 @@ impl Overlord {
}

async fn apply_relay_assignment(&mut self, assignment: RelayAssignment) -> Result<(), Error> {
let mut jobs = vec![
RelayJob {
reason: RelayConnectionReason::Follow,
payload: ToMinionPayload {
job_id: rand::random::<u64>(),
detail: ToMinionPayloadDetail::SubscribeGeneralFeed(
assignment.pubkeys.clone(),
),
},
let mut jobs = vec![RelayJob {
reason: RelayConnectionReason::Follow,
payload: ToMinionPayload {
job_id: rand::random::<u64>(),
detail: ToMinionPayloadDetail::SubscribeGeneralFeed(assignment.pubkeys.clone()),
},
];
}];

// Until NIP-65 is in widespread use, we should listen for mentions
// of us on all these relays too
Expand All @@ -269,23 +265,18 @@ impl Overlord {
}
}
if fetch_mentions {
jobs.push(
RelayJob {
reason: RelayConnectionReason::FetchMentions,
payload: ToMinionPayload {
job_id: rand::random::<u64>(),
detail: ToMinionPayloadDetail::SubscribeMentions,
},
jobs.push(RelayJob {
reason: RelayConnectionReason::FetchMentions,
payload: ToMinionPayload {
job_id: rand::random::<u64>(),
detail: ToMinionPayloadDetail::SubscribeMentions,
},
);
});
}

// Subscribe to the general feed
self.engage_minion(
assignment.relay_url.clone(),
jobs
)
.await?;
self.engage_minion(assignment.relay_url.clone(), jobs)
.await?;

Ok(())
}
Expand Down

0 comments on commit f55db80

Please sign in to comment.