export default class CommunitiesEntity {
/**
* Creates a new CommunitiesEntity instance from the provider parameters.
*
* @constructor CommunitiesEntity
* @param {Object} entityMap - Entity parameters
* @param {string} entityMap.id - Entity ID
* @param {number} entityMap.type - Entity type
* @param {string} [entityMap.title] - Entity title
* @param {string} [entityMap.avatarUrl] - Entity avatar
* @param {string} [entityMap.followersCount=0] - Followers amount
* @param {string} [entityMap.isFollowedByMe=false] - True if followed by current user
* @param {Object<number, boolean>} [entityMap.allowedActions={}] - Allowed actions
*/
constructor(entityMap) {
this.id = entityMap.id;
this.type = entityMap.type;
this.title = entityMap.title;
this.avatarUrl = entityMap.avatarUrl;
this.followersCount = entityMap.followersCount || 0;
this.isFollowedByMe = entityMap.isFollower === true;
this.allowedActions = entityMap.availableActions || {};
Object.freeze(this);
}
/**
* Check if current user is allowed to perform a certain action.
*
* @memberof CommunitiesEntity
* @instance
* @param {number} action - Action to be checked.
* @return {boolean} - True if current user is allowed to perform action, false otherwise.
*/
isActionAllowed(action) {
return this.allowedActions[action] === true;
}
}