Skip to content

Commit

Permalink
add parseVcard api
Browse files Browse the repository at this point in the history
  • Loading branch information
r10s committed May 29, 2024
1 parent 8fcec15 commit aa8d002
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
4 changes: 4 additions & 0 deletions DcCore/DcCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
30E8F24D2449D30200CE2C90 /* DcColors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30E8F24C2449D30200CE2C90 /* DcColors.swift */; };
78072F172A040ED800EB7C98 /* libdeltachat.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 78072F162A040ED800EB7C98 /* libdeltachat.a */; };
7871729629BA495200F110DC /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7871729529BA495200F110DC /* SystemConfiguration.framework */; };
B2F691252C0790140010D9B1 /* DcVcard.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2F691242C0790140010D9B1 /* DcVcard.swift */; };
D8BBF0032B57D8E5008C96FD /* DcAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8BBF0022B57D8E5008C96FD /* DcAccount.swift */; };
D8BBF0052B57D904008C96FD /* DcContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8BBF0042B57D904008C96FD /* DcContext.swift */; };
D8BBF0072B57D91B008C96FD /* DcEventEmitter.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8BBF0062B57D91B008C96FD /* DcEventEmitter.swift */; };
Expand Down Expand Up @@ -68,6 +69,7 @@
7827C8882A04089900B8470D /* libraries */ = {isa = PBXFileReference; lastKnownFileType = folder; name = libraries; path = "../deltachat-ios/libraries"; sourceTree = "<group>"; };
7827C88A2A0408A700B8470D /* libdeltachat.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libdeltachat.a; path = "../deltachat-ios/libraries/deltachat-core-rust/libdeltachat.a"; sourceTree = "<group>"; };
7871729529BA495200F110DC /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/System/Library/Frameworks/SystemConfiguration.framework; sourceTree = DEVELOPER_DIR; };
B2F691242C0790140010D9B1 /* DcVcard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DcVcard.swift; sourceTree = "<group>"; };
D8BBF0022B57D8E5008C96FD /* DcAccount.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DcAccount.swift; sourceTree = "<group>"; };
D8BBF0042B57D904008C96FD /* DcContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DcContext.swift; sourceTree = "<group>"; };
D8BBF0062B57D91B008C96FD /* DcEventEmitter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DcEventEmitter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -142,6 +144,7 @@
D8BBF0102B57D96F008C96FD /* DcMsg.swift */,
D8BBF0182B57D9AE008C96FD /* DcProvider.swift */,
D8BBF01A2B57D9BE008C96FD /* DcReaction.swift */,
B2F691242C0790140010D9B1 /* DcVcard.swift */,
30421985243F209E00516852 /* events.swift */,
30421961243E26C800516852 /* Logger.swift */,
3042194E243DE15D00516852 /* wrapper.c */,
Expand Down Expand Up @@ -318,6 +321,7 @@
D8BBF0132B57D97B008C96FD /* DcContact.swift in Sources */,
D8BBF0112B57D96F008C96FD /* DcMsg.swift in Sources */,
D8BBF00B2B57D93D008C96FD /* DcChatlist.swift in Sources */,
B2F691252C0790140010D9B1 /* DcVcard.swift in Sources */,
D8BBF0052B57D904008C96FD /* DcContext.swift in Sources */,
D8BBF0172B57D99F008C96FD /* DcBackupProvider.swift in Sources */,
304F5E41244F2F3200462538 /* UIImage+Extensions.swift in Sources */,
Expand Down
7 changes: 5 additions & 2 deletions deltachat-ios/Chat/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2120,8 +2120,11 @@ extension ChatViewController {
}

func didTapVcard(msg: DcMsg) {
let name = "foo bar"
let alert = UIAlertController(title: String.localizedStringWithFormat(String.localized("ask_start_chat_with"), name), message: nil, preferredStyle: .safeActionSheet)
guard let file = msg.file else { return }
guard let vcards = dcContext.parseVcard(path: file) else { return }
guard let vcard = vcards.first else { return }

let alert = UIAlertController(title: String.localizedStringWithFormat(String.localized("ask_start_chat_with"), vcard.displayName), message: nil, preferredStyle: .safeActionSheet)
alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
}))
alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
Expand Down
17 changes: 17 additions & 0 deletions deltachat-ios/DC/DcContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,23 @@ public class DcContext {
}
}

public func parseVcard(path: String) -> [DcVcardContact]? {
if let data = DcAccounts.shared.blockingCall(method: "parse_vcard", params: [path as AnyObject]) {
do {
return try JSONDecoder().decode(DcVcardContactResult.self, from: data).result
} catch {
logger.error("cannot parse vcard: \(error)")
}
}
return nil
}

public func importVcard(path: String) -> [Int]? {
DcAccounts.shared.blockingCall(method: "import_vcard", params: [path as AnyObject])
return nil
}


public func deleteMessage(msgId: Int) {
dc_delete_msgs(contextPointer, [UInt32(msgId)], 1)
}
Expand Down
25 changes: 25 additions & 0 deletions deltachat-ios/DC/DcVcard.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Foundation

public struct DcVcardContact: Decodable {
/// Email address.
public let addr: String

/// The contact's name, or the email address if no name was given.
public let displayName: String

/// Public PGP key in Base64.
public let key: String?

/// Profile image in Base64.
public let profileImage: String?

/// Contact color as hex string.
public let color: String

// Last update timestamp.
public let timestamp: Int64
}

struct DcVcardContactResult: Decodable {
let result: [DcVcardContact]
}

0 comments on commit aa8d002

Please sign in to comment.