commit 86f87fa0a522b0e15b0fad17ec32371c34692da0
parent 6b634646d5dcc4b879259cc3fd83c407fde09649
Author: William Casarin <jb55@jb55.com>
Date: Tue, 16 Jul 2024 12:29:56 -0700
noteref: move to note.rs
This doesn't need to be in timeline
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
3 files changed, 40 insertions(+), 25 deletions(-)
diff --git a/src/app.rs b/src/app.rs
@@ -6,11 +6,12 @@ use crate::error::Error;
use crate::frame_history::FrameHistory;
use crate::imgcache::ImageCache;
use crate::key_storage::KeyStorageType;
+use crate::note::NoteRef;
use crate::notecache::{CachedNote, NoteCache};
use crate::relay_pool_manager::RelayPoolManager;
use crate::route::Route;
use crate::timeline;
-use crate::timeline::{MergeKind, NoteRef, Timeline, ViewFilter};
+use crate::timeline::{MergeKind, Timeline, ViewFilter};
use crate::ui::note::PostAction;
use crate::ui::{self, AccountSelectionWidget, DesktopGlobalPopup};
use crate::ui::{DesktopSidePanel, RelayView, View};
diff --git a/src/note.rs b/src/note.rs
@@ -1 +1,37 @@
+use nostrdb::{NoteKey, QueryResult};
+use std::cmp::Ordering;
+#[derive(Debug, Eq, PartialEq, Copy, Clone)]
+pub struct NoteRef {
+ pub key: NoteKey,
+ pub created_at: u64,
+}
+
+impl NoteRef {
+ pub fn new(key: NoteKey, created_at: u64) -> Self {
+ NoteRef { key, created_at }
+ }
+
+ pub fn from_query_result(qr: QueryResult<'_>) -> Self {
+ NoteRef {
+ key: qr.note_key,
+ created_at: qr.note.created_at(),
+ }
+ }
+}
+
+impl Ord for NoteRef {
+ fn cmp(&self, other: &Self) -> Ordering {
+ match self.created_at.cmp(&other.created_at) {
+ Ordering::Equal => self.key.cmp(&other.key),
+ Ordering::Less => Ordering::Greater,
+ Ordering::Greater => Ordering::Less,
+ }
+ }
+}
+
+impl PartialOrd for NoteRef {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ Some(self.cmp(other))
+ }
+}
diff --git a/src/timeline.rs b/src/timeline.rs
@@ -1,4 +1,5 @@
use crate::draft::DraftSource;
+use crate::note::NoteRef;
use crate::notecache::CachedNote;
use crate::ui::note::PostAction;
use crate::{ui, Damus};
@@ -11,35 +12,12 @@ use crate::ui::BarAction;
use egui_tabs::TabColor;
use egui_virtual_list::VirtualList;
use enostr::{Filter, NoteId};
-use nostrdb::{Note, NoteKey, Subscription, Transaction};
+use nostrdb::{Note, Subscription, Transaction};
use std::cell::RefCell;
-use std::cmp::Ordering;
use std::rc::Rc;
use tracing::{debug, info, warn};
-#[derive(Debug, Eq, PartialEq, Copy, Clone)]
-pub struct NoteRef {
- pub key: NoteKey,
- pub created_at: u64,
-}
-
-impl Ord for NoteRef {
- fn cmp(&self, other: &Self) -> Ordering {
- match self.created_at.cmp(&other.created_at) {
- Ordering::Equal => self.key.cmp(&other.key),
- Ordering::Less => Ordering::Greater,
- Ordering::Greater => Ordering::Less,
- }
- }
-}
-
-impl PartialOrd for NoteRef {
- fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
- Some(self.cmp(other))
- }
-}
-
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum ViewFilter {
Notes,