dev: update referral and share notifs

This commit is contained in:
KernelDeimos 2024-11-19 16:47:41 -05:00
parent 0fa3be9d43
commit 36ca7f63aa
4 changed files with 39 additions and 6 deletions

View File

@ -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*/`
<p>Hi there {{rusername}},</p>
<p>{{link}}</p>
<p>You've received a share from {{susername}} on Puter.</p>
<p>Go to puter.com to check it out.</p>
<p>Sincerely,</p>
<p>Puter</p>
`
},
'share_by_email': {
subject: 'share by email',
html: `
html: /*html*/`
<p>Hi there,</p>
<p>You've received a share from {{sender_name}} on Puter:</p>
<p>{{link}}</p>
<p><a href="{{link}}">{{link}}</a></p>
<p>Sincerely,</p>
<p>Puter</p>
`

View File

@ -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,
};

View File

@ -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
}
});
}
}

View File

@ -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');
@ -542,6 +543,18 @@ module.exports = new Sequence([
'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' };
}