minor refactors, add OutgoingMessage
This commit is contained in:
@ -227,12 +227,12 @@ impl Subscription {
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
fn last_message(list: &gio::ListStore) -> Option<models::Message> {
|
||||
fn last_message(list: &gio::ListStore) -> Option<models::ReceivedMessage> {
|
||||
let n = list.n_items();
|
||||
let last = list
|
||||
.item(n.checked_sub(1)?)
|
||||
.and_downcast::<glib::BoxedAnyObject>()?;
|
||||
let last = last.borrow::<models::Message>();
|
||||
let last = last.borrow::<models::ReceivedMessage>();
|
||||
Some(last.clone())
|
||||
}
|
||||
fn update_unread_count(&self) {
|
||||
@ -275,7 +275,7 @@ impl Subscription {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
pub async fn publish_msg(&self, mut msg: models::Message) -> anyhow::Result<()> {
|
||||
pub async fn publish_msg(&self, mut msg: models::OutgoingMessage) -> anyhow::Result<()> {
|
||||
let imp = self.imp();
|
||||
let json = {
|
||||
msg.topic = self.topic();
|
||||
|
||||
@ -166,7 +166,7 @@ impl AddSubscriptionDialog {
|
||||
obj.set_content_width(480);
|
||||
obj.set_child(Some(&toolbar_view));
|
||||
}
|
||||
pub fn subscription(&self) -> Result<models::Subscription, Vec<ntfy_daemon::Error>> {
|
||||
pub fn subscription(&self) -> Result<models::Subscription, ntfy_daemon::Error> {
|
||||
let w = { self.imp().widgets.borrow().clone() };
|
||||
let mut sub = models::Subscription::builder(w.topic_entry.text().to_string());
|
||||
if w.server_expander.enables_expansion() {
|
||||
@ -183,7 +183,7 @@ impl AddSubscriptionDialog {
|
||||
w.topic_entry.remove_css_class("error");
|
||||
w.sub_btn.set_sensitive(true);
|
||||
|
||||
if let Err(errs) = sub {
|
||||
if let Err(ntfy_daemon::Error::InvalidSubscription(errs)) = sub {
|
||||
w.sub_btn.set_sensitive(false);
|
||||
for e in errs {
|
||||
match e {
|
||||
|
||||
@ -34,12 +34,12 @@ glib::wrapper! {
|
||||
}
|
||||
|
||||
impl MessageRow {
|
||||
pub fn new(msg: models::Message) -> Self {
|
||||
pub fn new(msg: models::ReceivedMessage) -> Self {
|
||||
let this: Self = glib::Object::new();
|
||||
this.build_ui(msg);
|
||||
this
|
||||
}
|
||||
fn build_ui(&self, msg: models::Message) {
|
||||
fn build_ui(&self, msg: models::ReceivedMessage) {
|
||||
self.set_margin_top(8);
|
||||
self.set_margin_bottom(8);
|
||||
self.set_margin_start(8);
|
||||
|
||||
@ -226,9 +226,9 @@ impl NotifyWindow {
|
||||
entry.error_boundary().spawn(async move {
|
||||
this.selected_subscription()
|
||||
.unwrap()
|
||||
.publish_msg(models::Message {
|
||||
.publish_msg(models::OutgoingMessage {
|
||||
message: Some(entry.text().as_str().to_string()),
|
||||
..models::Message::default()
|
||||
..models::OutgoingMessage::default()
|
||||
})
|
||||
.await?;
|
||||
Ok(())
|
||||
@ -266,13 +266,7 @@ impl NotifyWindow {
|
||||
fn add_subscription(&self, sub: models::Subscription) {
|
||||
let this = self.clone();
|
||||
self.error_boundary().spawn(async move {
|
||||
let sub = this
|
||||
.notifier()
|
||||
.subscribe(&sub.server, &sub.topic)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
anyhow::anyhow!(err.into_iter().map(|x| x.to_string()).collect::<String>())
|
||||
})?;
|
||||
let sub = this.notifier().subscribe(&sub.server, &sub.topic).await?;
|
||||
let imp = this.imp();
|
||||
|
||||
// Subscription::new will use the pipelined client to retrieve info about the subscription
|
||||
@ -371,7 +365,7 @@ impl NotifyWindow {
|
||||
imp.message_list
|
||||
.bind_model(Some(&sub.imp().messages), move |obj| {
|
||||
let b = obj.downcast_ref::<glib::BoxedAnyObject>().unwrap();
|
||||
let msg = b.borrow::<models::Message>();
|
||||
let msg = b.borrow::<models::ReceivedMessage>();
|
||||
|
||||
MessageRow::new(msg.clone()).upcast()
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user