Skip to content

Commit

Permalink
Merge pull request #149 from ReagentX/feat/cs/make-handleid-optional
Browse files Browse the repository at this point in the history
Feat/cs/make handleid optional
  • Loading branch information
ReagentX authored Aug 20, 2023
2 parents c73bc4d + eb0d930 commit 995c81b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 32 deletions.
8 changes: 4 additions & 4 deletions imessage-database/src/tables/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub struct Message {
pub guid: String,
pub text: Option<String>,
pub service: Option<String>,
pub handle_id: i32,
pub handle_id: Option<i32>,
pub subject: Option<String>,
pub date: i64,
pub date_read: i64,
Expand Down Expand Up @@ -107,7 +107,7 @@ impl Table for Message {
guid: row.get("guid")?,
text: row.get("text").unwrap_or(None),
service: row.get("service").unwrap_or(None),
handle_id: row.get("handle_id")?,
handle_id: row.get("handle_id").unwrap_or(None),
subject: row.get("subject").unwrap_or(None),
date: row.get("date")?,
date_read: row.get("date_read").unwrap_or(0),
Expand Down Expand Up @@ -316,7 +316,7 @@ impl Cacheable for Message {

impl Message {
/// Get the body text of a message, parsing it as [`streamtyped`](crate::util::streamtyped) data if necessary.
/// TODO: resolve the compiler warnings with this method
// TODO: resolve the compiler warnings with this method
pub fn gen_text<'a>(&'a mut self, db: &'a Connection) -> Result<&'a str, MessageError> {
if self.text.is_none() {
let body = self.attributed_body(db).ok_or(MessageError::MissingData)?;
Expand Down Expand Up @@ -934,7 +934,7 @@ mod tests {
guid: String::default(),
text: None,
service: Some("iMessage".to_string()),
handle_id: i32::default(),
handle_id: Some(i32::default()),
subject: None,
date: i64::default(),
date_read: i64::default(),
Expand Down
2 changes: 1 addition & 1 deletion imessage-database/src/util/output.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
Contains method to emit a loading message while we do other work
Contains functions that emit a loading message while we do other work
*/

use std::io::{stdout, Write};
Expand Down
6 changes: 3 additions & 3 deletions imessage-exporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ This binary is available on [crates.io](https://crates.io/crates/imessage-export

`cargo install imessage-exporter` is the best way to install the app for normal use.

<details><summary>Uninstall steps</code></summary><p><pre>% cargo uninstall message-exporter</pre></p></details>
<details><summary>Uninstall steps</code></summary><p><pre>% cargo uninstall imessage-exporter</pre></p></details>

### Homebrew

This binary is available via [`brew`](https://formulae.brew.sh/formula/imessage-exporter).

`brew install imessage-exporter` will install the app, but it may not be up to date with the latest release.

<details><summary>Uninstall steps</code></summary><p><pre>% brew uninstall message-exporter</pre></p></details>
<details><summary>Uninstall steps</code></summary><p><pre>% brew uninstall imessage-exporter</pre></p></details>

### Prebuilt Binaries

The [releases page](https://github.com/ReagentX/imessage-exporter/releases) provides prebuilt binaries for both Apple Silicon and Intel-based Macs.

<details><summary>Uninstall steps</code></summary><p><pre>% rm path/to/message-exporter-binary</pre></p></details>
<details><summary>Uninstall steps</code></summary><p><pre>% rm path/to/imessage-exporter-binary</pre></p></details>

### Installing manually

Expand Down
49 changes: 35 additions & 14 deletions imessage-exporter/src/app/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<'a> Config<'a> {
let mut added = 0;
let mut out_s = String::with_capacity(MAX_LENGTH);
for participant_id in participants.iter() {
let participant = self.who(participant_id, false);
let participant = self.who(&Some(*participant_id), false);
if participant.len() + out_s.len() < MAX_LENGTH {
if !out_s.is_empty() {
out_s.push_str(", ")
Expand Down Expand Up @@ -277,15 +277,16 @@ impl<'a> Config<'a> {
}

/// Determine who sent a message
pub fn who(&self, handle_id: &i32, is_from_me: bool) -> &str {
pub fn who(&self, handle_id: &Option<i32>, is_from_me: bool) -> &str {
if is_from_me {
self.options.custom_name.unwrap_or(ME)
} else {
match self.participants.get(handle_id) {
return self.options.custom_name.unwrap_or(ME);
} else if let Some(handle_id) = handle_id {
return match self.participants.get(handle_id) {
Some(contact) => contact,
None => UNKNOWN,
}
}
UNKNOWN
}
}

Expand Down Expand Up @@ -350,7 +351,7 @@ mod tests {
guid: String::default(),
text: None,
service: Some("iMessage".to_string()),
handle_id: i32::default(),
handle_id: Some(i32::default()),
subject: None,
date: i64::default(),
date_read: i64::default(),
Expand Down Expand Up @@ -561,8 +562,8 @@ mod tests {
// Create participant data
app.participants.insert(10, "Person 10".to_string());

// Get filename
let who = app.who(&10, false);
// Get participant name
let who = app.who(&Some(10), false);
assert_eq!(who, "Person 10".to_string());
}

Expand All @@ -571,8 +572,8 @@ mod tests {
let options = fake_options();
let app = fake_app(options);

// Get filename
let who = app.who(&10, false);
// Get participant name
let who = app.who(&Some(10), false);
assert_eq!(who, "Unknown".to_string());
}

Expand All @@ -581,8 +582,8 @@ mod tests {
let options = fake_options();
let app = fake_app(options);

// Get filename
let who = app.who(&0, true);
// Get participant name
let who = app.who(&Some(0), true);
assert_eq!(who, "Me".to_string());
}

Expand All @@ -592,11 +593,31 @@ mod tests {
options.custom_name = Some("Name");
let app = fake_app(options);

// Get filename
let who = app.who(&0, true);
// Get participant name
let who = app.who(&Some(0), true);
assert_eq!(who, "Name".to_string());
}

#[test]
fn can_get_who_none_me() {
let options = fake_options();
let app = fake_app(options);

// Get participant name
let who = app.who(&None, true);
assert_eq!(who, "Me".to_string());
}

#[test]
fn can_get_who_none_them() {
let options = fake_options();
let app = fake_app(options);

// Get participant name
let who = app.who(&None, false);
assert_eq!(who, "Unknown".to_string());
}

#[test]
fn can_get_chat_valid() {
let options = fake_options();
Expand Down
10 changes: 5 additions & 5 deletions imessage-exporter/src/exporters/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ mod tests {
guid: String::default(),
text: None,
service: Some("iMessage".to_string()),
handle_id: i32::default(),
handle_id: Some(i32::default()),
subject: None,
date: i64::default(),
date_read: i64::default(),
Expand Down Expand Up @@ -1276,7 +1276,7 @@ mod tests {
// May 17, 2022 8:29:42 PM
message.date = 674526582885055488;
message.text = Some("Hello world".to_string());
message.handle_id = 999999;
message.handle_id = Some(999999);

let actual = exporter.format_message(&message, 0).unwrap();
let expected = "<div class=\"message\">\n<div class=\"received\">\n<p><span class=\"timestamp\">May 17, 2022 5:29:42 PM</span>\n<span class=\"sender\">Sample Contact</span></p>\n<hr><div class=\"message_part\">\n<span class=\"bubble\">Hello world</span>\n</div>\n</div>\n</div>\n";
Expand All @@ -1295,7 +1295,7 @@ mod tests {
let exporter = HTML::new(&config);

let mut message = blank();
message.handle_id = 999999;
message.handle_id = Some(999999);
// May 17, 2022 8:29:42 PM
message.date = 674526582885055488;
message.text = Some("Hello world".to_string());
Expand Down Expand Up @@ -1323,7 +1323,7 @@ mod tests {
let exporter = HTML::new(&config);

let mut message = blank();
message.handle_id = 999999;
message.handle_id = Some(999999);
// May 17, 2022 8:29:42 PM
message.date = 674526582885055488;
message.text = Some("Hello world".to_string());
Expand Down Expand Up @@ -1428,7 +1428,7 @@ mod tests {
message.date = 674526582885055488;
message.associated_message_type = Some(2000);
message.associated_message_guid = Some("fake_guid".to_string());
message.handle_id = 999999;
message.handle_id = Some(999999);

let actual = exporter.format_reaction(&message).unwrap();
let expected = "<span class=\"reaction\"><b>Loved</b> by Sample Contact</span>";
Expand Down
10 changes: 5 additions & 5 deletions imessage-exporter/src/exporters/txt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ mod tests {
guid: String::default(),
text: None,
service: Some("iMessage".to_string()),
handle_id: i32::default(),
handle_id: Some(i32::default()),
subject: None,
date: i64::default(),
date_read: i64::default(),
Expand Down Expand Up @@ -926,7 +926,7 @@ mod tests {
// May 17, 2022 8:29:42 PM
message.date = 674526582885055488;
message.text = Some("Hello world".to_string());
message.handle_id = 999999;
message.handle_id = Some(999999);

let actual = exporter.format_message(&message, 0).unwrap();
let expected = "May 17, 2022 5:29:42 PM\nSample Contact\nHello world\n\n";
Expand All @@ -945,7 +945,7 @@ mod tests {
let exporter = TXT::new(&config);

let mut message = blank();
message.handle_id = 999999;
message.handle_id = Some(999999);
// May 17, 2022 8:29:42 PM
message.date = 674526582885055488;
message.text = Some("Hello world".to_string());
Expand Down Expand Up @@ -973,7 +973,7 @@ mod tests {
let exporter = TXT::new(&config);

let mut message = blank();
message.handle_id = 999999;
message.handle_id = Some(999999);
// May 17, 2022 8:29:42 PM
message.date = 674526582885055488;
message.text = Some("Hello world".to_string());
Expand Down Expand Up @@ -1078,7 +1078,7 @@ mod tests {
message.date = 674526582885055488;
message.associated_message_type = Some(2000);
message.associated_message_guid = Some("fake_guid".to_string());
message.handle_id = 999999;
message.handle_id = Some(999999);

let actual = exporter.format_reaction(&message).unwrap();
let expected = "Loved by Sample Contact";
Expand Down

0 comments on commit 995c81b

Please sign in to comment.