mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
🐛 Fixed members events for archived newsletters (#19638)
fixes https://linear.app/tryghost/issue/ENG-604/🐛-members-events-show-member-subscribed-to-archived-newsletter - This fixes a bug where it doesn't take archived newsletters into account and would create an Event for subscribing back to those newsletters even though its not the case, which causes some confusion for publishers in Member Events and wastes rows in the DB.
This commit is contained in:
parent
1843963e19
commit
ddc1a58c84
@ -559,7 +559,6 @@ module.exports = class MemberRepository {
|
||||
|
||||
if (needsNewsletters) {
|
||||
const existingNewsletters = initialMember.related('newsletters').models;
|
||||
|
||||
// This maps the old subscribed property to the new newsletters field and is only used to keep backward compatibility
|
||||
if (!memberData.newsletters) {
|
||||
if (memberData.subscribed === false) {
|
||||
@ -572,12 +571,13 @@ module.exports = class MemberRepository {
|
||||
|
||||
// only ever populated with active newsletters - never archived ones
|
||||
if (memberData.newsletters) {
|
||||
const archivedNewsletters = existingNewsletters.filter(n => n.get('status') === 'archived').map(n => n.id);
|
||||
const existingNewsletterIds = existingNewsletters
|
||||
.filter(newsletter => newsletter.attributes.status !== 'archived')
|
||||
.map(newsletter => newsletter.id);
|
||||
const incomingNewsletterIds = memberData.newsletters.map(newsletter => newsletter.id);
|
||||
|
||||
newslettersToAdd = _.differenceWith(incomingNewsletterIds, existingNewsletterIds);
|
||||
// make sure newslettersToAdd does not contain newslettersToIgnore (archived newsletters since that creates false events)
|
||||
newslettersToAdd = _.differenceWith(_.differenceWith(incomingNewsletterIds, existingNewsletterIds), archivedNewsletters);
|
||||
newslettersToRemove = _.differenceWith(existingNewsletterIds, incomingNewsletterIds);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user