1mod nostr;
2mod tests;
3use nostro2::notes::{NostrNote, NostrTag, NoteTags, TagList};
4use serde::{Deserialize, Serialize};
5
6#[allow(clippy::derive_partial_eq_without_eq)]
7#[derive(Clone, Copy, PartialEq, ::prost::Message)]
8pub struct Empty {}
9#[derive(Clone, Copy, PartialEq, ::prost::Message)]
10pub struct LoginRole {
11 #[prost(bool, tag = "1")]
12 pub is_admin: bool,
13}
14#[allow(clippy::derive_partial_eq_without_eq)]
15#[derive(Clone, PartialEq, Serialize, Deserialize, ::prost::Message)]
16pub struct GrpcNostrNoteId {
17 #[prost(string, tag = "1")]
18 pub id: ::prost::alloc::string::String,
19}
20#[allow(clippy::derive_partial_eq_without_eq)]
21#[derive(Clone, PartialEq, Serialize, Deserialize, ::prost::Message)]
22pub struct GrpcNostrNoteTag {
23 #[prost(string, repeated, tag = "1")]
24 pub tag: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
25}
26impl GrpcNostrNoteTag {
27 pub fn to_vec(&self) -> Vec<String> {
28 self.tag.clone()
29 }
30}
31#[allow(clippy::derive_partial_eq_without_eq)]
32#[derive(Clone, PartialEq, Serialize, Deserialize, ::prost::Message)]
33pub struct GrpcNostrNote {
34 #[prost(string, tag = "1")]
35 pub content: ::prost::alloc::string::String,
36 #[prost(uint32, tag = "2")]
37 pub kind: u32,
38 #[prost(string, tag = "3")]
39 pub pubkey: ::prost::alloc::string::String,
40 #[prost(int64, tag = "4")]
41 pub created_at: i64,
42 #[prost(message, repeated, tag = "5")]
43 pub tags: ::prost::alloc::vec::Vec<GrpcNostrNoteTag>,
44 #[prost(string, tag = "6")]
45 pub id: ::prost::alloc::string::String,
46 #[prost(string, tag = "7")]
47 pub sig: ::prost::alloc::string::String,
48}
49impl From<NostrNote> for GrpcNostrNote {
50 fn from(note: NostrNote) -> Self {
51 let tags = note
52 .tags
53 .0
54 .iter()
55 .map(|tag| GrpcNostrNoteTag {
56 tag: {
57 let mut tags = vec![];
58 match tag.tag_type {
59 NostrTag::Pubkey => tags.push("p".to_string()),
60 NostrTag::Parameterized => tags.push("d".to_string()),
61 NostrTag::Event => tags.push("e".to_string()),
62 NostrTag::Custom(custom) => tags.push(custom.to_string()),
63 }
64 tags.extend(tag.tags.clone());
65 tags
66 },
67 })
68 .collect();
69 GrpcNostrNote {
70 content: note.content.clone(),
71 kind: note.kind,
72 pubkey: note.pubkey.clone(),
73 created_at: note.created_at,
74 tags,
75 id: note.id.clone().unwrap_or_default(),
76 sig: note.sig.clone().unwrap_or_default(),
77 }
78 }
79}
80impl Into<NostrNote> for GrpcNostrNote {
81 fn into(self) -> NostrNote {
82 let tags = self
83 .tags
84 .iter()
85 .filter_map(|tag| {
86 let tag_list = TagList {
87 tag_type: {
88 let first = tag.tag.first()?;
89 match first.as_str() {
90 "p" => NostrTag::Pubkey,
91 "d" => NostrTag::Parameterized,
92 "e" => NostrTag::Event,
93 other => {
94 NostrTag::Custom(Box::leak(other.to_string().into_boxed_str()))
95 }
96 }
97 },
98 tags: tag.tag.iter().skip(1).map(|tag| tag.clone()).collect(),
99 };
100 Some(tag_list)
101 })
102 .collect::<Vec<TagList>>();
103 NostrNote {
104 pubkey: self.pubkey,
105 kind: self.kind,
106 content: self.content,
107 created_at: self.created_at,
108 tags: NoteTags(tags),
109 id: Some(self.id),
110 sig: Some(self.sig),
111 }
112 }
113}
114impl TryFrom<String> for GrpcNostrNote {
115 type Error = serde_json::Error;
116 fn try_from(json: String) -> Result<Self, Self::Error> {
117 serde_json::from_str(&json)
118 }
119}
120impl TryFrom<&str> for GrpcNostrNote {
121 type Error = serde_json::Error;
122 fn try_from(json: &str) -> Result<Self, Self::Error> {
123 serde_json::from_str(json)
124 }
125}
126#[allow(clippy::derive_partial_eq_without_eq)]
127#[derive(Clone, PartialEq, Serialize, Deserialize, ::prost::Message)]
128pub struct GrpcNostrNoteList {
129 #[prost(message, repeated, tag = "1")]
130 pub events: ::prost::alloc::vec::Vec<GrpcNostrNote>,
131}
132impl GrpcNostrNoteList {
133 pub fn to_signed_note_vec(&self) -> Vec<NostrNote> {
134 self.events
135 .iter()
136 .map(|event| (*event).clone().into())
137 .collect()
138 }
139}
140#[allow(clippy::derive_partial_eq_without_eq)]
141#[derive(Clone, PartialEq, ::prost::Message)]
142pub struct Filter {
143 #[prost(string, repeated, tag = "1")]
144 pub authors: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
145 #[prost(uint32, repeated, tag = "2")]
146 pub kinds: ::prost::alloc::vec::Vec<u32>,
147 #[prost(string, repeated, tag = "3")]
148 pub ids: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
149 #[prost(uint32, tag = "4")]
150 pub since: u32,
151 #[prost(uint32, tag = "5")]
152 pub until: u32,
153 #[prost(uint32, tag = "6")]
154 pub limit: u32,
155}
156#[allow(clippy::derive_partial_eq_without_eq)]
157#[derive(Clone, PartialEq, ::prost::Message)]
158pub struct FilterTag {
159 #[prost(string, repeated, tag = "1")]
160 pub parameter: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
161}