import { isPlaylistObjectValid } from './playlist'
function isRootActivityValid (activity: any) {
- return Array.isArray(activity['@context']) && (
- (
- (activity.type === 'Collection' || activity.type === 'OrderedCollection') &&
- validator.isInt(activity.totalItems, { min: 0 }) &&
- Array.isArray(activity.items)
- ) ||
- (
- isActivityPubUrlValid(activity.id) &&
- exists(activity.actor) &&
- (isActivityPubUrlValid(activity.actor) || isActivityPubUrlValid(activity.actor.id))
- )
- )
+ return isCollection(activity) || isActivity(activity)
+}
+
+function isCollection (activity: any) {
+ return (activity.type === 'Collection' || activity.type === 'OrderedCollection') &&
+ validator.isInt(activity.totalItems, { min: 0 }) &&
+ Array.isArray(activity.items)
+}
+
+function isActivity (activity: any) {
+ return isActivityPubUrlValid(activity.id) &&
+ exists(activity.actor) &&
+ (isActivityPubUrlValid(activity.actor) || isActivityPubUrlValid(activity.actor.id))
}
const activityCheckers: { [ P in ActivityType ]: (activity: Activity) => boolean } = {