fix(message-list): improve idioms (avoid redundant clone, extend labels, safer message extraction)

This commit is contained in:
Jeremiah Russell
2025-10-20 07:38:19 +01:00
committed by Jeremiah Russell
parent 12344c123e
commit d0b1391738

View File

@@ -372,9 +372,7 @@ impl MessageList for GmailClient {
/// Add label to the labels collection /// Add label to the labels collection
fn add_labels_ids(&mut self, label_ids: &[String]) { fn add_labels_ids(&mut self, label_ids: &[String]) {
if !label_ids.is_empty() { if !label_ids.is_empty() {
for id in label_ids { self.label_ids.extend(label_ids.iter().cloned());
self.label_ids.push(id.to_string())
}
} }
} }
@@ -390,11 +388,7 @@ impl MessageList for GmailClient {
/// Get a reference to the message_ids /// Get a reference to the message_ids
fn message_ids(&self) -> Vec<String> { fn message_ids(&self) -> Vec<String> {
self.messages self.messages.iter().map(|m| m.id().to_string()).collect()
.iter()
.map(|m| m.id().to_string())
.collect::<Vec<_>>()
.clone()
} }
/// Get a reference to the message_ids /// Get a reference to the message_ids
@@ -479,14 +473,13 @@ impl MessageList for GmailClient {
return Ok(list); return Ok(list);
} }
let mut list_ids = list if let Some(msgs) = &list.messages {
.clone() let mut list_ids: Vec<MessageSummary> = msgs
.messages .iter()
.unwrap() .flat_map(|item| item.id.as_deref().map(MessageSummary::new))
.iter() .collect();
.flat_map(|item| item.id.as_ref().map(|id| MessageSummary::new(id))) self.messages.append(&mut list_ids);
.collect(); }
self.messages.append(&mut list_ids);
Ok(list) Ok(list)
} }