From 36ca7f63aa7d5986bbd512652eae1d151c6deae9 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Tue, 19 Nov 2024 16:47:41 -0500 Subject: [PATCH] dev: update referral and share notifs --- src/backend/src/services/EmailService.js | 11 ++++++----- src/backend/src/services/NotificationService.js | 5 +++++ src/backend/src/services/ReferralCodeService.js | 16 +++++++++++++++- src/backend/src/structured/sequence/share.js | 13 +++++++++++++ 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/backend/src/services/EmailService.js b/src/backend/src/services/EmailService.js index d00e7632..21ddfab1 100644 --- a/src/backend/src/services/EmailService.js +++ b/src/backend/src/services/EmailService.js @@ -132,21 +132,22 @@ If this was not you, please contact support@puter.com immediately. ` }, // TODO: revise email contents - 'share_existing_user': { + 'share_by_username': { subject: 'Puter share from {{susername}}', - html: ` + html: /*html*/`

Hi there {{rusername}},

-

{{link}}

+

You've received a share from {{susername}} on Puter.

+

Go to puter.com to check it out.

Sincerely,

Puter

` }, 'share_by_email': { subject: 'share by email', - html: ` + html: /*html*/`

Hi there,

You've received a share from {{sender_name}} on Puter:

-

{{link}}

+

{{link}}

Sincerely,

Puter

` diff --git a/src/backend/src/services/NotificationService.js b/src/backend/src/services/NotificationService.js index 89412e36..3be1d189 100644 --- a/src/backend/src/services/NotificationService.js +++ b/src/backend/src/services/NotificationService.js @@ -29,6 +29,10 @@ const UsernameNotifSelector = username => async (self) => { return [user.id]; }; +const UserIDNotifSelector = user_id => async (self) => { + return [user_id]; +}; + class NotificationService extends BaseService { static MODULES = { uuidv4: require('uuid').v4, @@ -214,4 +218,5 @@ class NotificationService extends BaseService { module.exports = { NotificationService, UsernameNotifSelector, + UserIDNotifSelector, }; diff --git a/src/backend/src/services/ReferralCodeService.js b/src/backend/src/services/ReferralCodeService.js index b3660a4f..151bc9af 100644 --- a/src/backend/src/services/ReferralCodeService.js +++ b/src/backend/src/services/ReferralCodeService.js @@ -22,6 +22,7 @@ const { Context } = require('../util/context'); const { get_user } = require('../helpers'); const { DB_WRITE } = require('./database/consts'); const BaseService = require('./BaseService'); +const { UsernameNotifSelector, UserIDNotifSelector } = require('./NotificationService'); class ReferralCodeService extends BaseService { _construct () { @@ -117,7 +118,20 @@ class ReferralCodeService extends BaseService { const svc_email = Context.get('services').get('email'); await svc_email.send_email (referred_by, 'new-referral', { storage_increase: this.STORAGE_INCREASE_STRING - }) + }); + + const svc_notification = Context.get('services').get('notification'); + svc_notification.notify(UserIDNotifSelector(referred_by.id), { + source: 'referral', + icon: 'c-check.svg', + text: `You have referred user ${user.username} and ` + + `have received ${this.STORAGE_INCREASE_STRING} of storage.`, + template: 'referral', + fields: { + storage_increase: this.STORAGE_INCREASE_STRING, + referred_username: user.username + } + }); } } diff --git a/src/backend/src/structured/sequence/share.js b/src/backend/src/structured/sequence/share.js index 26fc187f..b59fd4e2 100644 --- a/src/backend/src/structured/sequence/share.js +++ b/src/backend/src/structured/sequence/share.js @@ -485,6 +485,7 @@ module.exports = new Sequence([ const svc_permission = a.iget('services').get('permission'); const svc_notification = a.iget('services').get('notification'); + const svc_email = a.iget('services').get('email'); const actor = a.get('actor'); @@ -541,6 +542,18 @@ module.exports = new Sequence([ (files.length === 1 ? 'file' : 'files') + ' ' + 'with you.', }); + + + // Working on notifications + // Email should have a link to a shared file, right? + // .. how do I make those URLs? (gui feature) + await svc_email.send_email({ + email: recipient_item.user.email, + }, 'share_by_username', { + // link: // TODO: create a link to the shared file + susername: actor.type.user.username, + rusername: username, + }); result.recipients[recipient_item.i] = { $: 'api:status-report', status: 'success' };