2024-04-19 23:54:06 +02:00
|
|
|
use crate::database::{redis_conn, redis_key};
|
2024-04-21 15:43:09 +02:00
|
|
|
use crate::service::stream::{publish_to_stream, Error, Stream};
|
2024-04-19 23:54:06 +02:00
|
|
|
use crate::util::id::get_timestamp;
|
|
|
|
use redis::{streams::StreamMaxlen, Commands};
|
|
|
|
|
|
|
|
#[crate::export]
|
2024-04-21 17:30:59 +02:00
|
|
|
pub fn add_note_to_antenna(antenna_id: String, note_id: &str) -> Result<(), Error> {
|
2024-04-19 23:54:06 +02:00
|
|
|
redis_conn()?.xadd_maxlen(
|
|
|
|
redis_key(format!("antennaTimeline:{}", antenna_id)),
|
|
|
|
StreamMaxlen::Approx(200),
|
2024-04-21 15:40:58 +02:00
|
|
|
format!("{}-*", get_timestamp(note_id)),
|
|
|
|
&[("note", note_id)],
|
2024-04-19 23:54:06 +02:00
|
|
|
)?;
|
|
|
|
|
2024-04-21 15:43:09 +02:00
|
|
|
publish_to_stream(
|
2024-04-21 17:30:59 +02:00
|
|
|
&Stream::Antenna { antenna_id },
|
2024-04-20 22:47:11 +02:00
|
|
|
Some("note"),
|
|
|
|
Some(format!("{{ \"id\": \"{}\" }}", note_id)),
|
|
|
|
)
|
2024-04-19 23:54:06 +02:00
|
|
|
}
|