✅ fix(message-list): improve idioms (avoid redundant clone, extend labels, safer message extraction)
This commit is contained in:
committed by
Jeremiah Russell
parent
12344c123e
commit
d0b1391738
@@ -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
|
|
||||||
.unwrap()
|
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|item| item.id.as_ref().map(|id| MessageSummary::new(id)))
|
.flat_map(|item| item.id.as_deref().map(MessageSummary::new))
|
||||||
.collect();
|
.collect();
|
||||||
self.messages.append(&mut list_ids);
|
self.messages.append(&mut list_ids);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(list)
|
Ok(list)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user