[retention] Add setting for auto removing notifications
This commit is contained in:
@ -54,6 +54,8 @@ mod imp {
|
||||
pub muted: Cell<bool>,
|
||||
#[property(get)]
|
||||
pub unread_count: Cell<u32>,
|
||||
#[property(get)]
|
||||
pub retention_hours: Cell<u32>,
|
||||
pub read_until: Cell<u64>,
|
||||
pub messages: gio::ListStore,
|
||||
pub client: OnceCell<ntfy_daemon::SubscriptionHandle>,
|
||||
@ -79,6 +81,7 @@ mod imp {
|
||||
client: Default::default(),
|
||||
unread_count: Default::default(),
|
||||
read_until: Default::default(),
|
||||
retention_hours: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -124,6 +127,7 @@ impl Subscription {
|
||||
muted: bool,
|
||||
read_until: u64,
|
||||
display_name: &str,
|
||||
retention_hours: u32,
|
||||
) {
|
||||
let imp = self.imp();
|
||||
imp.topic.replace(topic.to_string());
|
||||
@ -134,6 +138,8 @@ impl Subscription {
|
||||
self.notify_muted();
|
||||
imp.read_until.replace(read_until);
|
||||
self.notify_unread_count();
|
||||
imp.retention_hours.replace(retention_hours);
|
||||
self.notify_retention_hours();
|
||||
self._set_display_name(display_name.to_string());
|
||||
}
|
||||
|
||||
@ -149,6 +155,7 @@ impl Subscription {
|
||||
model.muted,
|
||||
model.read_until,
|
||||
&model.display_name,
|
||||
model.retention_hours,
|
||||
);
|
||||
|
||||
let (prev_msgs, mut rx) = remote_subscription.attach().await;
|
||||
@ -214,8 +221,9 @@ impl Subscription {
|
||||
.unwrap()
|
||||
.update_info(
|
||||
models::Subscription::builder(self.topic())
|
||||
.display_name((imp.display_name.borrow().to_string()))
|
||||
.display_name(imp.display_name.borrow().to_string())
|
||||
.muted(imp.muted.get())
|
||||
.retention_hours(imp.retention_hours.get())
|
||||
.build()
|
||||
.map_err(|e| anyhow::anyhow!("invalid subscription data {:?}", e))?,
|
||||
)
|
||||
@ -249,6 +257,15 @@ impl Subscription {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub fn set_retention_hours(&self, value: u32) -> impl Future<Output = anyhow::Result<()>> {
|
||||
let this = self.clone();
|
||||
async move {
|
||||
this.imp().retention_hours.replace(value);
|
||||
this.notify_retention_hours();
|
||||
this.send_updated_info().await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub async fn flag_all_as_read(&self) -> anyhow::Result<()> {
|
||||
let imp = self.imp();
|
||||
let Some(value) = Self::last_message(&imp.messages)
|
||||
|
||||
@ -20,6 +20,8 @@ mod imp {
|
||||
pub display_name_entry: TemplateChild<adw::EntryRow>,
|
||||
#[template_child]
|
||||
pub muted_switch_row: TemplateChild<adw::SwitchRow>,
|
||||
#[template_child]
|
||||
pub retention_hours_spin_row: TemplateChild<adw::SpinRow>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
@ -47,6 +49,12 @@ mod imp {
|
||||
.set_text(&this.subscription().unwrap().display_name());
|
||||
self.muted_switch_row
|
||||
.set_active(this.subscription().unwrap().muted());
|
||||
self.retention_hours_spin_row
|
||||
.set_value(this.subscription().unwrap().retention_hours() as f64);
|
||||
let adj = self.retention_hours_spin_row.adjustment();
|
||||
adj.set_upper(8760.0);
|
||||
adj.set_step_increment(1.0);
|
||||
adj.set_page_increment(24.0);
|
||||
|
||||
let debouncer = crate::async_utils::Debouncer::new();
|
||||
self.display_name_entry.connect_changed({
|
||||
@ -64,6 +72,14 @@ mod imp {
|
||||
this.update_muted(switch);
|
||||
}
|
||||
});
|
||||
let this = self.obj().clone();
|
||||
self.retention_hours_spin_row
|
||||
.adjustment()
|
||||
.connect_value_changed({
|
||||
move |adj| {
|
||||
this.update_retention_hours(adj.value() as u32);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
impl WidgetImpl for SubscriptionInfoDialog {}
|
||||
@ -99,4 +115,11 @@ impl SubscriptionInfoDialog {
|
||||
.spawn(async move { sub.set_muted(switch.is_active()).await })
|
||||
}
|
||||
}
|
||||
fn update_retention_hours(&self, value: u32) {
|
||||
if let Some(sub) = self.subscription() {
|
||||
let sub = sub.clone();
|
||||
self.error_boundary()
|
||||
.spawn(async move { sub.set_retention_hours(value).await })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user