Пример #1
0
            'actor': ['self', 'followers'],
            'object': ['self']
        },
        'notification': {
            'object': ['self']
        }
    }
});

/*!
 * Post a following-follow activity when a user follows another user
 */
FollowingAPI.on(FollowingConstants.events.FOLLOW, function(ctx, followingUser, followedUser) {
    var millis = Date.now();
    var actorResource = new ActivityModel.ActivitySeedResource('user', followingUser.id, {'user': followingUser});
    var objectResource = new ActivityModel.ActivitySeedResource('user', followedUser.id, {'user': followedUser});
    var activitySeed = new ActivityModel.ActivitySeed(FollowingConstants.activity.ACTIVITY_FOLLOW, millis, ActivityConstants.verbs.FOLLOW, actorResource, objectResource);
    ActivityAPI.postActivity(ctx, activitySeed);
});


//////////////////////////////////
// ACTIVITY ENTITY ASSOCIATIONS //
//////////////////////////////////

/*!
 * Register a user association that presents all the followers of a user
 */
ActivityAPI.registerActivityEntityAssociation('user', 'followers', function(associationsCtx, entity, callback) {
    // Get all the followers of the user
    var userId = entity.user.id;
Пример #2
0
// SEARCH ENDPOINTS //
//////////////////////

SearchAPI.registerSearch('followers', require('./searches/followers'));
SearchAPI.registerSearch('following', require('./searches/following'));


////////////////////
// INDEXING TASKS //
////////////////////

/*!
 * Update the following search index and the followers search index based on the change in the following user and the followed user
 */
FollowingAPI.on(FollowingConstants.events.FOLLOW, function(ctx, followingUser, followedUser) {
    return _handleIndexChange(ctx, followingUser.id, followedUser.id);
});

/*!
 * Update the following search index and the followers search index based on the change in the following user and the unfollowed user
 */
FollowingAPI.on(FollowingConstants.events.UNFOLLOW, function(ctx, followingUser, unfollowedUserId) {
    return _handleIndexChange(ctx, followingUser.id, unfollowedUserId);
});

/*!
 * Handle the change in follower/following index. The `followingUserId` will have their following index updated
 * while the `followedUserId` will have their followers index updated
 *
 * @param  {Context}    ctx                 The context of the request that updated the index
 * @param  {String}     followingUserId     The id of the user whose following index to update