{"size": 948, "ext": "js", "max_stars_repo_path": "src/ActivitySummaryEntity.js", "max_stars_repo_name": "BrightspaceUILabs/training-activity-summary", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/ActivitySummaryEntity.js", "max_issues_repo_name": "BrightspaceUILabs/training-activity-summary", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/ActivitySummaryEntity.js", "max_forks_repo_name": "BrightspaceUILabs/training-activity-summary", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 35.1111111111, "max_line_length": 103, "alphanum_fraction": 0.75}
import { ActivityEventEntity } from './ActivityEventEntity';
import { Entity } from 'siren-sdk/src/es6/Entity';

export class ActivitySummaryEntity extends Entity {
	static get class() { return 'activity-summary'; }

	/**
	 * @returns {Array} array of activity-event subentities sorted by timestamp
	 */
	getSortedActivityEvents() {
		const activityEvents = this._entity && this._entity.getSubEntitiesByClass(ActivityEventEntity.class);
		return activityEvents && activityEvents.sort(this._activityEventSortFunction);
	}

	/**
	 * @param {object} event1 first event to compare
	 * @param {object} event2 second event to compare
	 * @returns {boolean} whether or not event 1 comes before event 2
	 */
	_activityEventSortFunction(event1, event2) {
		const timestamp1 = event1 && event1.properties && event1.properties.timestamp;
		const timestamp2 = event2 && event2.properties && event2.properties.timestamp;

		return timestamp1 < timestamp2;
	}
}
