Skip to content

Commit

Permalink
Rename MessageFilter to Filter
Browse files Browse the repository at this point in the history
  • Loading branch information
canac committed Jun 19, 2024
1 parent 0a98766 commit acb481a
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 135 deletions.
10 changes: 5 additions & 5 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::import::read_messages_stdin;
use anyhow::{bail, Context, Result};
use clap::Parser;
use cli::{ConfigSubcommand, ViewMessageState};
use database::{Backend, Database, HttpBackend, MessageFilter, NewMessage, SqliteBackend, State};
use database::{Backend, Database, Filter, HttpBackend, NewMessage, SqliteBackend, State};
use directories::ProjectDirs;
use import::import_messages;
use message_formatter::MessageFormatter;
Expand Down Expand Up @@ -153,7 +153,7 @@ async fn run<B: Backend + Send + Sync + 'static>(
Command::View { mailbox, state, .. } => {
let messages = db
.load_messages(
MessageFilter::new()
Filter::new()
.with_mailbox_option(mailbox)
.with_states(states_from_view_message_state(state)),
)
Expand All @@ -164,7 +164,7 @@ async fn run<B: Backend + Send + Sync + 'static>(
Command::Read { mailbox } => {
let messages = db
.change_state(
MessageFilter::new()
Filter::new()
.with_mailbox_option(mailbox)
.with_states(vec![State::Unread]),
State::Read,
Expand All @@ -176,7 +176,7 @@ async fn run<B: Backend + Send + Sync + 'static>(
Command::Archive { mailbox } => {
let messages = db
.change_state(
MessageFilter::new()
Filter::new()
.with_mailbox_option(mailbox)
.with_states(vec![State::Unread, State::Read]),
State::Archived,
Expand All @@ -188,7 +188,7 @@ async fn run<B: Backend + Send + Sync + 'static>(
Command::Clear { mailbox } => {
let messages = db
.delete_messages(
MessageFilter::new()
Filter::new()
.with_mailbox_option(mailbox)
.with_states(vec![State::Archived]),
)
Expand Down
12 changes: 6 additions & 6 deletions cli/src/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::navigable_list::{Keyed, NavigableList};
use super::tree_list::{Depth, TreeList};
use super::worker::{spawn, Receiver, Request, Response, Sender};
use anyhow::Result;
use database::{Backend, Database, MailboxInfo, Message, MessageFilter, State};
use database::{Backend, Database, Filter, MailboxInfo, Message, State};
use std::collections::hash_map::DefaultHasher;
use std::collections::{HashMap, HashSet};
use std::hash::Hasher;
Expand Down Expand Up @@ -137,7 +137,7 @@ impl App {
// Update the mailboxes list
pub fn update_mailboxes(&mut self) -> Result<()> {
self.worker_tx.send(Request::LoadMailboxes(
MessageFilter::new().with_states(self.get_active_states()),
Filter::new().with_states(self.get_active_states()),
))?;
Ok(())
}
Expand Down Expand Up @@ -177,8 +177,8 @@ impl App {
}

// Get the filter representing which messages should be displayed
pub fn get_display_filter(&self) -> MessageFilter {
MessageFilter::new()
pub fn get_display_filter(&self) -> Filter {
Filter::new()
.with_mailbox_option(
self.mailboxes
.get_cursor_item()
Expand All @@ -188,7 +188,7 @@ impl App {
}

// // Get the filter representing which messages are selected and should be acted upon
fn get_action_filter(&self) -> MessageFilter {
fn get_action_filter(&self) -> Filter {
let selected_items = self
.messages
.get_selected_items()
Expand All @@ -204,7 +204,7 @@ impl App {
} else {
selected_items
};
MessageFilter::new().with_ids(active_ids)
Filter::new().with_ids(active_ids)
}

// Change the state of all selected messages
Expand Down
13 changes: 5 additions & 8 deletions cli/src/tui/worker.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
use super::monotonic_counter::MonotonicCounter;
use database::{Backend, Database, MailboxInfo, Message, MessageFilter, State};
use database::{Backend, Database, Filter, MailboxInfo, Message, State};
use std::sync::mpsc::{self, channel};
use std::sync::Arc;
use std::thread;
use tokio::runtime::Handle;

pub enum Request {
LoadMessages(MessageFilter),
LoadMailboxes(MessageFilter),
ChangeMessageStates {
filter: MessageFilter,
new_state: State,
},
DeleteMessages(MessageFilter),
LoadMessages(Filter),
LoadMailboxes(Filter),
ChangeMessageStates { filter: Filter, new_state: State },
DeleteMessages(Filter),
}

pub enum Response {
Expand Down
16 changes: 5 additions & 11 deletions database/src/backend.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::database::MailboxInfo;
use crate::filter::Filter;
use crate::message::{Message, State};
use crate::message_filter::MessageFilter;
use crate::new_message::NewMessage;
use anyhow::Result;
use std::future::Future;
Expand All @@ -10,21 +10,15 @@ pub trait Backend {
&self,
messages: Vec<NewMessage>,
) -> impl Future<Output = Result<Vec<Message>>> + Send;
fn load_messages(
&self,
filter: MessageFilter,
) -> impl Future<Output = Result<Vec<Message>>> + Send;
fn load_messages(&self, filter: Filter) -> impl Future<Output = Result<Vec<Message>>> + Send;
fn change_state(
&self,
filter: MessageFilter,
filter: Filter,
new_state: State,
) -> impl Future<Output = Result<Vec<Message>>> + Send;
fn delete_messages(
&self,
filter: MessageFilter,
) -> impl Future<Output = Result<Vec<Message>>> + Send;
fn delete_messages(&self, filter: Filter) -> impl Future<Output = Result<Vec<Message>>> + Send;
fn load_mailboxes(
&self,
filter: MessageFilter,
filter: Filter,
) -> impl Future<Output = Result<Vec<MailboxInfo>>> + Send;
}
14 changes: 5 additions & 9 deletions database/src/database.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::filter::Filter;
use crate::mailbox::Mailbox;
use crate::message::{Message, State};
use crate::message_filter::MessageFilter;
use crate::new_message::NewMessage;
use crate::Backend;
use anyhow::{bail, Result};
Expand Down Expand Up @@ -41,28 +41,24 @@ impl<B: Backend + Sized> Database<B> {
}

// Load all messages that match the filter
pub async fn load_messages(&self, filter: MessageFilter) -> Result<Vec<Message>> {
pub async fn load_messages(&self, filter: Filter) -> Result<Vec<Message>> {
self.backend.load_messages(filter).await
}

// Move messages that match the filter from their old state into new_state, returning the
// modified messages
pub async fn change_state(
&self,
filter: MessageFilter,
new_state: State,
) -> Result<Vec<Message>> {
pub async fn change_state(&self, filter: Filter, new_state: State) -> Result<Vec<Message>> {
self.backend.change_state(filter, new_state).await
}

// Delete messages that match the filter, returning the deleted messages
pub async fn delete_messages(&self, filter: MessageFilter) -> Result<Vec<Message>> {
pub async fn delete_messages(&self, filter: Filter) -> Result<Vec<Message>> {
self.backend.delete_messages(filter).await
}

// Given all messages that match the filter, determine the names and sizes of all mailboxes
// used by those messages
pub async fn load_mailboxes(&self, filter: MessageFilter) -> Result<Vec<MailboxInfo>> {
pub async fn load_mailboxes(&self, filter: Filter) -> Result<Vec<MailboxInfo>> {
self.backend.load_mailboxes(filter).await
}
}
Expand Down
Loading

0 comments on commit acb481a

Please sign in to comment.