Skip to content

Commit 1d18e44

Browse files
authored
Fix/notification response (#183)
* fix(notifications): reply original tweet data * fix(notifications): reply original tweet data * fix(notifications): reply original tweet data * fix(notifications): reply original tweet data * fix(notifications): extra data * fix(notifications): extra data * fix(notifications): push notification format * fix(notifications): push notification format * fix(notifications): push notification format * fix(notifications): push notification format * fix(notifications): push notification format * fix(notifications): push notification format * fix(notifications): push notification format * fix(notifications): push notification format * fix(notifications): push notification format * fix(notifications): push notification format * fix(notifications): push notification format * fix(notifications): push notification format * fix(notifications): push notification format * fix(notifications): push notification format * fix(notifications): push notification format * fix(notifications): push notification format * fix(notifications): push notification format
1 parent 4aeee9e commit 1d18e44

File tree

4 files changed

+21
-24
lines changed

4 files changed

+21
-24
lines changed

src/expo/expo.service.spec.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ describe('FCMService', () => {
217217
it('should send LIKE notification successfully', async () => {
218218
const payload = {
219219
likers: [{ name: 'John Doe' }],
220-
tweets: [{ content: 'Tweet content' }],
220+
tweets: [{ content: 'Tweet content', id: 'tweet-123' }],
221221
tweet_id: 'tweet-123',
222222
};
223223

@@ -240,8 +240,7 @@ describe('FCMService', () => {
240240
body: 'Tweet content',
241241
subtitle: 'Tweet content',
242242
data: {
243-
type: NotificationType.LIKE,
244-
...payload,
243+
tweet_id: 'tweet-123',
245244
},
246245
},
247246
]);
@@ -252,7 +251,7 @@ describe('FCMService', () => {
252251
it('should send REPLY notification successfully', async () => {
253252
const payload = {
254253
replier: { name: 'Jane Smith' },
255-
reply_tweet: { content: 'Reply content' },
254+
reply_tweet: { content: 'Reply content', id: 'tweet-456' },
256255
tweet_id: 'tweet-456',
257256
};
258257

@@ -277,7 +276,7 @@ describe('FCMService', () => {
277276
it('should send REPOST notification successfully', async () => {
278277
const payload = {
279278
reposter: { name: 'Bob Johnson' },
280-
tweet: { content: 'Tweet content' },
279+
tweet: { content: 'Tweet content', id: 'tweet-789' },
281280
};
282281

283282
await service.sendNotificationToUserDevice(
@@ -299,7 +298,7 @@ describe('FCMService', () => {
299298
it('should send QUOTE notification successfully', async () => {
300299
const payload = {
301300
quoted_by: { username: 'alice' },
302-
quote: { content: 'Quote content' },
301+
quote: { content: 'Quote content', id: 'tweet-101' },
303302
};
304303

305304
await service.sendNotificationToUserDevice('user-123', NotificationType.QUOTE, payload);
@@ -317,7 +316,7 @@ describe('FCMService', () => {
317316
it('should send MENTION notification successfully', async () => {
318317
const payload = {
319318
mentioned_by: { name: 'Charlie Wilson' },
320-
tweet: { content: 'Tweet content' },
319+
tweet: { content: 'Tweet content', id: 'tweet-202' },
321320
};
322321

323322
await service.sendNotificationToUserDevice(
@@ -339,7 +338,8 @@ describe('FCMService', () => {
339338
it('should send MESSAGE notification successfully', async () => {
340339
const payload = {
341340
sender: { name: 'David Lee' },
342-
message: { content: 'Hello!' },
341+
content: 'Hello!',
342+
chat_id: 'chat-123',
343343
};
344344

345345
await service.sendNotificationToUserDevice(
@@ -361,6 +361,7 @@ describe('FCMService', () => {
361361
it('should send FOLLOW notification with follower_name', async () => {
362362
const payload = {
363363
follower_username: 'emma',
364+
follower_id: 'user-303',
364365
};
365366

366367
await service.sendNotificationToUserDevice(
@@ -438,7 +439,7 @@ describe('FCMService', () => {
438439

439440
await service.sendNotificationToUserDevice('user-123', NotificationType.LIKE, {
440441
likers: [{ name: 'Test' }],
441-
tweets: [{ content: 'Content' }],
442+
tweets: [{ content: 'Content', id: 'tweet-1' }],
442443
});
443444

444445
expect(logger_spy).toHaveBeenCalledWith('Notification sent via FCM to user user-123');
@@ -456,7 +457,7 @@ describe('FCMService', () => {
456457
NotificationType.LIKE,
457458
{
458459
likers: [{ name: 'Test' }],
459-
tweets: [{ content: 'Content' }],
460+
tweets: [{ content: 'Content', id: 'tweet-1' }],
460461
}
461462
);
462463

@@ -475,7 +476,7 @@ describe('FCMService', () => {
475476
username: 'complexuser',
476477
},
477478
],
478-
tweets: [{ content: 'Tweet content' }],
479+
tweets: [{ content: 'Tweet content', id: 'tweet-123' }],
479480
tweet_id: 'tweet-123',
480481
};
481482

@@ -485,8 +486,7 @@ describe('FCMService', () => {
485486
expect.arrayContaining([
486487
expect.objectContaining({
487488
data: {
488-
type: NotificationType.LIKE,
489-
...payload,
489+
tweet_id: 'tweet-123',
490490
},
491491
}),
492492
])

src/expo/expo.service.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,7 @@ export class FCMService {
108108
body: notification_content.body,
109109
};
110110

111-
const data = {
112-
type: notification_type,
113-
...payload,
114-
};
115-
116-
await this.sendToDevice(user.fcm_token, data, notification);
111+
await this.sendToDevice(user.fcm_token, notification_content.data, notification);
117112
this.logger.log(`Notification sent via FCM to user ${user_id}`);
118113
return true;
119114
} catch (error) {
@@ -127,13 +122,13 @@ export class FCMService {
127122
private getNotificationContent(
128123
type: NotificationType,
129124
payload: any
130-
): { title: string; body: string; data?: any } {
125+
): { title: string; body: string; data: any } {
131126
switch (type) {
132127
case NotificationType.FOLLOW:
133128
return {
134129
title: 'yapper',
135130
body: `@${payload.follower_username || 'Someone'} followed you!`,
136-
data: { username: payload.follower_id },
131+
data: { user_id: payload.follower_id },
137132
};
138133
case NotificationType.MENTION:
139134
return {
@@ -183,12 +178,14 @@ export class FCMService {
183178
case NotificationType.MESSAGE:
184179
return {
185180
title: payload.sender?.name || 'New Message',
186-
body: payload.message?.content || 'You have a new message',
181+
body: payload.content || 'You have a new message',
182+
data: { chat_id: payload.chat_id },
187183
};
188184
default:
189185
return {
190186
title: 'yapper',
191187
body: 'You have a new notification',
188+
data: {},
192189
};
193190
}
194191
}

src/messages/messages.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export class MessagesService {
149149
sender: {
150150
name: sender.name,
151151
username: sender.username,
152+
chat_id,
152153
},
153154
}
154155
);

src/notifications/notifications.service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,7 @@ export class NotificationsService implements OnModuleInit {
297297
old_notification: aggregation_result.old_notification,
298298
});
299299
} else {
300-
console.log('Send in FCM');
301-
300+
console.log('Send Expo Push Notification');
302301
await this.fcmService.sendNotificationToUserDevice(
303302
user_id,
304303
notification_data.type,

0 commit comments

Comments
 (0)