2024-04-19 23:54:06 +02:00
|
|
|
use crate::database::{redis_conn, redis_key};
|
|
|
|
use crate::model::entity::note;
|
|
|
|
use crate::service::stream::{publish, Error, Stream};
|
|
|
|
use crate::util::id::get_timestamp;
|
|
|
|
use redis::{streams::StreamMaxlen, Commands};
|
|
|
|
|
|
|
|
#[crate::export]
|
|
|
|
pub fn add_note_to_antenna(antenna_id: &str, note: ¬e::Model) -> Result<(), Error> {
|
|
|
|
redis_conn()?.xadd_maxlen(
|
|
|
|
redis_key(format!("antennaTimeline:{}", antenna_id)),
|
|
|
|
StreamMaxlen::Approx(200),
|
|
|
|
format!("{}-*", get_timestamp(¬e.id)),
|
|
|
|
&[("note", ¬e.id)],
|
|
|
|
)?;
|
|
|
|
|
|
|
|
let stream = Stream::Antenna {
|
|
|
|
id: antenna_id.to_string(),
|
|
|
|
};
|
2024-04-20 02:54:02 +02:00
|
|
|
publish(&stream, Some("note"), Some(serde_json::to_string(note)?))
|
2024-04-19 23:54:06 +02:00
|
|
|
}
|