Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion __tests__/notifications/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,9 @@ describe('generateNotification', () => {
expect(actual.notification.targetUrl).toEqual(
'http://localhost:5002/squads/a',
);
expect(actual.notification.title).toEqual('<b>Tsahi</b> joined <b>A</b>');
expect(actual.notification.title).toEqual(
'<b>Tsahi</b> joined <b>A</b>. Say hi!',
);
expect(actual.avatars).toEqual([
{
image: 'http://image.com/a',
Expand Down
4 changes: 2 additions & 2 deletions __tests__/workers/newNotificationV2Mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ it('should set parameters for article_upvote_milestone email', async () => {
post_image: 'https://daily.dev/image.jpg',
post_title: 'P1',
upvotes: '50',
upvote_title: '50 upvotes. Your post is trending 🔥',
upvote_title: '50 upvotes! Trending on the feed 🔥',
});
expect(args.transactional_message_id).toEqual('22');
});
Expand Down Expand Up @@ -682,7 +682,7 @@ it('should set parameters for comment_upvote_milestone email', async () => {
discussion_link:
'http://localhost:5002/posts/p1?utm_source=notification&utm_medium=email&utm_campaign=comment_upvote_milestone#c-c1',
main_comment: 'parent comment',
upvote_title: '50 upvotes. Your post is trending 🔥',
upvote_title: '50 upvotes! Trending on the feed 🔥',
});
expect(args.transactional_message_id).toEqual('44');
});
Expand Down
6 changes: 3 additions & 3 deletions src/notifications/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const notificationTitleMap: Record<
ctx: NotificationPostContext &
NotificationSourceContext &
NotificationDoneByContext,
) => `<b>${ctx.doneBy.name}</b> joined <b>${ctx.source.name}</b>`,
) => `<b>${ctx.doneBy.name}</b> joined <b>${ctx.source.name}</b>. Say hi!`,
squad_new_comment: (ctx: NotificationCommenterContext) =>
`<b>${ctx.commenter.name}</b> <span class="text-theme-color-blueCheese">commented</span> on your post on <b>${ctx.source.name}</b>.`,
squad_reply: (ctx: NotificationCommenterContext) =>
Expand Down Expand Up @@ -150,7 +150,7 @@ export const notificationTitleMap: Record<
user_given_top_reader: (ctx: NotificationUserTopReaderContext) => {
const keyword =
(ctx.keyword.flags as KeywordFlags)?.title || ctx.keyword.value;
return `You earned the <span class="text-theme-color-cabbage">Top Reader</span> badge in ${keyword}`;
return `Great news! You earned the <span class="text-theme-color-cabbage">Top Reader</span> badge in ${keyword}`;
},
source_post_approved: (ctx: NotificationPostContext) =>
`Your post in <b>${ctx.source.name}</b> has been <span class="text-theme-color-cabbage">approved</span> and is now live`,
Expand Down Expand Up @@ -239,7 +239,7 @@ export const notificationTitleMap: Record<
`Your <span class="text-theme-color-cabbage">feedback has been resolved</span>`,
feedback_cancelled: () => feedbackCancelledTitle,
achievement_unlocked: (ctx: NotificationAchievementContext) =>
`<span class="text-theme-color-cabbage">Achievement unlocked!</span> ${ctx.achievementName}`,
`<span class="text-theme-color-cabbage">Achievement unlocked!</span> You earned ${ctx.achievementName}`,
digest_ready: () => `<strong>Your personalized digest is ready</strong>`,
};

