Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email list ux improvements #165

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dwata",
"version": "0.1.6",
"version": "0.2.0",
"description": "AI assistants for everyone",
"type": "module",
"author": {
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["openai"]

[package]
name = "dwata"
version = "0.1.6"
version = "0.2.0"
description = "AI assisted app for our private data"
authors = ["Sumit Datta <[email protected]>"]
license = "Apache-2.0 license"
Expand Down Expand Up @@ -56,6 +56,7 @@ slug = "0.1.5"
openai = { version = "2.0.0", path = "openai" }
tantivy = "0.22.0"
tauri-plugin-shell = "2.0.0-rc.2"
regex = "1.10.6"

[features]
# this feature is used for production builds or when `devPath` points to the filesystem
Expand Down
4 changes: 0 additions & 4 deletions src-tauri/bindings/AIIntegration.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/AIIntegrationCreateUpdate.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/AIIntegrationFilters.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src-tauri/bindings/AIModel.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/AIModelDeveloper.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/AIModelFeatures.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/AIProvider.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src-tauri/bindings/Chat.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src-tauri/bindings/ChatCreateUpdate.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/ChatFilters.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/ChatToolResponse.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src-tauri/bindings/Configuration.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/Content.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src-tauri/bindings/ContentSpec.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/ContentType.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src-tauri/bindings/DatabaseSource.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/DatabaseSourceCreateUpdate.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/DatabaseType.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/DirectorySource.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/DirectorySourceCreateUpdate.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/File.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src-tauri/bindings/FormFieldData.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/HeterogeneousContentArray.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src-tauri/bindings/HomogeneousContentArray.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/InsertUpdateResponse.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/Module.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src-tauri/bindings/ModuleDataCreateUpdate.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src-tauri/bindings/ModuleDataRead.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src-tauri/bindings/ModuleDataReadList.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src-tauri/bindings/ModuleFilters.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/Objective.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/Role.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/Step.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/TextType.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/UserAccount.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/bindings/UserAccountCreateUpdate.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src-tauri/bindings/Workflow.ts

This file was deleted.

12 changes: 10 additions & 2 deletions src-tauri/src/email/crud.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use super::{EmailCreateUpdate, EmailFilters};
use super::{Email, EmailCreateUpdate, EmailFilters};
use crate::error::DwataError;
use crate::workspace::crud::{CRUDCreateUpdate, CRUDReadFilter, InputValue, VecColumnNameValue};
use crate::workspace::crud::{
CRUDCreateUpdate, CRUDRead, CRUDReadFilter, InputValue, VecColumnNameValue,
};

impl CRUDReadFilter for EmailFilters {
fn get_column_names_values_to_filter(&self) -> VecColumnNameValue {
Expand Down Expand Up @@ -29,3 +31,9 @@ impl CRUDCreateUpdate for EmailCreateUpdate {
Ok(names_values)
}
}

impl CRUDRead for Email {
fn table_name() -> String {
"email".to_string()
}
}
47 changes: 37 additions & 10 deletions src-tauri/src/email/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::workspace::crud::{CRUDRead, CRUDReadFilter, InputValue, VecColumnName
use chrono::{DateTime, Utc};
use log::{error, info};
use mail_parser::MessageParser;
use regex::Regex;
use sqlx::{Execute, Pool, QueryBuilder, Sqlite};
use std::{fs::create_dir_all, path::PathBuf};
use tantivy::{
Expand Down Expand Up @@ -254,6 +255,41 @@ pub async fn search_emails_in_tantivy(
Ok(emails)
}

pub fn clean_email_body_text(body_text: &String) -> String {
let mut body_text = body_text.clone().chars().take(400).collect::<String>();
// We remove consecutive new lines from the body text
match Regex::new(r"\n{2,}") {
Ok(re) => {
body_text = re.replace(&body_text, "\n").to_string();
}
Err(_) => {}
};
// We remove consecutive spaces from the body text
match Regex::new(r" {2,}") {
Ok(re) => {
body_text = re.replace(&body_text, " ").to_string();
}
Err(_) => {}
};
// We remove consecutive tabs from the body text
// body_text = body_text.map(|x| x.replace("\t", " "));
// We remove consecutive underscores (2 or more) from the body text
match Regex::new("_{2,}") {
Ok(re) => {
body_text = re.replace(&body_text, "").to_string();
}
Err(_) => {}
};
// We remove consecutive dashes (2 or more) from the body text
match Regex::new(r"\-{2,}") {
Ok(re) => {
body_text = re.replace(&body_text, "").to_string();
}
Err(_) => {}
};
body_text
}

pub async fn search_emails_in_tantity_and_dwata_db(
filters: EmailFilters,
limit: usize,
Expand Down Expand Up @@ -316,16 +352,7 @@ pub async fn search_emails_in_tantity_and_dwata_db(
// We select first 200 characters of the body text for each email
result.iter_mut().for_each(|x: &mut Email| {
if let Some(body) = &x.body_text {
let mut body_text = Some(body.clone().chars().take(400).collect::<String>());
// We remove consecutive new lines from the body text
body_text = body_text.map(|x| x.replace("\n\n", "\n"));
// We remove consecutive spaces from the body text
body_text = body_text.map(|x| x.replace(" ", " "));
// We remove consecutive tabs from the body text
body_text = body_text.map(|x| x.replace("\t", " "));
// We remove consecutive dashes (2 or more) from the body text using a regex
body_text = body_text.map(|x| x.replace(r"-{2,}", "-"));
x.body_text = body_text;
x.body_text = Some(clean_email_body_text(body));
}
});
let count = match count_builder
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/email/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use ts_rs::TS;
pub mod commands;
pub mod crud;
pub mod helpers;
pub mod tests;

#[derive(Deserialize, Serialize, TS, Type, EnumString, Display)]
#[sqlx(rename_all = "lowercase")]
Expand Down
35 changes: 35 additions & 0 deletions src-tauri/src/email/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use super::helpers::clean_email_body_text;

#[cfg(test)]
mod tests {
use crate::email::helpers::clean_email_body_text;

// use super::*;
#[test]
fn check_consecutive_end_of_lines_removed() {
let body_text = "\n\n\n\n\n\n\n".to_string();
let cleaned = clean_email_body_text(&body_text);
assert_eq!(cleaned, "\n");
}

#[test]
fn check_consecutive_spaces_removed() {
let body_text = " ".to_string();
let cleaned = clean_email_body_text(&body_text);
assert_eq!(cleaned, " ");
}

#[test]
fn check_consecutive_underscores_removed() {
let body_text = "_______________________________________".to_string();
let cleaned = clean_email_body_text(&body_text);
assert_eq!(cleaned, "");
}

#[test]
fn check_consecutive_dashes_removed() {
let body_text = "---------------------------------".to_string();
let cleaned = clean_email_body_text(&body_text);
assert_eq!(cleaned, "");
}
}
Loading