Skip to content

Commit

Permalink
Better handling of missing phone/icloud details. Fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
hyfen committed Mar 16, 2022
1 parent e4ebff9 commit 02e1785
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion chronicle-imessage.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "chronicle-etl", "~> 0.4.2"
spec.add_dependency "chronicle-etl", "~> 0.4.4"
spec.add_dependency "sqlite3", "~> 1.4"
spec.add_dependency "phonelib", "~> 0.6"

Expand Down
14 changes: 7 additions & 7 deletions lib/chronicle/imessage/imessage_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def extract
meta = {}
meta[:participants] = @chats[message['chat_id']]
meta[:attachments] = @attachments[message['message_id']] if @attachments
meta[:my_phone_contact] = @my_phone_contact
meta[:my_icloud_account] = @my_icloud_account
meta[:my_phone_contact] = @my_phone_contact if @my_phone_contact.values.all?
meta[:my_icloud_account] = @my_icloud_account if @my_icloud_account.values.all?

yield Chronicle::ETL::Extraction.new(data: message, meta: meta)
end
Expand Down Expand Up @@ -58,16 +58,16 @@ def prepare_data

def load_my_phone_contact(local_contacts)
{
phone_number: @config.my_phone_number || local_contacts.my_phone_contact.fetch(:phone_number),
name: @config.my_name || local_contacts.my_phone_contact.fetch(:full_name)
phone_number: @config.my_phone_number || local_contacts.my_phone_contact&.fetch(:phone_number),
name: @config.my_name || local_contacts.my_phone_contact&.fetch(:full_name)
}
end

def load_my_icloud_account(local_contacts)
{
id: @config.icloud_account_id || local_contacts.my_icloud_account.fetch(:AccountID),
dsid: @config.icloud_account_dsid || local_contacts.my_icloud_account.fetch(:AccountDSID),
display_name: @config.icloud_account_display_name || @config.my_name || local_contacts.my_icloud_account.fetch(:DisplayName)
id: nil,
dsid: @config.icloud_account_dsid || local_contacts.my_icloud_account&.fetch(:AccountDSID),
display_name: @config.icloud_account_display_name || @config.my_name || local_contacts.my_icloud_account&.fetch(:DisplayName)
}
end

Expand Down
6 changes: 3 additions & 3 deletions lib/chronicle/imessage/imessage_transformer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def build_attachment(attachment)
end

def build_identity identity
raise ::Chronicle::ETL::UntransformableRecordError.new("Could not build identity", transformation: self) unless identity
raise(Chronicle::ETL::UntransformableRecordError, "Could not build record due to missing identity data") unless identity

record = ::Chronicle::ETL::Models::Entity.new({
represents: 'identity',
Expand All @@ -125,7 +125,7 @@ def build_identity_mine

def build_identity_mine_icloud
icloud_account = @extraction.meta[:my_icloud_account]
raise(UntransformableRecordError, "Missing iCloud account information") unless icloud_account
raise(Chronicle::ETL::UntransformableRecordError, "Could not build record due to missing iCloud details. Please provide them through the extractor settings.") unless icloud_account

record = ::Chronicle::ETL::Models::Entity.new({
represent: 'identity',
Expand All @@ -140,7 +140,7 @@ def build_identity_mine_icloud

def build_identity_mine_phone
phone_account = @extraction.meta[:my_phone_contact]
raise(UntransformableRecordError, "Missing own phone contact information") unless phone_account
raise(Chronicle::ETL::UntransformableRecordError, "Could not build record due to missing phone details. Please provide them through the extractor settings.") unless phone_account

record = ::Chronicle::ETL::Models::Entity.new({
represent: 'identity',
Expand Down
2 changes: 2 additions & 0 deletions lib/chronicle/imessage/local_contacts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def my_icloud_account
@my_icloud_account ||= load_my_icloud_account
end

private

# The synced address book doesn't have a stable folder location so we
# have to search for it
def find_local_icloud_address_book
Expand Down

0 comments on commit 02e1785

Please sign in to comment.