Skip to content

Commit

Permalink
Merge pull request #107 from ReagentX/develop
Browse files Browse the repository at this point in the history
Coyote Mint
  • Loading branch information
ReagentX authored Apr 10, 2023
2 parents b61bc81 + 9c5f185 commit fd13ddb
Show file tree
Hide file tree
Showing 19 changed files with 450 additions and 127 deletions.
112 changes: 68 additions & 44 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Documentation for the library is located [here](imessage-database/README.md).

### Supported Features

This crate supports every iMessage feature as of MacOS 13.2.1 (22D68):
This crate supports every iMessage feature as of MacOS 13.3.1 (22E261):

- Multi-part messages
- Replies/Threads
Expand Down
6 changes: 3 additions & 3 deletions imessage-database/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ repository = "https://github.com/ReagentX/imessage-exporter"
version = "0.0.0"

[dependencies]
chrono = "0.4.23"
plist = "1.3.1"
rusqlite = {version = "0.28.0", features = ["blob", "bundled"]}
chrono = "0.4.24"
plist = "1.4.3"
rusqlite = {version = "0.29.0", features = ["blob", "bundled"]}
2 changes: 1 addition & 1 deletion imessage-database/src/error/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
This module contains types of errors that can happen when parsing iMessage data
This module contains types of errors that can happen when parsing iMessage data.
*/

pub mod message;
Expand Down
16 changes: 15 additions & 1 deletion imessage-database/src/message_types/variants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
/// - 1 is the second image
/// - 2 is the third image
/// - 3 is the text of the message
///
///
/// In this example, a Like on `p:2/` is a like on the third image
///
/// Reactions are normal messages in the database, but only the latest reaction
Expand Down Expand Up @@ -83,6 +83,20 @@ pub enum URLOverride<'a> {
Collaboration(CollaborationMessage<'a>),
}

/// Announcement Message Types
///
/// Announcements are messages sent to a thread for actions that are not balloons, i.e.
/// updating the name of the group or changing the group photo
#[derive(Debug)]
pub enum Announcement<'a> {
/// Someone changed the name of the group
NameChange(&'a str),
/// Someone updated the group photo
PhotoChange,
/// Types that may occur in the future, i.e. someone leaving or joining a group
Unknown(&'a i32),
}

/// Message variant container
///
/// Messages can exist as one of many different variants, this encapsulates
Expand Down
2 changes: 1 addition & 1 deletion imessage-database/src/tables/attachment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl Attachment {
pub fn mime_type(&'_ self) -> MediaType<'_> {
match &self.mime_type {
Some(mime) => {
if let Some(mime_str) = mime.split('/').into_iter().next() {
if let Some(mime_str) = mime.split('/').next() {
match mime_str {
"image" => MediaType::Image(mime),
"video" => MediaType::Video(mime),
Expand Down
20 changes: 18 additions & 2 deletions imessage-database/src/tables/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
error::{message::MessageError, table::TableError},
message_types::{
expressives::{BubbleEffect, Expressive, ScreenEffect},
variants::{CustomBalloon, Reaction, Variant},
variants::{Announcement, CustomBalloon, Reaction, Variant},
},
tables::table::{
Cacheable, Diagnostic, Table, ATTRIBUTED_BODY, CHAT_MESSAGE_JOIN, MESSAGE,
Expand Down Expand Up @@ -86,6 +86,7 @@ pub struct Message {
pub is_read: bool,
pub item_type: i32,
pub group_title: Option<String>,
pub group_action_type: i32,
pub associated_message_guid: Option<String>,
pub associated_message_type: Option<i32>,
pub balloon_bundle_id: Option<String>,
Expand Down Expand Up @@ -114,6 +115,7 @@ impl Table for Message {
is_read: row.get("is_read")?,
item_type: row.get("item_type").unwrap_or_default(),
group_title: row.get("group_title").unwrap_or(None),
group_action_type: row.get("group_action_type").unwrap_or(0),
associated_message_guid: row.get("associated_message_guid").unwrap_or(None),
associated_message_type: row.get("associated_message_type").unwrap_or(None),
balloon_bundle_id: row.get("balloon_bundle_id").unwrap_or(None),
Expand Down Expand Up @@ -431,7 +433,7 @@ impl Message {

/// `true` if the message renames a thread, else `false`
pub fn is_announcement(&self) -> bool {
self.group_title.is_some()
self.group_title.is_some() || self.group_action_type != 0
}

/// `true` if the message is a reaction to another message, else `false`
Expand Down Expand Up @@ -764,6 +766,19 @@ impl Message {
Variant::Normal
}

/// Determine the type of announcement a message contains, if it contains one
pub fn get_announcement(&self) -> Option<Announcement> {
if let Some(name) = &self.group_title {
return Some(Announcement::NameChange(name));
}

return match &self.group_action_type {
0 => None,
1 => Some(Announcement::PhotoChange),
other => Some(Announcement::Unknown(other)),
};
}

/// Determine the service the message was sent from, i.e. iMessage, SMS, IRC, etc.
pub fn service(&self) -> Service {
match self.service.as_deref() {
Expand Down Expand Up @@ -894,6 +909,7 @@ mod tests {
is_read: false,
item_type: 0,
group_title: None,
group_action_type: 0,
associated_message_guid: None,
associated_message_type: Some(i32::default()),
balloon_bundle_id: None,
Expand Down
3 changes: 2 additions & 1 deletion imessage-database/src/tables/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ pub const MESSAGE_SUMMARY_INFO: &str = "message_summary_info";
pub const ATTRIBUTED_BODY: &str = "attributedBody";

// Default information
/// Name used for messages sent by the database owner
/// Names used for messages sent by the database owner
pub const ME: &str = "Me";
pub const YOU: &str = "You";
/// Name used for contacts or chats where the name cannot be discovered
pub const UNKNOWN: &str = "Unknown";
/// Default location for the Messages database
Expand Down
Loading

0 comments on commit fd13ddb

Please # to comment.