migrate to check following through Contacts::is_following
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -1,58 +1,5 @@
|
||||
use nostrdb::{Filter, Ndb, Note, Transaction};
|
||||
|
||||
fn pk1_is_following_pk2(
|
||||
ndb: &Ndb,
|
||||
txn: &Transaction,
|
||||
pk1: &[u8; 32],
|
||||
pk2: &[u8; 32],
|
||||
) -> Option<bool> {
|
||||
let note = get_contacts_note(ndb, txn, pk1)?;
|
||||
|
||||
Some(note_follows(note, pk2))
|
||||
}
|
||||
|
||||
pub fn trust_media_from_pk2(
|
||||
ndb: &Ndb,
|
||||
txn: &Transaction,
|
||||
pk1: Option<&[u8; 32]>,
|
||||
pk2: &[u8; 32],
|
||||
) -> bool {
|
||||
pk1.map(|pk| pk == pk2 || pk1_is_following_pk2(ndb, txn, pk, pk2).unwrap_or(false))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn get_contacts_note<'a>(ndb: &'a Ndb, txn: &'a Transaction, user: &[u8; 32]) -> Option<Note<'a>> {
|
||||
Some(
|
||||
ndb.query(txn, &[contacts_filter(user)], 1)
|
||||
.ok()?
|
||||
.first()?
|
||||
.note
|
||||
.clone(),
|
||||
)
|
||||
}
|
||||
use nostrdb::Filter;
|
||||
|
||||
pub fn contacts_filter(pk: &[u8; 32]) -> Filter {
|
||||
Filter::new().authors([pk]).kinds([3]).limit(1).build()
|
||||
}
|
||||
|
||||
fn note_follows(contacts_note: Note<'_>, pk: &[u8; 32]) -> bool {
|
||||
for tag in contacts_note.tags() {
|
||||
if tag.count() < 2 {
|
||||
continue;
|
||||
}
|
||||
|
||||
let Some("p") = tag.get_str(0) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let Some(author) = tag.get_id(1) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
if pk == author {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ use std::cell::OnceCell;
|
||||
|
||||
use crate::{
|
||||
blur::imeta_blurhashes,
|
||||
contacts::trust_media_from_pk2,
|
||||
jobs::JobsCache,
|
||||
note::{NoteAction, NoteOptions, NoteResponse, NoteView},
|
||||
};
|
||||
@@ -11,7 +10,7 @@ use egui::{Color32, Hyperlink, RichText};
|
||||
use nostrdb::{BlockType, Mention, Note, NoteKey, Transaction};
|
||||
use tracing::warn;
|
||||
|
||||
use notedeck::NoteContext;
|
||||
use notedeck::{IsFollowing, NoteContext};
|
||||
|
||||
use super::media::{find_renderable_media, image_carousel, RenderableMedia};
|
||||
|
||||
@@ -284,11 +283,11 @@ pub fn render_note_contents(
|
||||
ui.add_space(2.0);
|
||||
let carousel_id = egui::Id::new(("carousel", note.key().expect("expected tx note")));
|
||||
|
||||
let zapping_acc = {
|
||||
let cur_acc = note_context.accounts.get_selected_account();
|
||||
cur_acc.wallet.as_ref().map(|_| cur_acc.key.pubkey.bytes())
|
||||
};
|
||||
let trusted_media = trust_media_from_pk2(note_context.ndb, txn, zapping_acc, note.pubkey());
|
||||
let trusted_media = note_context
|
||||
.accounts
|
||||
.get_selected_account()
|
||||
.is_following(note.pubkey())
|
||||
== IsFollowing::Yes;
|
||||
|
||||
media_action = image_carousel(
|
||||
ui,
|
||||
|
||||
Reference in New Issue
Block a user