2023-04-25 16:47:29 +03:00
|
|
|
const AnnouncementVisibilityValues = require('./AnnouncementVisibilityValues');
|
|
|
|
|
2023-04-20 18:23:06 +03:00
|
|
|
class AnnouncementBarSettings {
|
|
|
|
#getAnnouncementSettings;
|
|
|
|
|
2023-04-25 16:47:29 +03:00
|
|
|
static VisibilityValues = AnnouncementVisibilityValues;
|
|
|
|
|
2023-04-20 18:23:06 +03:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {Object} deps
|
|
|
|
* @param {() => {announcement: string, announcement_visibility: string[], announcement_background: string}} deps.getAnnouncementSettings
|
|
|
|
*/
|
|
|
|
constructor(deps) {
|
|
|
|
this.#getAnnouncementSettings = deps.getAnnouncementSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Object} [member]
|
|
|
|
* @param {string} member.status
|
|
|
|
* @returns {{announcement: string, announcement_background: string}}
|
|
|
|
*/
|
|
|
|
getAnnouncementSettings(member) {
|
|
|
|
let announcement = undefined;
|
|
|
|
|
|
|
|
// NOTE: combination of 'free_members' & 'paid_members' makes just a 'members' filter
|
|
|
|
const announcementSettings = this.#getAnnouncementSettings();
|
|
|
|
|
|
|
|
if (announcementSettings.announcement) {
|
|
|
|
const visibilities = announcementSettings.announcement_visibility;
|
|
|
|
const announcementContent = announcementSettings.announcement;
|
|
|
|
|
|
|
|
if (visibilities.length === 0) {
|
|
|
|
announcement = undefined;
|
|
|
|
} else {
|
2023-04-25 16:47:29 +03:00
|
|
|
if (visibilities.includes(AnnouncementVisibilityValues.VISITORS) && !member) {
|
2023-04-20 18:23:06 +03:00
|
|
|
announcement = announcementContent;
|
2023-04-25 16:47:29 +03:00
|
|
|
} else if (visibilities.includes(AnnouncementVisibilityValues.FREE_MEMBERS) && (member?.status === 'free')) {
|
2023-04-20 18:23:06 +03:00
|
|
|
announcement = announcementContent;
|
2023-04-25 16:47:29 +03:00
|
|
|
} else if (visibilities.includes(AnnouncementVisibilityValues.PAID_MEMBERS) && (member && member.status !== 'free')) {
|
2023-04-20 18:23:06 +03:00
|
|
|
announcement = announcementContent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (announcement !== undefined) {
|
|
|
|
return {
|
|
|
|
announcement,
|
|
|
|
announcement_background: announcementSettings.announcement_background
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = AnnouncementBarSettings;
|