Expand Down
32 changes: 26 additions & 6 deletions src/onesignal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const pushHeadingMap: Partial<Record<NotificationType, string>> = {
[NotificationType.SquadReply]: 'New reply',
[NotificationType.CommentMention]: 'You were mentioned',
[NotificationType.PostMention]: 'You were mentioned',
[NotificationType.ArticleUpvoteMilestone]: 'Milestone reached',
[NotificationType.CommentUpvoteMilestone]: 'Milestone reached',
[NotificationType.ArticleUpvoteMilestone]: 'New milestone',
[NotificationType.CommentUpvoteMilestone]: 'New milestone',
[NotificationType.SquadPostAdded]: 'New squad post',
[NotificationType.SquadMemberJoined]: 'New member',
[NotificationType.UserFollow]: 'New follower',
Expand All @@ -36,7 +36,7 @@ const pushHeadingMap: Partial<Record<NotificationType, string>> = {
[NotificationType.DigestReady]: 'Digest ready',
[NotificationType.StreakResetRestore]: 'Streak broken',
[NotificationType.UserGiftedPlus]: 'Plus gift',
[NotificationType.AchievementUnlocked]: 'Achievement unlocked',
[NotificationType.AchievementUnlocked]: 'Level up!',
[NotificationType.PollResult]: 'Poll results',
[NotificationType.PollResultAuthor]: 'Poll results',
[NotificationType.FeedbackResolved]: 'Feedback update',
Expand Down Expand Up @@ -75,8 +75,28 @@ const pushHeadingMap: Partial<Record<NotificationType, string>> = {
[NotificationType.SquadSubscribeToNotification]: 'Squad notifications',
};

const getPushHeading = (type: string): string =>
pushHeadingMap[type as NotificationType] ?? 'daily.dev';
const pushHeadingFnMap: Partial<
Record<NotificationType, (title: string) => string>
> = {
[NotificationType.SquadPostAdded]: (title) => {
const match = title.match(/<b>([^<]+)<\/b>[^<]*<b>([^<]+)<\/b>/);
return match ? `New post in ${match[2]}` : 'New squad post';
},
[NotificationType.SquadNewComment]: (title) => {
const match = title.match(/<b>([^<]+)<\/b>/);
return match ? `${match[1]} commented` : 'New comment';
},
[NotificationType.ArticleNewComment]: (title) => {
const match = title.match(/<b>([^<]+)<\/b>/);
return match ? `${match[1]} commented` : 'New comment';
},
};

const getPushHeading = (type: string, title?: string): string => {
const fn = pushHeadingFnMap[type as NotificationType];
if (fn && title) return fn(title);
return pushHeadingMap[type as NotificationType] ?? 'daily.dev';
};

type PushOpts = { increaseBadge?: boolean };

Expand Down Expand Up @@ -121,7 +141,7 @@ export async function sendPushNotification(

const push = createPush(userIds, targetUrl, type, { increaseBadge: true });
push.contents = { en: basicHtmlStrip(title) };
push.headings = { en: getPushHeading(type) };
push.headings = { en: getPushHeading(type, title) };
push.data = { notificationId: id };
if (avatar) {
push.chrome_web_icon = mapCloudinaryUrl(avatar.image);
Expand Down
26 changes: 13 additions & 13 deletions src/workers/notifications/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,20 +246,20 @@ export async function articleNewCommentHandler(
}

export const UPVOTE_TITLES = {
1: '<span class="text-theme-color-avocado">1 upvote.</span> Your first! 🎉',
3: '<span class="text-theme-color-avocado">3 upvotes.</span> Off to a good start ✨',
5: '<span class="text-theme-color-avocado">5 upvotes.</span> People are reading 👀',
10: '<span class="text-theme-color-avocado">10 upvotes.</span> Double digits 🙌',
20: '<span class="text-theme-color-avocado">20 upvotes.</span> People are noticing 🥳',
50: '<span class="text-theme-color-avocado">50 upvotes.</span> Your post is trending 🔥',
100: '<span class="text-theme-color-avocado">100 upvotes.</span> Triple digits ⚡️',
200: '<span class="text-theme-color-avocado">200 upvotes.</span> This one took off 🚀',
500: '<span class="text-theme-color-avocado">500 upvotes.</span> Going viral 📈',
1000: '<span class="text-theme-color-avocado">1,000 upvotes.</span> Legendary 💎',
2000: '<span class="text-theme-color-avocado">2,000 upvotes.</span> Top of the charts 💥',
5000: '<span class="text-theme-color-avocado">5,000 upvotes.</span> One for the books 🏆',
1: '<span class="text-theme-color-avocado">1 upvote!</span> Off to a good start 🎉',
3: '<span class="text-theme-color-avocado">3 upvotes!</span> No bugs, just vibes ✨',
5: '<span class="text-theme-color-avocado">5 upvotes!</span> Gaining traction 👀',
10: '<span class="text-theme-color-avocado">10 upvotes!</span> New high score 🙌',
20: '<span class="text-theme-color-avocado">20 upvotes!</span> Level up 🥳',
50: '<span class="text-theme-color-avocado">50 upvotes!</span> Trending on the feed 🔥',
100: '<span class="text-theme-color-avocado">100 upvotes!</span> Critical hit ⚡️',
200: '<span class="text-theme-color-avocado">200 upvotes!</span> This one took off 🚀',
500: '<span class="text-theme-color-avocado">500 upvotes!</span> Going viral 📈',
1000: '<span class="text-theme-color-avocado">1,000 upvotes!</span> Legendary unlocked 💎',
2000: '<span class="text-theme-color-avocado">2,000 upvotes!</span> Mythic tier 💥',
5000: '<span class="text-theme-color-avocado">5,000 upvotes!</span> Hall of fame 🏆',
10000:
'<span class="text-theme-color-avocado">10,000 upvotes.</span> History made 👑',
'<span class="text-theme-color-avocado">10,000 upvotes!</span> GOAT 👑',
};
export const UPVOTE_MILESTONES = Object.keys(UPVOTE_TITLES);

Expand Down
Loading