Skip to content

Commit

Permalink
feat: group support to communication push (#1017)
Browse files Browse the repository at this point in the history
  • Loading branch information
focux authored Jun 10, 2024
1 parent ddf7485 commit 0239339
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
34 changes: 32 additions & 2 deletions ios/NotifeeCore/NotifeeCoreUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -738,16 +738,46 @@ + (INSendMessageIntent *)generateSenderIntentForCommunicationNotification:
contactIdentifier:nil
customIdentifier:nil];

NSMutableArray *recipients = nil;

INSpeakableString *speakableGroupName = nil;
if (communicationInfo[@"groupName"] != nil) {
speakableGroupName = [[INSpeakableString alloc] initWithSpokenPhrase:communicationInfo[@"groupName"]];

// For the `groupName` to work we need to have more than one recipient, otherwise, it won't be recognized
// as a group communication. For this reason, we are adding a placeholder person to the recipients which is
// not going to do any harm, the recipients are used as a fallback for when you don't have a `groupName`
// it concatenates the recipients name and then use that as a group name.
INPersonHandle *placeholderPersonHandle =
[[INPersonHandle alloc] initWithValue:@"placeholderId" type:INPersonHandleTypeUnknown];
INPerson *placeholderPerson = [[INPerson alloc] initWithPersonHandle:placeholderPersonHandle
nameComponents:nil
displayName:sender[@"displayName"]
image:avatar
contactIdentifier:nil
customIdentifier:nil];
recipients = [NSMutableArray array];
[recipients addObject:senderPerson];
[recipients addObject:placeholderPerson];
}

INSendMessageIntent *intent =
[[INSendMessageIntent alloc] initWithRecipients:nil
[[INSendMessageIntent alloc] initWithRecipients:recipients
outgoingMessageType:INOutgoingMessageTypeOutgoingMessageText
content:communicationInfo[@"body"]
speakableGroupName:nil
speakableGroupName:speakableGroupName
conversationIdentifier:communicationInfo[@"conversationId"]
serviceName:nil
sender:senderPerson
attachments:nil];

if (communicationInfo[@"groupAvatar"] != nil) {
NSURL *groupAvatarURL = [[NSURL alloc] initWithString:communicationInfo[@"groupAvatar"]];
INImage *groupAvatarImage = [INImage imageWithURL:groupAvatarURL];

[intent setImage:groupAvatarImage forParameterNamed:@"speakableGroupName"];
}

return intent;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/src/types/NotificationIOS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ export interface NotificationIOS {
export interface IOSCommunicationInfo {
conversationId: string;
body?: string;
groupName?: string;
groupAvatar?: string;
sender: IOSCommunicationInfoPerson;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,21 @@ export default function validateIOSCommunicationInfo(
out.body = communicationInfo.body;
}

if (communicationInfo.groupName) {
if (!isString(communicationInfo.groupName)) {
throw new Error("'groupName' expected a valid string value.");
}

out.groupName = communicationInfo.groupName;
}

if (communicationInfo.groupAvatar) {
if (!isString(communicationInfo.groupAvatar)) {
throw new Error("'groupAvatar' expected a valid string value.");
}

out.groupAvatar = communicationInfo.groupAvatar;
}

return out;
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ describe('Validate IOS Notification', () => {
const $ = validateIOSNotification({
communicationInfo: {
conversationId: 'id',
groupName: "Friends",

Check failure on line 73 in tests_react_native/__tests__/validators/validateIOSNotification.test.ts

View workflow job for this annotation

GitHub Actions / ESLint

Replace `"Friends"` with `'Friends'`
sender: {
id: 'sender-id',
displayName: 'John Doe',
Expand All @@ -79,6 +80,7 @@ describe('Validate IOS Notification', () => {
expect($).toEqual({
communicationInfo: {
conversationId: 'id',
groupName: "Friends",

Check failure on line 83 in tests_react_native/__tests__/validators/validateIOSNotification.test.ts

View workflow job for this annotation

GitHub Actions / ESLint

Replace `"Friends"` with `'Friends'`
sender: {
id: 'sender-id',
displayName: 'John Doe',
Expand Down
2 changes: 2 additions & 0 deletions tests_react_native/example/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export const notifications: { key: string; notification: Notification | Notifica
categoryId: 'communicationId',
communicationInfo: {
conversationId: '123',
groupName: "Friends",

Check failure on line 73 in tests_react_native/example/notifications.ts

View workflow job for this annotation

GitHub Actions / ESLint

Replace `"Friends"` with `'Friends'`
groupAvatar: 'https://pbs.twimg.com/profile_images/1070077650713133056/oji2RT4i_normal.jpg',

Check failure on line 74 in tests_react_native/example/notifications.ts

View workflow job for this annotation

GitHub Actions / ESLint

Insert `⏎···········`
sender: {
id: 'abcde',
avatar: 'https://pbs.twimg.com/profile_images/1070077650713133056/oji2RT4i_normal.jpg',
Expand Down
1 change: 1 addition & 0 deletions tests_react_native/sendPushNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var payload = {
ios: {
communicationInfo: {
conversationId: 'id-abcde',
groupName: "Friends",
sender: {
id: 'senderId',
avatar: 'https://placeimg.com/640/480/any',
Expand Down

0 comments on commit 0239339

Please sign in to comment.