Skip to content
12 changes: 6 additions & 6 deletions src/app/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl AppModel {
self.user_set_flags(star_label(star), &many, FlagKind::Star, star);
return;
}
if let Some(m) = self.reply_target() {
if let Some(m) = self.reply_target().cloned() {
if self.thread_star_target(&m) {
// The conversation is the target: any member starred
// reads as a starred thread, and the toggle clears or
Expand Down Expand Up @@ -63,7 +63,7 @@ impl AppModel {
return;
}
}
if let Some(m) = self.reply_target() {
if let Some(m) = self.reply_target().cloned() {
self.move_to(m, FolderKind::Archive);
}
}
Expand Down Expand Up @@ -94,7 +94,7 @@ impl AppModel {
self.message_list.emit(MessageListInput::ResolveDelete);
return;
}
if let Some(m) = self.reply_target() {
if let Some(m) = self.reply_target().cloned() {
// In the Outbox, deleting means giving up on sending it —
// there is no server-side copy to move to Trash.
if self.outbox_item(m.account_id, m.id).is_some() {
Expand Down Expand Up @@ -122,7 +122,7 @@ impl AppModel {
.emit(MessageListInput::Bulk(BulkAction::DeleteForever));
return;
}
if let Some(m) = self.reply_target() {
if let Some(m) = self.reply_target().cloned() {
if self.outbox_item(m.account_id, m.id).is_some() {
self.drop_outbox_row(m.account_id, m.id, &sender);
self.current = None;
Expand Down Expand Up @@ -152,7 +152,7 @@ impl AppModel {
if !many.is_empty() {
let read = many.iter().any(|m| m.unread);
self.user_set_flags(read_label(read), &many, FlagKind::Read, read);
} else if let Some(m) = self.reply_target() {
} else if let Some(m) = self.reply_target().cloned() {
let read = m.unread;
self.user_set_flags(read_label(read), &[m], FlagKind::Read, read);
}
Expand Down Expand Up @@ -186,7 +186,7 @@ impl AppModel {
.emit(MessageListInput::Bulk(BulkAction::Spam));
return;
}
if let Some(m) = self.reply_target() {
if let Some(m) = self.reply_target().cloned() {
if self.in_junk(&m) {
self.mark_ham_msg(m);
} else {
Expand Down
38 changes: 22 additions & 16 deletions src/app/attachments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,35 +185,41 @@ impl AppModel {
/// hand. Opening a thread used to load nothing at all — the drawer only
/// appeared after clicking a member, which runs the single-message path.
pub(super) fn load_thread_attachments(&mut self) {
let wanted: Vec<(u32, u32, u32, String)> = self
let wanted: Vec<(BodyKey, MailRequest)> = self
.current_thread
.iter()
.filter(|tm| tm.has_attachment)
// A reply's stand-in card is on no server yet.
.filter(|tm| !self.provisionals.contains_key(&(tm.account_id, tm.id)))
.filter(|tm| !self.attachment_cache.contains_key(&body_key(tm)))
.filter_map(|tm| {
self.resolve_folder_path(tm)
.map(|p| (tm.account_id, tm.id, tm.uid, p))
})
.collect();
if !wanted.is_empty() {
self.attachments_loading = true;
}
for (account_id, message_id, uid, path) in wanted {
self.send_to(
account_id,
MailRequest::LoadAttachments {
message_id,
let path = self.resolve_folder_path(tm)?;
let req = MailRequest::LoadAttachments {
message_id: tm.id,
path,
uid,
uid: tm.uid,
download: true,
},
);
};
Some((body_key(tm), req))
})
.collect();
for (key, req) in wanted {
self.ask_attachments(key, req);
}
self.refresh_thread_attachments();
}

/// Send `req`, which asks for the attachments of the message at `key`,
/// unless this opening has asked for them already: the message, its
/// conversation and the related lookup each want them, and every answer
/// carries the files' bytes.
pub(super) fn ask_attachments(&mut self, key: BodyKey, req: MailRequest) {
if self.attachments_asked.insert(key) {
self.attachments_loading = true;
self.send_to(key.0, req);
}
}

/// Point the drawer at the union of cached attachments across the open
/// conversation. A reply pulled in from Sent can duplicate what it was
/// sent with, so identical (name, size) pairs are shown once.
Expand Down
5 changes: 4 additions & 1 deletion src/app/children.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,10 @@ fn contacts_page_output_msg(out: ContactsPageOutput) -> AppMsg {
// hung the UI trying to parse it. Name it by content.
let name = format!("{name}.{}", crate::models::image_ext(&data));
AppMsg::ShowLightbox {
items: vec![crate::models::Attachment { name, data }],
items: vec![crate::models::Attachment {
name,
data: data.into(),
}],
start: 0,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl AppModel {
pub(super) fn selected_targets(&self) -> Vec<Message> {
let mut targets = self.multi_selection();
if targets.is_empty() {
targets.extend(self.reply_target());
targets.extend(self.reply_target().cloned());
}
targets
}
Expand Down
5 changes: 5 additions & 0 deletions src/app/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ pub(crate) struct AppModel {
pub(super) attachments: Vec<Attachment>,
/// True while the current message's attachments are downloading.
pub(super) attachments_loading: bool,
/// The messages whose attachments the reader has asked for since the
/// open message or conversation was selected: opening one asks from
/// several places (the message, its conversation, the related lookup),
/// and each answer otherwise came back, megabytes and all, once per ask.
pub(super) attachments_asked: HashSet<BodyKey>,
/// The reader header's right-hand actions are collapsed into the overflow menu
/// (pane squeezed under READER_ACTIONS_BREAKPOINT).
pub(super) reader_actions_collapsed: bool,
Expand Down
1 change: 1 addition & 0 deletions src/app/model_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ impl AppModel {
attachments: Vec::new(),
lightbox,
attachments_loading: false,
attachments_asked: Default::default(),
reader_actions_collapsed: false,
reader_compact: false,
list_actions_collapsed: false,
Expand Down
6 changes: 3 additions & 3 deletions src/app/move_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl AppModel {
.emit(MessageListInput::Bulk(BulkAction::MoveToInbox));
return;
}
if let Some(m) = self.reply_target() {
if let Some(m) = self.reply_target().cloned() {
self.move_to(m, FolderKind::Inbox);
}
}
Expand Down Expand Up @@ -84,7 +84,7 @@ impl AppModel {
(self.list_selection[0].0, None)
} else {
match self.reply_target() {
Some(m) => (m.account_id, self.resolve_folder_path(&m)),
Some(m) => (m.account_id, self.resolve_folder_path(m)),
None => return,
}
};
Expand Down Expand Up @@ -251,7 +251,7 @@ impl AppModel {
})
.collect();
self.drop_move(account_id, dest, items);
} else if let Some(m) = self.reply_target() {
} else if let Some(m) = self.reply_target().cloned() {
if m.account_id == account_id {
self.move_to_path(m, dest);
} else {
Expand Down
29 changes: 13 additions & 16 deletions src/app/reader_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ impl AppModel {
self.follow_keyboard_into_reader();
self.attachments.clear();
self.attachments_loading = false;
self.attachments_asked.clear();
self.sync_attachment_drawer();
let account_id = m.account_id;
let folder_path = self.resolve_folder_path(&m);
Expand Down Expand Up @@ -530,9 +531,8 @@ impl AppModel {
}
self.reader_swap.freeze();
self.show_single(&m, display, needs_body, folder_path.clone(), related);
self.load_attachments_on_open(&m, folder_path);
}

self.load_attachments_on_open(&m, folder_path);
}

/// With the Privacy switch on, the remote content of the rows likely
Expand Down Expand Up @@ -745,27 +745,24 @@ impl AppModel {
self.show_message(Some(display), needs_body);
}

/// Attachments: use the in-memory cache if present; otherwise
/// fetch them (disk cache first, then the server). Opening the
/// A lone message's attachments: use the in-memory cache if present;
/// otherwise fetch them (disk cache first, then the server). Opening the
/// message is the request — the paperclip appears when they
/// land, with no "load attachments" click in between.
/// land, with no "load attachments" click in between. A conversation's
/// drawer spans all its messages, and `load_thread_attachments` fills it.
fn load_attachments_on_open(&mut self, m: &Message, folder_path: Option<String>) {
let account_id = m.account_id;
if m.has_attachment {
if let Some(cached) = self.attachment_cache.get(&body_key(m)).cloned() {
self.attachments = cached;
self.sync_attachment_drawer();
} else if let Some(path) = folder_path {
self.attachments_loading = true;
self.send_to(
account_id,
MailRequest::LoadAttachments {
message_id: m.id,
path,
uid: m.uid,
download: true,
},
);
let req = MailRequest::LoadAttachments {
message_id: m.id,
path,
uid: m.uid,
download: true,
};
self.ask_attachments(body_key(m), req);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/app/reader_toolbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl AppModel {
.retain(|k| many.iter().all(|m| self.carries_tag(m, k)));
all
}
None => self.reply_target()?,
None => self.reply_target()?.clone(),
};
let s = sender.input_sender().clone();
Some(crate::ui::message_list::tag_menu_entries(
Expand Down Expand Up @@ -207,9 +207,9 @@ impl AppModel {
let target = self.reply_target();
let acts = target.is_some();
let many = acts || self.many_selected();
let starred = target.as_ref().is_some_and(|m| m.starred);
let target_unread = target.as_ref().is_some_and(|m| m.unread);
let restorable = target.as_ref().is_some_and(|m| {
let starred = target.is_some_and(|m| m.starred);
let target_unread = target.is_some_and(|m| m.unread);
let restorable = target.is_some_and(|m| {
self.folder_kind(m.account_id, m.folder_id)
.is_some_and(|k| matches!(k, FolderKind::Trash | FolderKind::Junk))
});
Expand Down
2 changes: 1 addition & 1 deletion src/app/removal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl AppModel {
/// Whether the reader's target sits in Junk: the spam button, shortcut
/// and menu entry then read "Not Spam" (#168).
pub(super) fn target_in_junk(&self) -> bool {
self.reply_target().is_some_and(|m| self.in_junk(&m))
self.reply_target().is_some_and(|m| self.in_junk(m))
}

/// Delete `messages`: the ones still outside Trash are moved there, and any
Expand Down
14 changes: 8 additions & 6 deletions src/app/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ impl AppModel {
/// one is highlighted. `None` greys the buttons out: with no card (or
/// several) selected there is no way to say which message an action would
/// mean.
pub(super) fn reply_target(&self) -> Option<Message> {
///
/// Lent, not copied: the toolbar asks for it a dozen times on every
/// redraw, and a message with pictures in its body runs to megabytes.
pub(super) fn reply_target(&self) -> Option<&Message> {
if self.current_thread.len() <= 1 {
return self.current.clone();
return self.current.as_ref();
}
match self.list_selection.as_slice() {
[(account_id, id)] => self
.current_thread
.iter()
.find(|m| m.account_id == *account_id && m.id == *id)
.cloned(),
.find(|m| m.account_id == *account_id && m.id == *id),
_ => None,
}
}
Expand Down Expand Up @@ -132,7 +134,7 @@ impl AppModel {
/// only decides where that message is drawn (#165). A highlighted card is
/// addressed as itself.
pub(super) fn compose_target(&self) -> Option<Message> {
let m = self.reply_target()?;
let m = self.reply_target()?.clone();
tracing::debug!(
target: "hylki::reply",
"toolbar target: selected {}:{} from={} cards={} thread={} head={}",
Expand Down Expand Up @@ -282,7 +284,7 @@ impl AppModel {
/// star, or any member's when the conversation is the target.
pub(super) fn toolbar_star_lit(&self) -> bool {
self.reply_target().is_some_and(|m| {
if self.thread_star_target(&m) {
if self.thread_star_target(m) {
self.current_thread.iter().any(|t| t.starred)
} else {
m.starred
Expand Down
2 changes: 1 addition & 1 deletion src/app/send_morph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl AppModel {
let data = std::fs::read(&f.path).ok()?;
Some(Attachment {
name: f.card.name.clone(),
data,
data: data.into(),
})
})
.collect()
Expand Down
8 changes: 4 additions & 4 deletions src/app/shortcuts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl AppModel {
};
}
if targets.is_empty() {
targets.extend(self.reply_target());
targets.extend(self.reply_target().cloned());
}
if !read {
self.hold_unread(&targets);
Expand All @@ -213,7 +213,7 @@ impl AppModel {
let targets = if self.many_selected() {
self.multi_selection()
} else {
self.reply_target().into_iter().collect()
self.reply_target().cloned().into_iter().collect()
};
let mut changes: HashMap<u32, Vec<FlagChange>> = HashMap::new();
for target in targets {
Expand Down Expand Up @@ -397,14 +397,14 @@ impl AppModel {
return;
}
if self.current_thread.len() <= 1 {
if let Some(m) = self.reply_target() {
if let Some(m) = self.reply_target().cloned() {
self.user_set_flags(read_label(false), &[m], FlagKind::Read, false);
}
return;
}
let order = |m: &Message| (m.timestamp, m.uid);
let start = (if self.selection_from_cards {
self.reply_target()
self.reply_target().cloned()
} else {
None
})
Expand Down
4 changes: 2 additions & 2 deletions src/app/snooze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl AppModel {
pub(super) fn snooze_offered(&self) -> bool {
!self.showing_outbox
&& match self.reply_target() {
Some(m) => self.snoozable(&m),
Some(m) => self.snoozable(m),
None => self.many_selected(),
}
}
Expand Down Expand Up @@ -231,7 +231,7 @@ impl AppModel {
let messages = if messages.len() > 1 {
messages
} else {
self.reply_target().into_iter().collect()
self.reply_target().cloned().into_iter().collect()
};
self.apply_snooze(action, messages);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cache/bodies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl Cache {
let rows = stmt.query_map(params![account_id, folder_path, uid], |row| {
Ok(Attachment {
name: row.get(0)?,
data: row.get(1)?,
data: row.get::<_, Vec<u8>>(1)?.into(),
})
})?;
rows.collect()
Expand Down
2 changes: 1 addition & 1 deletion src/cache/gallery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl Cache {
from_name: row.get(6)?,
subject: row.get(7)?,
timestamp: row.get(8)?,
data: row.get(9)?,
data: row.get::<_, Option<Vec<u8>>>(9)?.map(Into::into),
downloaded: row.get(10)?,
folder_name: row.get(11)?,
})
Expand Down
2 changes: 1 addition & 1 deletion src/cache/thread_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ fn attachments_downloaded_under_one_label_answer_for_the_others() {
7,
&[Attachment {
name: "spec.pdf".into(),
data: vec![1, 2, 3],
data: [1, 2, 3].as_slice().into(),
}],
);

Expand Down
Loading