Show encrypted DMs in inbox (can not reply yet; cannot generate them yet)

This commit is contained in:
Mike Dilger 2023-02-23 12:44:36 +13:00
parent 1a23be6975
commit cfac07699b
6 changed files with 47 additions and 15 deletions

View File

@ -105,9 +105,9 @@ impl DbEvent {
};
let kinds = if GLOBALS.settings.read().await.reactions {
"(1, 5, 6, 7)"
"(1, 4, 5, 6, 7)"
} else {
"(1, 5, 6)"
"(1, 4, 5, 6)"
};
let sql = format!(

View File

@ -129,7 +129,9 @@ impl Feed {
.iter()
.map(|r| r.value().to_owned())
.filter(|e| {
e.kind == EventKind::TextNote || (enable_reposts && (e.kind == EventKind::Repost))
e.kind == EventKind::TextNote
|| e.kind == EventKind::EncryptedDirectMessage
|| (enable_reposts && (e.kind == EventKind::Repost))
})
.filter(|e| e.pubkey.as_hex_string() == person.as_str())
.filter(|e| !GLOBALS.dismissed.blocking_read().contains(&e.id))
@ -173,7 +175,9 @@ impl Feed {
.iter()
.map(|r| r.value().to_owned())
.filter(|e| {
e.kind == EventKind::TextNote || (settings.reposts && (e.kind == EventKind::Repost))
e.kind == EventKind::TextNote
|| e.kind == EventKind::EncryptedDirectMessage
|| (settings.reposts && (e.kind == EventKind::Repost))
})
.collect();
@ -252,6 +256,7 @@ impl Feed {
})
.cloned()
.collect();
revents.sort_by(|a, b| b.created_at.cmp(&a.created_at));
*self.replies_feed.write() = revents.iter().map(|e| e.id).collect();
}

View File

@ -540,7 +540,7 @@ impl Minion {
// Any mentions of me
// (but not in peoples contact lists, for example)
let mut kinds = vec![EventKind::TextNote];
let mut kinds = vec![EventKind::TextNote, EventKind::EncryptedDirectMessage];
if enable_reactions {
kinds.push(EventKind::Reaction);
}

View File

@ -244,4 +244,11 @@ impl Signer {
Ok(())
}
pub fn decrypt_message(&self, event: &Event) -> Result<String, Error> {
match &*self.private.read() {
Some(private) => Ok(event.decrypted_contents(private)?),
_ => Err(Error::NoPrivateKey),
}
}
}

View File

@ -4,7 +4,7 @@ use crate::globals::GLOBALS;
use eframe::egui;
use egui::{RichText, Ui};
use linkify::{LinkFinder, LinkKind};
use nostr_types::{Event, IdHex, Tag};
use nostr_types::{Event, EventKind, IdHex, Tag};
pub(super) fn render_content(
app: &mut GossipUi,
@ -15,11 +15,18 @@ pub(super) fn render_content(
override_content: Option<String>,
) {
let content = match override_content {
Some(ref s) => s,
None => &event.content,
Some(s) => s,
None => match event.kind {
EventKind::TextNote | EventKind::Repost => event.content.clone(),
EventKind::EncryptedDirectMessage => match GLOBALS.signer.decrypt_message(event) {
Ok(m) => m,
Err(_) => "DECRYPTION FAILED".to_owned(),
},
_ => "NON FEED RELATED EVENT".to_owned(),
},
};
for span in LinkFinder::new().kinds(&[LinkKind::Url]).spans(content) {
for span in LinkFinder::new().kinds(&[LinkKind::Url]).spans(&content) {
if span.kind().is_some() {
ui.hyperlink_to(span.as_str(), span.as_str());
} else {

View File

@ -258,9 +258,12 @@ fn render_post_actual(
let top = ui.next_widget_position();
// Only render TextNote events
// Only render known relevent events
let enable_reposts = GLOBALS.settings.blocking_read().reposts;
if event.kind != EventKind::TextNote && !(enable_reposts && (event.kind == EventKind::Repost)) {
if event.kind != EventKind::TextNote
&& !(enable_reposts && (event.kind == EventKind::Repost))
&& event.kind != EventKind::EncryptedDirectMessage
{
return;
}
@ -426,6 +429,15 @@ fn render_post_inner(
ui.label(RichText::new("REPOSTED").color(color));
}
if event.kind == EventKind::EncryptedDirectMessage {
let color = if ui.visuals().dark_mode {
Color32::LIGHT_BLUE
} else {
Color32::DARK_BLUE
};
ui.label(RichText::new("ENCRYPTED DM").color(color));
}
ui.with_layout(Layout::right_to_left(Align::TOP), |ui| {
ui.menu_button(RichText::new("📃▼").size(13.0), |ui| {
if !is_main_event && ui.button("View Thread").clicked() {
@ -574,10 +586,11 @@ fn render_post_inner(
ui.add_space(24.0);
// Button to reply
if ui
.add(Label::new(RichText::new("💬").size(18.0)).sense(Sense::click()))
.on_hover_text("Reply")
.clicked()
if event.kind != EventKind::EncryptedDirectMessage
&& ui
.add(Label::new(RichText::new("💬").size(18.0)).sense(Sense::click()))
.on_hover_text("Reply")
.clicked()
{
app.replying_to = Some(event.id);
}