From 5e72e42d32cf422ba762e0f9e643a98cc210e4fa Mon Sep 17 00:00:00 2001 From: "Fabien \"egg\" O'Carroll" Date: Wed, 30 Nov 2022 18:34:41 +0700 Subject: [PATCH] Moved InMemoryEmailSuppressionList to own file This cleans up the service file so we can make the switch to a Mailgun specific implementation later. --- .../InMemoryEmailSuppressionList.js | 36 ++++++++++++++++++ .../email-suppression-list/service.js | 37 +------------------ 2 files changed, 37 insertions(+), 36 deletions(-) create mode 100644 ghost/core/core/server/services/email-suppression-list/InMemoryEmailSuppressionList.js diff --git a/ghost/core/core/server/services/email-suppression-list/InMemoryEmailSuppressionList.js b/ghost/core/core/server/services/email-suppression-list/InMemoryEmailSuppressionList.js new file mode 100644 index 0000000000..36099370f1 --- /dev/null +++ b/ghost/core/core/server/services/email-suppression-list/InMemoryEmailSuppressionList.js @@ -0,0 +1,36 @@ +const {AbstractEmailSuppressionList, EmailSuppressionData} = require('@tryghost/email-suppression-list'); + +module.exports = class InMemoryEmailSuppressionList extends AbstractEmailSuppressionList { + store = ['spam@member.test', 'fail@member.test']; + + async removeEmail(email) { + if ((email === 'fail@member.test' || email === 'spam@member.test') && this.store.includes(email)) { + this.store = this.store.filter(el => el !== email); + + setTimeout(() => this.store.push(email), 3000); + return true; + } + + return false; + } + + async getSuppressionData(email) { + if (email === 'spam@member.test' && this.store.includes(email)) { + return new EmailSuppressionData(true, { + timestamp: new Date(), + reason: 'spam' + }); + } + if (email === 'fail@member.test' && this.store.includes(email)) { + return new EmailSuppressionData(true, { + timestamp: new Date(), + reason: 'fail' + }); + } + return new EmailSuppressionData(false); + } + + async init() { + return; + } +}; diff --git a/ghost/core/core/server/services/email-suppression-list/service.js b/ghost/core/core/server/services/email-suppression-list/service.js index 97c0f45105..d1f4edc4fa 100644 --- a/ghost/core/core/server/services/email-suppression-list/service.js +++ b/ghost/core/core/server/services/email-suppression-list/service.js @@ -1,38 +1,3 @@ -const {AbstractEmailSuppressionList, EmailSuppressionData} = require('@tryghost/email-suppression-list'); - -class InMemoryEmailSuppressionList extends AbstractEmailSuppressionList { - store = ['spam@member.test', 'fail@member.test']; - - async removeEmail(email) { - if ((email === 'fail@member.test' || email === 'spam@member.test') && this.store.includes(email)) { - this.store = this.store.filter(el => el !== email); - - setTimeout(() => this.store.push(email), 3000); - return true; - } - - return false; - } - - async getSuppressionData(email) { - if (email === 'spam@member.test' && this.store.includes(email)) { - return new EmailSuppressionData(true, { - timestamp: new Date(), - reason: 'spam' - }); - } - if (email === 'fail@member.test' && this.store.includes(email)) { - return new EmailSuppressionData(true, { - timestamp: new Date(), - reason: 'fail' - }); - } - return new EmailSuppressionData(false); - } - - async init() { - return; - } -} +const InMemoryEmailSuppressionList = require('./InMemoryEmailSuppressionList'); module.exports = new InMemoryEmailSuppressionList();