domainGroupMapper.addFollower(followerId, targetId);
// Update the cache list of followers
addCachedGroupFollowerMapper.execute(followerId, targetId);
// Queue async action to remove the newly followed group from cache (to sync follower counts)
asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections
.singleton(CacheKeys.GROUP_BY_ID + targetId)));
// remove any requests from the user for group membership
if (deleteRequestForGroupMembershipMapper
.execute(new RequestForGroupMembershipRequest(targetId, followerId)))
{
// if any requests were present, then user was just approved for access
asyncRequests.add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null,
new GroupMembershipResponseNotificationsRequest(RequestType.REQUEST_GROUP_ACCESS_APPROVED,
inActionContext.getActionContext().getPrincipal().getId(), targetId, followerId)));
}
// remove person modelview from cache as groupstreamhiddenlineindex will be changed.
deleteCacheKeyMapper.execute(Collections.singleton(CacheKeys.PERSON_BY_ID + followerId));
// Sends new follower notifications.
asyncRequests.add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null,
new TargetEntityNotificationsRequest(RequestType.FOLLOW_GROUP, followerId, targetId)));
// Posts a message to the user's personal stream unless this is a new pending group
if (!isPending)
{
String targetStream = "";
if (params instanceof SetFollowingStatusRequest)
{
SetFollowingStatusRequest currentRequest = (SetFollowingStatusRequest) params;
targetStream = currentRequest.getTargetUniqueId();
}
else if (params instanceof SetFollowingStatusByGroupCreatorRequest)
{
SetFollowingStatusByGroupCreatorRequest currentRequest = // \n
(SetFollowingStatusByGroupCreatorRequest) params;
targetStream = currentRequest.getTargetUniqueId();
}
StreamEntityDTO destination = new StreamEntityDTO();
destination.setUniqueIdentifier(followerAccountId);
destination.setType(EntityType.PERSON);
ActivityDTO activity = new ActivityDTO();
HashMap<String, String> props = new HashMap<String, String>();
activity.setBaseObjectProperties(props);
String content = "";
if (targetStream.length() > 0)
{
content = "%EUREKA:ACTORNAME% is now following the [" + targetName + "](#activity/group/"
+ targetStream + ") group";
}
else
{
content = "%EUREKA:ACTORNAME% is now following the " + targetName + " group";
}
activity.getBaseObjectProperties().put("content", content);
activity.setDestinationStream(destination);
activity.setBaseObjectType(BaseObjectType.NOTE);
activity.setVerb(ActivityVerb.POST);
// Note: create a principal for the follower: we want to post on the follower's stream as the
// follower.
// The current principal will be different from the follower in some cases, namely when following a
// private group (the current principal / actor is the coordinator who approved access).
new InlineExecutionStrategyExecutor().execute(postActivityExecutor, new PostActivityRequest(activity),
new DefaultPrincipal(followerAccountId, null, followerId),
inActionContext.getUserActionRequests());
}
break;
case NOTFOLLOWING:
// Check if the User to be removed is a Group Coordinator.
boolean isToBeRemovedUserGroupCoordinator = domainGroupMapper.isInputUserGroupCoordinator(followerId,
targetId);
// Do not remove the last Group Coordinator.
if ((domainGroupMapper.getGroupCoordinatorCount(targetId) == 1) && isToBeRemovedUserGroupCoordinator)
{
log.error("Cannot remove followerId: " + followerId + " " + "from targetId:" + targetId
+ " since there's " + "only a single Group Coordinator remaining " + "in the Group");
throw new ExecutionException("Cannot remove followerId: " + followerId + " " + "from targetId:"
+ targetId + " since there's " + "only a single Group Coordinator remaining " + "in the Group");
}
// Update the db for list of followers and following.
domainGroupMapper.removeFollower(followerId, targetId);
// Queue async action to remove the newly followed group from cache (to sync follower counts)
asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections
.singleton(CacheKeys.GROUP_BY_ID + targetId)));
// Remove the current user that is severing a relationship with the target group
// from the list of followers for that target group.
asyncRequests.add(new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest(
Collections.singletonList(CacheKeys.FOLLOWERS_BY_GROUP + targetId), Collections
.singletonList(followerId))));
// Remove the target group the current user is now following from the list of
// groups that the current user is already following.
asyncRequests.add(new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest(
Collections.singletonList(CacheKeys.GROUPS_FOLLOWED_BY_PERSON + followerId), Collections
.singletonList(targetId))));
if (isToBeRemovedUserGroupCoordinator)
{
// delete group coordinator from db
domainGroupMapper.removeGroupCoordinator(followerId, targetId);
// queue the removal of the target group's coordinator
asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections
.singleton(CacheKeys.COORDINATOR_PERSON_IDS_BY_GROUP_ID + targetId)));
// Update the 'PRIVATE_GROUP_IDS_VIEWABLE_BY_PERSON_AS_COORDINATOR' cache if Private Group
if (domainGroupMapper.isGroupPrivate(targetId))
{
// queue the removal the person's list of followed group ids
asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections
.singleton(CacheKeys.PRIVATE_GROUP_IDS_VIEWABLE_BY_PERSON_AS_COORDINATOR + followerId)));
}
}
break;