commit ad8bc9e6c3c9eb7107b764166a1679188ef98afb
parent 41c36ac7bade06c2902ebcdce32503b32af6e621
Author: William Casarin <jb55@jb55.com>
Date: Thu, 6 Jul 2023 19:38:49 -0700
enostr: add initial note code
Diffstat:
A | enostr/src/note.rs | | | 91 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 91 insertions(+), 0 deletions(-)
diff --git a/enostr/src/note.rs b/enostr/src/note.rs
@@ -0,0 +1,91 @@
+use crate::Event;
+use shatter::shard::Shards;
+
+#[derive(Debug, Eq, PartialEq)]
+struct RefId(i32);
+
+struct Ref<'a> {
+ ref_tag: u8,
+ relay_id: Option<&'a str>,
+ id: &'a str,
+}
+
+impl<'a> RefId {
+ fn get_ref(self, tags: &'a Vec<Vec<String>>) -> Option<Ref<'a>> {
+ let ind = self.0 as usize;
+
+ if ind > tags.len() - 1 {
+ return None;
+ }
+
+ let tag = &tags[ind];
+
+ if tag.len() < 2 {
+ return None;
+ }
+
+ if tag[0].len() != 1 {
+ return None;
+ }
+
+ let ref_tag = if let Some(rtag) = tag[0].as_bytes().first() {
+ *rtag
+ } else {
+ 0
+ };
+
+ let id = &tag[1];
+ if id.len() != 64 {
+ return None;
+ }
+
+ let relay_id = if tag[2].len() == 0 {
+ None
+ } else {
+ Some(&*tag[2])
+ };
+
+ Some(Ref {
+ ref_tag,
+ relay_id,
+ id,
+ })
+ }
+}
+
+enum MentionType {
+ Pubkey,
+ Event,
+}
+
+struct Mention {
+ index: Option<i32>,
+ typ: MentionType,
+ refid: RefId,
+}
+
+enum EventRef {
+ Mention(Mention),
+ ThreadId(RefId),
+ Reply(RefId),
+ ReplyToRoot(RefId),
+}
+
+struct EventRefs {
+ refs: Vec<EventRef>,
+}
+
+struct TextNote {
+ event: Event,
+ shards: Shards,
+ refs: EventRefs,
+}
+
+struct DM {
+ decrypted: Option<String>,
+ shards: Shards,
+}
+
+enum Note {
+ Text(TextNote),
+}