hippofish/packages/backend-rs/src/service/add_note_to_antenna.rs

21 lines
661 B
Rust
Raw Normal View History

use crate::database::{redis_conn, redis_key};
use crate::service::stream::{publish_to_stream, Error, Stream};
use crate::util::id::get_timestamp;
use redis::{streams::StreamMaxlen, Commands};
#[crate::export]
pub fn add_note_to_antenna(antenna_id: String, note_id: &str) -> Result<(), Error> {
redis_conn()?.xadd_maxlen(
redis_key(format!("antennaTimeline:{}", antenna_id)),
StreamMaxlen::Approx(200),
format!("{}-*", get_timestamp(note_id)),
&[("note", note_id)],
)?;
publish_to_stream(
&Stream::Antenna { antenna_id },
Some("note"),
Some(format!("{{ \"id\": \"{}\" }}", note_id)),
)
}