rust_macios/contacts/
cn_save_request.rs1use objc::{msg_send, sel, sel_impl};
2
3use crate::{
4 foundation::NSString,
5 object,
6 objective_c_runtime::{
7 macros::interface_impl,
8 nil,
9 traits::{FromId, PNSObject},
10 },
11 utils::to_bool,
12};
13
14use super::{CNMutableContact, CNMutableGroup, ICNContact, ICNGroup};
15
16object! {
17 unsafe pub struct CNSaveRequest;
19}
20
21#[interface_impl(NSObject)]
22impl CNSaveRequest {
23 #[method]
33 pub fn add_contact_to_container_with_identifier<Contact>(
34 &self,
35 contact: Contact,
36 identifier: Option<NSString>,
37 ) where
38 Contact: ICNContact,
39 {
40 match identifier {
41 Some(identifier) => unsafe {
42 msg_send![self.m_self(), addContact: contact.m_self() toContainerWithIdentifier: identifier]
43 },
44 None => unsafe {
45 msg_send![self.m_self(), addContact: contact.m_self() toContainerWithIdentifier: nil]
46 },
47 }
48 }
49
50 #[method]
52 pub fn update_contact(&self, contact: CNMutableContact) {
53 unsafe { msg_send![self.m_self(), updateContact: contact] }
54 }
55
56 #[method]
58 pub fn delete_contact(&self, contact: CNMutableContact) {
59 unsafe { msg_send![self.m_self(), deleteContact: contact] }
60 }
61
62 #[method]
66 pub fn add_group_to_container_with_identifier(
67 &self,
68 group: CNMutableGroup,
69 identifier: NSString,
70 ) {
71 unsafe { msg_send![self.m_self(), addGroup: group toContainerWithIdentifier: identifier] }
72 }
73
74 #[method]
76 pub fn update_group(&self, group: CNMutableGroup) {
77 unsafe { msg_send![self.m_self(), updateGroup: group] }
78 }
79
80 #[method]
82 pub fn delete_group(&self, group: CNMutableGroup) {
83 unsafe { msg_send![self.m_self(), deleteGroup: group] }
84 }
85
86 #[method]
88 pub fn add_member_to_group<Contact, Group>(&self, contact: Contact, group: Group)
89 where
90 Contact: ICNContact,
91 Group: ICNGroup,
92 {
93 unsafe { msg_send![self.m_self(), addMember: contact toGroup: group] }
94 }
95
96 #[method]
98 pub fn remove_member_from_group<Contact, Group>(&self, contact: Contact, group: Group)
99 where
100 Contact: ICNContact,
101 Group: ICNGroup,
102 {
103 unsafe { msg_send![self.m_self(), removeMember: contact fromGroup: group] }
104 }
105
106 #[method]
111 pub fn add_subgroup_to_group<Group, ParentGroup>(&self, group: Group, parent_group: ParentGroup)
112 where
113 Group: ICNGroup,
114 ParentGroup: ICNGroup,
115 {
116 unsafe { msg_send![self.m_self(), addSubgroup: group toGroup: parent_group] }
117 }
118
119 #[method]
121 pub fn remove_subgroup_from_group<Group, ParentGroup>(
122 &self,
123 group: Group,
124 parent_group: ParentGroup,
125 ) where
126 Group: ICNGroup,
127 ParentGroup: ICNGroup,
128 {
129 unsafe { msg_send![self.m_self(), removeSubgroup: group fromGroup: parent_group] }
130 }
131
132 #[property]
137 pub fn should_refetch_contacts(&self) -> bool {
138 unsafe { to_bool(msg_send![self.m_self(), shouldRefetchContacts]) }
139 }
140
141 #[property]
143 pub fn transaction_author(&self) -> NSString {
144 unsafe { NSString::from_id(msg_send![self.m_self(), transactionAuthor]) }
145 }
146}