Skip to content

Commit

Permalink
Merge pull request #222 from ReagentX/feat/cs/fix-edited-thread-origi…
Browse files Browse the repository at this point in the history
…nators

Feat/cs/fix edited thread originators
  • Loading branch information
ReagentX committed Nov 30, 2023
2 parents b9b4ed6 + 22d1b19 commit ff27e9c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 36 deletions.
6 changes: 6 additions & 0 deletions imessage-database/src/message_types/handwriting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ impl HandwrittenMessage {
Self {}
}
}

impl Default for HandwrittenMessage {
fn default() -> Self {
Self::new()
}
}
24 changes: 12 additions & 12 deletions imessage-exporter/src/app/export_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ use std::fmt::Display;
#[derive(PartialEq, Eq, Debug)]
pub enum ExportType {
/// HTML file export
HTML,
Html,
/// Text file export
TXT,
Txt,
}

impl ExportType {
/// Given user's input, return a variant if the input matches one
pub fn from_cli(platform: &str) -> Option<Self> {
match platform.to_lowercase().as_str() {
"txt" => Some(Self::TXT),
"html" => Some(Self::HTML),
"txt" => Some(Self::Txt),
"html" => Some(Self::Html),
_ => None,
}
}
Expand All @@ -27,8 +27,8 @@ impl ExportType {
impl Display for ExportType {
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ExportType::TXT => write!(fmt, "txt"),
ExportType::HTML => write!(fmt, "html"),
ExportType::Txt => write!(fmt, "txt"),
ExportType::Html => write!(fmt, "html"),
}
}
}
Expand All @@ -41,23 +41,23 @@ mod tests {
fn can_parse_html_any_case() {
assert!(matches!(
ExportType::from_cli("html"),
Some(ExportType::HTML)
Some(ExportType::Html)
));
assert!(matches!(
ExportType::from_cli("HTML"),
Some(ExportType::HTML)
Some(ExportType::Html)
));
assert!(matches!(
ExportType::from_cli("HtMl"),
Some(ExportType::HTML)
Some(ExportType::Html)
));
}

#[test]
fn can_parse_txt_any_case() {
assert!(matches!(ExportType::from_cli("txt"), Some(ExportType::TXT)));
assert!(matches!(ExportType::from_cli("TXT"), Some(ExportType::TXT)));
assert!(matches!(ExportType::from_cli("tXt"), Some(ExportType::TXT)));
assert!(matches!(ExportType::from_cli("txt"), Some(ExportType::Txt)));
assert!(matches!(ExportType::from_cli("TXT"), Some(ExportType::Txt)));
assert!(matches!(ExportType::from_cli("tXt"), Some(ExportType::Txt)));
}

#[test]
Expand Down
10 changes: 5 additions & 5 deletions imessage-exporter/src/app/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ mod arg_tests {
attachment_root: None,
attachment_manager: AttachmentManager::default(),
diagnostic: false,
export_type: Some(ExportType::HTML),
export_type: Some(ExportType::Html),
export_path: validate_path(Some(&tmp_dir), &None).unwrap(),
query_context: QueryContext::default(),
no_lazy: false,
Expand Down Expand Up @@ -537,7 +537,7 @@ mod arg_tests {
attachment_root: None,
attachment_manager: AttachmentManager::default(),
diagnostic: false,
export_type: Some(ExportType::TXT),
export_type: Some(ExportType::Txt),
export_path: validate_path(None, &None).unwrap(),
query_context: QueryContext::default(),
no_lazy: true,
Expand Down Expand Up @@ -657,7 +657,7 @@ mod path_tests {
fn can_validate_empty() {
let tmp = String::from("/tmp");
let export_path = Some(&tmp);
let export_type = Some(ExportType::TXT);
let export_type = Some(ExportType::Txt);

let result = validate_path(export_path, &export_type.as_ref());

Expand All @@ -668,7 +668,7 @@ mod path_tests {
fn can_validate_different_type() {
let tmp = String::from("/tmp");
let export_path = Some(&tmp);
let export_type = Some(ExportType::TXT);
let export_type = Some(ExportType::Txt);

let result = validate_path(export_path, &export_type.as_ref());

Expand All @@ -685,7 +685,7 @@ mod path_tests {
fn can_validate_same_type() {
let tmp = String::from("/tmp");
let export_path = Some(&tmp);
let export_type = Some(ExportType::TXT);
let export_type = Some(ExportType::Txt);

let result = validate_path(export_path, &export_type.as_ref());

Expand Down
4 changes: 2 additions & 2 deletions imessage-exporter/src/app/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,10 @@ impl Config {

// Create exporter, pass it data we care about, then kick it off
match export_type {
ExportType::HTML => {
ExportType::Html => {
HTML::new(self).iter_messages()?;
}
ExportType::TXT => {
ExportType::Txt => {
TXT::new(self).iter_messages()?;
}
}
Expand Down
2 changes: 0 additions & 2 deletions imessage-exporter/src/app/sanitizers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ mod test_filename {

#[cfg(test)]
mod tests {
use std::borrow::Cow;

use crate::app::sanitizers::sanitize_html;

#[test]
Expand Down
33 changes: 18 additions & 15 deletions imessage-exporter/src/exporters/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,25 +298,28 @@ impl<'a> Writer<'a> for HTML<'a> {
"<div class=\"edited\">",
"</div>",
);
continue;
}

match message_part {
BubbleType::Text(text) => {
if text.starts_with(FITNESS_RECEIVER) {
self.add_line(
&mut formatted_message,
&text.replace(FITNESS_RECEIVER, YOU),
"<span class=\"bubble\">",
"</span>",
);
} else {
self.add_line(
&mut formatted_message,
&sanitize_html(text),
"<span class=\"bubble\">",
"</span>",
);
// Render the message body if the message was not edited
// If it was edited, it was rendered already
if !message.is_edited() {
if text.starts_with(FITNESS_RECEIVER) {
self.add_line(
&mut formatted_message,
&text.replace(FITNESS_RECEIVER, YOU),
"<span class=\"bubble\">",
"</span>",
);
} else {
self.add_line(
&mut formatted_message,
&sanitize_html(text),
"<span class=\"bubble\">",
"</span>",
);
}
}
}
BubbleType::Attachment => {
Expand Down

0 comments on commit ff27e9c

Please sign in to comment.