implement a method for post type
This commit is contained in:
parent
d7c654fcb4
commit
920141e0ce
23
src/db.rs
23
src/db.rs
|
@ -73,6 +73,29 @@ pub struct Post {
|
|||
pub subject: Option<String>,
|
||||
}
|
||||
|
||||
impl Post {
|
||||
/// Create a new instance of the Post struct. A default value of `false` is
|
||||
/// set for `read`.
|
||||
pub fn new(
|
||||
key: String,
|
||||
text: String,
|
||||
date: String,
|
||||
sequence: u64,
|
||||
timestamp: i64,
|
||||
subject: Option<String>,
|
||||
) -> Post {
|
||||
Post {
|
||||
key,
|
||||
text,
|
||||
date,
|
||||
sequence,
|
||||
timestamp,
|
||||
subject,
|
||||
read: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An instance of the key-value database and relevant trees.
|
||||
#[allow(dead_code)]
|
||||
#[derive(Clone)]
|
||||
|
|
20
src/sbot.rs
20
src/sbot.rs
|
@ -183,24 +183,24 @@ pub async fn get_root_posts(
|
|||
let content = msg.value.content.to_owned();
|
||||
if let Value::Object(content_map) = content {
|
||||
if !content_map.contains_key("root") {
|
||||
latest_sequence = msg.value.sequence;
|
||||
|
||||
let text = content_map.get_key_value("text").unwrap().1.to_string();
|
||||
let timestamp = msg.value.timestamp.round() as i64 / 1000;
|
||||
let datetime = NaiveDateTime::from_timestamp(timestamp, 0);
|
||||
let date = datetime.format("%d %b %Y").to_string();
|
||||
|
||||
let text = content_map.get_key_value("text").unwrap().1.to_string();
|
||||
let subject = text.get(0..52).map(|s| s.to_string());
|
||||
|
||||
latest_sequence = msg.value.sequence;
|
||||
|
||||
posts.push(Post {
|
||||
key: msg.key.to_owned(),
|
||||
let post = Post::new(
|
||||
msg.key.to_owned(),
|
||||
text,
|
||||
timestamp,
|
||||
date,
|
||||
sequence: msg.value.sequence,
|
||||
read: false,
|
||||
msg.value.sequence,
|
||||
timestamp,
|
||||
subject,
|
||||
})
|
||||
);
|
||||
|
||||
posts.push(post)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue