Skip to content

Commit 1d5eae7

Browse files
authored
Merge pull request #763 from mrpmohiburrahman/mrp/add-group-functionality
feat: add group functionality
2 parents 6ef00ab + cd982b1 commit 1d5eae7

File tree

6 files changed

+432
-2
lines changed

6 files changed

+432
-2
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,16 @@ If you'd like to read/write the contact's notes, call the `iosEnableNotesUsage(t
194194
* `requestPermission()`: Promise<string> - request permission to access Contacts _ios only_
195195
* `writePhotoToPath()` - writes the contact photo to a given path _android only_
196196

197+
### ios group specific functions
198+
* `getGroups()`: Promise - returns an array of all groups. Each group contains `{ identifier: string; name: string;}`
199+
* `getGroup: (identifier: string)`: Promise - returns the group matching the provided group identifier.
200+
* `deleteGroup(identifier: string)`: Promise - deletes a group by group identifier.
201+
* `updateGroup(identifier: string, groupData: Pick<Group, 'name'>`: Promise - updates an existing group's details. You can only change the group name.
202+
* `addGroup(group: Pick<Group, 'name'>)`: Promise - adds a new group. Group name should be provided.
203+
* `contactsInGroup(identifier: string)`: Promise - retrieves all contacts within a specified group.
204+
* `addContactsToGroup(groupIdentifier: string, contactIdentifiers: string[])`: Promise - adds contacts to a group. Only contacts with id that has `:ABperson` as suffix can be added.
205+
* `removeContactsFromGroup(groupIdentifier: string, contactIdentifiers: string[])`: Promise - removes specified contacts from a group.
206+
197207
## Example Contact Record
198208
```js
199209
{

index.d.ts

+12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ export function requestPermission(): Promise<'authorized' | 'denied' | 'undefine
1818
export function writePhotoToPath(contactId: string, file: string): Promise<boolean>;
1919
export function iosEnableNotesUsage(enabled: boolean): void;
2020

21+
export function getGroups(): Promise<Group[]>;
22+
export function getGroup(identifier: string): Promise<Group | null>;
23+
export function deleteGroup(identifier: string): Promise<boolean>;
24+
export function updateGroup(identifier: string, groupData: Pick<Group, 'name'>): Promise<Group>;
25+
export function addGroup(group: Pick<Group, 'name'>): Promise<Group>;
26+
export function contactsInGroup(identifier: string): Promise<Contact[]>;
27+
export function addContactsToGroup(groupIdentifier: string, contactIdentifiers: string[]): Promise<boolean>;
28+
export function removeContactsFromGroup(groupIdentifier: string, contactIdentifiers: string[]): Promise<boolean>;
29+
export interface Group {
30+
identifier: string;
31+
name: string;
32+
}
2133
export interface EmailAddress {
2234
label: string;
2335
email: string;

index.ts

+34-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NativeModules } from "react-native";
22
import NativeContacts from "./src/NativeContacts";
3-
import { Contact, PermissionType } from "./type";
3+
import { Contact, Group, PermissionType } from "./type";
44

55
const isTurboModuleEnabled = global.__turboModuleProxy != null;
66
const Contacts = isTurboModuleEnabled ? NativeContacts : NativeModules.Contacts;
@@ -87,6 +87,31 @@ async function writePhotoToPath(
8787
): Promise<boolean> {
8888
return Contacts.writePhotoToPath(contactId, file);
8989
}
90+
91+
async function getGroups(): Promise<Group[]> {
92+
return Contacts.getGroups();
93+
}
94+
async function getGroup(identifier: string): Promise<Group | null> {
95+
return Contacts.getGroup(identifier);
96+
}
97+
async function deleteGroup(identifier: string): Promise<boolean> {
98+
return Contacts.deleteGroup(identifier);
99+
}
100+
async function updateGroup(identifier: string, groupData: Pick<Group, 'name'>): Promise<Group> {
101+
return Contacts.updateGroup(identifier, groupData);
102+
}
103+
async function addGroup(group: Pick<Group, 'name'>): Promise<Group>{
104+
return Contacts.addGroup(group);
105+
}
106+
async function contactsInGroup(identifier: string): Promise<Contact[]> {
107+
return Contacts.contactsInGroup(identifier);
108+
}
109+
async function addContactsToGroup(groupIdentifier: string, contactIdentifiers: string[]): Promise<boolean> {
110+
return Contacts.addContactsToGroup(groupIdentifier, contactIdentifiers);
111+
}
112+
async function removeContactsFromGroup(groupIdentifier: string, contactIdentifiers: string[]): Promise<boolean> {
113+
return Contacts.removeContactsFromGroup(groupIdentifier, contactIdentifiers);
114+
}
90115
export default {
91116
getAll,
92117
getAllWithoutPhotos,
@@ -106,4 +131,12 @@ export default {
106131
checkPermission,
107132
requestPermission,
108133
writePhotoToPath,
134+
getGroups,
135+
getGroup,
136+
deleteGroup,
137+
updateGroup,
138+
addGroup,
139+
contactsInGroup,
140+
addContactsToGroup,
141+
removeContactsFromGroup
109142
};

0 commit comments

Comments
 (0)