Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fixed members events for archived newsletters #19638

Merged
merged 4 commits into from
Feb 1, 2024
Merged
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
6 changes: 3 additions & 3 deletions ghost/members-api/lib/repositories/MemberRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}

Expand Down
Loading