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 d10ddbe
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 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
3 changes: 3 additions & 0 deletions deltachat-ios/Chat/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2120,7 +2120,10 @@ extension ChatViewController {
}

func didTapVcard(msg: DcMsg) {
guard let file = msg.file else { return }
let vcard = dcContext.parseVcard(path: file)
let name = "foo bar"

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

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

public func deleteMessage(msgId: Int) {
dc_delete_msgs(contextPointer, [UInt32(msgId)], 1)
}
Expand Down
34 changes: 34 additions & 0 deletions deltachat-ios/DC/DcVcard.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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 contactColor: String

// Last update timestamp.
public let timestamp: Int64

public init(addr: String, displayName: String, key: String? = nil, profileImage: String? = nil, contactColor: String, timestamp: Int64) {
self.addr = addr
self.displayName = displayName
self.key = key
self.profileImage = profileImage
self.contactColor = contactColor
self.timestamp = timestamp
}
}

struct DcVcardContactResult: Decodable {
let result: DcVcardContact
}

0 comments on commit d10ddbe

Please sign in to comment.