mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-06-12 09:24:29 +02:00
Support list of notifications
This commit is contained in:
@@ -5,6 +5,7 @@ use chrono::{DateTime, Duration, Utc};
|
|||||||
use log::debug;
|
use log::debug;
|
||||||
use reqwest::Method;
|
use reqwest::Method;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_json::Value;
|
||||||
use tauri::{Emitter, Manager, Runtime, WebviewWindow};
|
use tauri::{Emitter, Manager, Runtime, WebviewWindow};
|
||||||
use yaak_models::queries::{get_key_value_raw, set_key_value_raw, UpdateSource};
|
use yaak_models::queries::{get_key_value_raw, set_key_value_raw, UpdateSource};
|
||||||
|
|
||||||
@@ -74,17 +75,29 @@ impl YaakNotifier {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let notification = resp.json::<YaakNotification>().await.map_err(|e| e.to_string())?;
|
let result = resp.json::<Value>().await.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
let age = notification.timestamp.signed_duration_since(Utc::now());
|
// Support both single and multiple notifications.
|
||||||
let seen = get_kv(window).await?;
|
// TODO: Remove support for single after April 2025
|
||||||
if seen.contains(¬ification.id) || (age > Duration::days(2)) {
|
let notifications = match result {
|
||||||
debug!("Already seen notification {}", notification.id);
|
Value::Array(a) => a
|
||||||
return Ok(());
|
.into_iter()
|
||||||
|
.map(|a| serde_json::from_value(a).unwrap())
|
||||||
|
.collect::<Vec<YaakNotification>>(),
|
||||||
|
a @ _ => vec![serde_json::from_value(a).unwrap()],
|
||||||
|
};
|
||||||
|
|
||||||
|
for notification in notifications {
|
||||||
|
let age = notification.timestamp.signed_duration_since(Utc::now());
|
||||||
|
let seen = get_kv(window).await?;
|
||||||
|
if seen.contains(¬ification.id) || (age > Duration::days(2)) {
|
||||||
|
debug!("Already seen notification {}", notification.id);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
debug!("Got notification {:?}", notification);
|
||||||
|
|
||||||
|
let _ = window.emit_to(window.label(), "notification", notification.clone());
|
||||||
}
|
}
|
||||||
debug!("Got notification {:?}", notification);
|
|
||||||
|
|
||||||
let _ = window.emit_to(window.label(), "notification", notification.clone());
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user