Skip to content

Commit 42e8181

Browse files
authored
feat: FCM HTTP v1 changes (#787)
1 parent b555830 commit 42e8181

File tree

6 files changed

+93
-29
lines changed

6 files changed

+93
-29
lines changed

android/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ android {
7979
applicationId "com.chatwoot.app"
8080
minSdkVersion rootProject.ext.minSdkVersion
8181
targetSdkVersion rootProject.ext.targetSdkVersion
82-
versionCode 5180031
83-
versionName "1.10.40"
82+
versionCode 5180032
83+
versionName "1.10.41"
8484
}
8585
lintOptions {
8686
checkReleaseBuilds false

ios/Chatwoot.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@
561561
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
562562
CLANG_ENABLE_MODULES = YES;
563563
CODE_SIGN_ENTITLEMENTS = Chatwoot/Chatwoot.entitlements;
564-
CURRENT_PROJECT_VERSION = 340;
564+
CURRENT_PROJECT_VERSION = 341;
565565
DEVELOPMENT_TEAM = L7YLMN4634;
566566
ENABLE_BITCODE = NO;
567567
INFOPLIST_FILE = Chatwoot/Info.plist;
@@ -570,7 +570,7 @@
570570
"$(inherited)",
571571
"@executable_path/Frameworks",
572572
);
573-
MARKETING_VERSION = 1.10.40;
573+
MARKETING_VERSION = 1.10.41;
574574
OTHER_LDFLAGS = (
575575
"$(inherited)",
576576
"-ObjC",
@@ -595,15 +595,15 @@
595595
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
596596
CLANG_ENABLE_MODULES = YES;
597597
CODE_SIGN_ENTITLEMENTS = Chatwoot/Chatwoot.entitlements;
598-
CURRENT_PROJECT_VERSION = 340;
598+
CURRENT_PROJECT_VERSION = 341;
599599
DEVELOPMENT_TEAM = L7YLMN4634;
600600
INFOPLIST_FILE = Chatwoot/Info.plist;
601601
INFOPLIST_KEY_CFBundleDisplayName = Chatwoot;
602602
LD_RUNPATH_SEARCH_PATHS = (
603603
"$(inherited)",
604604
"@executable_path/Frameworks",
605605
);
606-
MARKETING_VERSION = 1.10.40;
606+
MARKETING_VERSION = 1.10.41;
607607
OTHER_LDFLAGS = (
608608
"$(inherited)",
609609
"-ObjC",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@chatwoot/mobile-app",
3-
"version": "1.10.40",
3+
"version": "1.10.41",
44
"private": true,
55
"scripts": {
66
"android": "react-native run-android",

src/helpers/PushHelper.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ export const updateBadgeCount = ({ count = 0 }) => {
1616
};
1717

1818
export const findConversationLinkFromPush = ({ notification, installationUrl }) => {
19-
const pushData = JSON.parse(notification);
20-
21-
const { notification_type } = pushData;
19+
const { notification_type } = notification;
2220

2321
if (NOTIFICATION_TYPES.includes(notification_type)) {
24-
const { primary_actor, primary_actor_id, primary_actor_type } = pushData;
22+
const { primary_actor, primary_actor_id, primary_actor_type } = notification;
2523
let conversationId = null;
2624
if (primary_actor_type === 'Conversation') {
2725
conversationId = primary_actor.id;
@@ -35,3 +33,17 @@ export const findConversationLinkFromPush = ({ notification, installationUrl })
3533
}
3634
return;
3735
};
36+
37+
export const findNotificationFromFCM = ({ message }) => {
38+
let notification = null;
39+
// FCM HTTP v1
40+
if (message?.data?.payload) {
41+
const parsedPayload = JSON.parse(message.data.payload);
42+
notification = parsedPayload.data.notification;
43+
}
44+
// FCM legacy. It will be deprecated soon
45+
else {
46+
notification = JSON.parse(message.data.notification);
47+
}
48+
return notification;
49+
};

src/helpers/specs/pushHelper.spec.js

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
1-
import { findConversationLinkFromPush } from '../PushHelper';
1+
import { findConversationLinkFromPush, findNotificationFromFCM } from '../PushHelper';
22

33
describe('findConversationLinkFromPush', () => {
44
it('should return conversation link if notification_type is conversation_creation', () => {
5-
const notification =
6-
'{"id":8687,"notification_type":"conversation_creation","primary_actor_id":14902,"primary_actor_type":"Conversation","primary_actor":{"id":14428}}';
5+
const notification = {
6+
id: 8687,
7+
notification_type: 'conversation_creation',
8+
primary_actor_id: 14902,
9+
primary_actor_type: 'Conversation',
10+
primary_actor: { id: 14428 },
11+
};
712
const installationUrl = 'https://app.chatwoot.com';
813
const result = findConversationLinkFromPush({ notification, installationUrl });
914
expect(result).toBe(
1015
'https://app.chatwoot.com/app/accounts/1/conversations/14428/14902/Conversation',
1116
);
1217
});
18+
1319
it('should return conversation link if notification_type is conversation_assignment', () => {
14-
const notification =
15-
'{"id":8696,"notification_type":"conversation_assignment","primary_actor_id":3104,"primary_actor_type":"Conversation","primary_actor":{"id":2684}}';
20+
const notification = {
21+
id: 8696,
22+
notification_type: 'conversation_assignment',
23+
primary_actor_id: 3104,
24+
primary_actor_type: 'Conversation',
25+
primary_actor: { id: 2684 },
26+
};
1627
const installationUrl = 'https://app.chatwoot.com';
1728
const result = findConversationLinkFromPush({ notification, installationUrl });
1829
expect(result).toBe(
@@ -21,8 +32,13 @@ describe('findConversationLinkFromPush', () => {
2132
});
2233

2334
it('should return conversation link if notification_type is assigned_conversation_new_message', () => {
24-
const notification =
25-
'{"id":8694,"notification_type":"assigned_conversation_new_message","primary_actor_id":58731,"primary_actor_type":"Message","primary_actor":{"conversation_id":14429,"id":58731}}';
35+
const notification = {
36+
id: 8694,
37+
notification_type: 'assigned_conversation_new_message',
38+
primary_actor_id: 58731,
39+
primary_actor_type: 'Message',
40+
primary_actor: { conversation_id: 14429, id: 58731 },
41+
};
2642
const installationUrl = 'https://app.chatwoot.com';
2743
const result = findConversationLinkFromPush({ notification, installationUrl });
2844
expect(result).toBe(
@@ -31,8 +47,13 @@ describe('findConversationLinkFromPush', () => {
3147
});
3248

3349
it('should return conversation link if notification_type is conversation_mention', () => {
34-
const notification =
35-
'{"id":8690,"notification_type":"conversation_mention","primary_actor_id":58725,"primary_actor_type":"Message","primary_actor":{"conversation_id":14428,"id":58725}}';
50+
const notification = {
51+
id: 8690,
52+
notification_type: 'conversation_mention',
53+
primary_actor_id: 58725,
54+
primary_actor_type: 'Message',
55+
primary_actor: { conversation_id: 14428, id: 58725 },
56+
};
3657
const installationUrl = 'https://app.chatwoot.com';
3758
const result = findConversationLinkFromPush({ notification, installationUrl });
3859
expect(result).toBe(
@@ -41,21 +62,52 @@ describe('findConversationLinkFromPush', () => {
4162
});
4263

4364
it('should return conversation link if notification_type is participating_conversation_new_message', () => {
44-
const notification =
45-
'{"id":8678,"notification_type":"participating_conversation_new_message","primary_actor_id":58712,"primary_actor_type":"Message","primary_actor":{"conversation_id":14427,"id":58712}}';
46-
65+
const notification = {
66+
id: 8678,
67+
notification_type: 'participating_conversation_new_message',
68+
primary_actor_id: 58712,
69+
primary_actor_type: 'Message',
70+
primary_actor: { conversation_id: 14427, id: 58712 },
71+
};
4772
const installationUrl = 'https://app.chatwoot.com';
4873
const result = findConversationLinkFromPush({ notification, installationUrl });
4974
expect(result).toBe(
5075
'https://app.chatwoot.com/app/accounts/1/conversations/14427/58712/Message',
5176
);
5277
});
53-
it('should return nothing if notification_type is not valid', () => {
54-
const notification =
55-
'{"id":8678,"notification_type":"participating_conversation_message","primary_actor_id":58712,"primary_actor_type":"Message","primary_actor":{"conversation_id":14427,"id":58712}}';
5678

79+
it('should return nothing if notification_type is not valid', () => {
80+
const notification = {
81+
id: 8678,
82+
notification_type: 'participating_conversation_message',
83+
primary_actor_id: 58712,
84+
primary_actor_type: 'Message',
85+
primary_actor: { conversation_id: 14427, id: 58712 },
86+
};
5787
const installationUrl = 'https://app.chatwoot.com';
5888
const result = findConversationLinkFromPush({ notification, installationUrl });
5989
expect(result).toBe(undefined);
6090
});
6191
});
92+
93+
describe('findNotificationFromFCM', () => {
94+
it('should return notification from FCM HTTP v1 message', () => {
95+
const message = {
96+
data: {
97+
payload: '{"data": {"notification": {"id": 123, "title": "Test Notification"}}}',
98+
},
99+
};
100+
const result = findNotificationFromFCM({ message });
101+
expect(result).toEqual({ id: 123, title: 'Test Notification' });
102+
});
103+
104+
it('should return notification from FCM legacy message', () => {
105+
const message = {
106+
data: {
107+
notification: '{"id": 456, "title": "Legacy Notification"}',
108+
},
109+
};
110+
const result = findNotificationFromFCM({ message });
111+
expect(result).toEqual({ id: 456, title: 'Legacy Notification' });
112+
});
113+
});

src/router.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import ConversationAction from './screens/ConversationAction/ConversationAction'
2121
import TabStack from './components/TabBar';
2222
import i18n from 'i18n';
2323
import { navigationRef } from 'helpers/NavigationHelper';
24-
import { findConversationLinkFromPush } from './helpers/PushHelper';
24+
import { findConversationLinkFromPush, findNotificationFromFCM } from './helpers/PushHelper';
2525
import { extractConversationIdFromUrl } from './helpers/conversationHelpers';
2626
import { selectLoggedIn } from 'reducer/authSlice';
2727
import { selectInstallationUrl, selectLocale } from 'reducer/settingsSlice';
@@ -109,7 +109,7 @@ const App = () => {
109109
// Handle notification caused app to open from quit state:
110110
const message = await messaging().getInitialNotification();
111111
if (message) {
112-
const { notification } = message.data;
112+
const notification = findNotificationFromFCM({ message });
113113
const conversationLink = findConversationLinkFromPush({ notification, installationUrl });
114114
if (conversationLink) {
115115
return conversationLink;
@@ -126,7 +126,7 @@ const App = () => {
126126
// Handle notification caused app to open from background state
127127
const unsubscribeNotification = messaging().onNotificationOpenedApp(message => {
128128
if (message) {
129-
const { notification } = message.data;
129+
const notification = findNotificationFromFCM({ message });
130130

131131
const conversationLink = findConversationLinkFromPush({ notification, installationUrl });
132132
if (conversationLink) {

0 commit comments

Comments
 (0)