use of codeu.model.data.Activity in project codeu-2018-team12 by codeu-2018-team12.
the class ChatServlet method leaveConversation.
/**
* Removes a user from a conversation
*/
private void leaveConversation(User user, Conversation conversation) {
removeConversationFriends(user, conversation);
conversation.removeUser(user.getId());
String activityMessage = " left " + "<a href=\"/chat/" + conversation.getTitle() + "\">" + conversation.getTitle() + "</a>.";
Activity activity = new Activity(UUID.randomUUID(), user.getId(), conversation.getId(), Instant.now(), "leftConvo", activityMessage, conversation.getConversationUsers(), conversation.getIsPublic());
activityStore.addActivity(activity);
}
use of codeu.model.data.Activity in project codeu-2018-team12 by codeu-2018-team12.
the class ActivityStore method getActivitiesPerPrivacy.
/**
* Access list of activities with respect to user privacy settings
*
* @param currentUser the current logged in user
* @param activities1 the list of from which to activities to pull
* @return list of activities
*/
public List<Activity> getActivitiesPerPrivacy(User currentUser, List<Activity> activities1) {
UserStore userstore = UserStore.getInstance();
List<Activity> activitiesPerPrivacy = new ArrayList<>();
if (activities1 == null) {
return activitiesPerPrivacy;
} else {
for (Activity activity : activities1) {
if (activity != null) {
UUID activityUserID = activity.getUserId();
User user = userstore.getUser(activityUserID);
if (user != null && user.equals(currentUser)) {
activitiesPerPrivacy.add(activity);
} else if (currentUser != null && user != null && currentUser.getConversationFriends().contains(activityUserID) && (user.getActivityFeedPrivacy().equals("someContent"))) {
activitiesPerPrivacy.add(activity);
} else if (user != null && user.getActivityFeedPrivacy().equals("allContent")) {
activitiesPerPrivacy.add(activity);
} else if (currentUser != null && activityUserID.equals(currentUser.getId())) {
activitiesPerPrivacy.add(activity);
}
}
}
return activitiesPerPrivacy;
}
}
use of codeu.model.data.Activity in project codeu-2018-team12 by codeu-2018-team12.
the class DefaultDataStore method addRandomActivities.
private void addRandomActivities() {
for (int i = 0; i < DEFAULT_ACTIVITY_COUNT; i++) {
String activityType;
Random random = new Random();
int max = 4, min = 0;
int randomNum = random.nextInt(max - min + 1) + min;
if (randomNum == 0) {
activityType = "joinedApp";
} else if (randomNum == 1) {
activityType = "joinedConvo";
} else if (randomNum == 2) {
activityType = "leftConvo";
} else if (randomNum == 3) {
activityType = "createdConvo";
} else {
activityType = "messageSent";
}
UUID conversationId, associatedUserId;
User user = getRandomElement(users);
associatedUserId = user.getId();
Conversation conversation = getRandomElement(conversations);
associatedUserId = conversation.getOwnerId();
if (activityType.equals("joinedApp")) {
conversationId = new UUID(0L, 0L);
} else if (activityType.equals("createdConvo")) {
conversationId = conversation.getId();
} else {
conversation = getRandomElement(conversations);
conversationId = conversation.getId();
}
String activityMessage = generateActivityContent(user, conversation, activityType);
Activity activity = new Activity(UUID.randomUUID(), associatedUserId, conversationId, Instant.now(), activityType, activityMessage, conversation.getConversationUsers(), conversation.getIsPublic());
PersistentStorageAgent.getInstance().writeThrough(activity);
activities.add(activity);
}
}
use of codeu.model.data.Activity in project codeu-2018-team12 by codeu-2018-team12.
the class ChatServlet method createActivity.
/**
* Constructs an activity object and adds it to activityStore
*/
private void createActivity(Conversation conversation, User user, String messageContent, boolean containsImage) {
String activityMessage;
if (containsImage) {
activityMessage = " sent a picture in " + "<a href=\"/chat/" + conversation.getTitle() + "\">" + conversation.getTitle() + "</a>.";
} else {
activityMessage = " sent a message in " + "<a href=\"/chat/" + conversation.getTitle() + "\">" + conversation.getTitle() + "</a>" + ": " + messageContent;
}
Activity activity = new Activity(UUID.randomUUID(), user.getId(), conversation.getId(), Instant.now(), "messageSent", activityMessage, conversation.getConversationUsers(), conversation.getIsPublic());
activityStore.addActivity(activity);
Email email = new Email();
email.sendEmailNotification(user, conversation);
}
use of codeu.model.data.Activity in project codeu-2018-team12 by codeu-2018-team12.
the class DirectMessageServlet method createActivity.
/**
* Constructs an activity object and adds it to activityStore
*/
private void createActivity(Conversation conversation, User user, String messageContent, boolean containsImage) {
String activityMessage;
if (containsImage) {
activityMessage = " sent a picture in" + "<a href=\"/chat/" + conversation.getTitle() + "\">" + conversation.getTitle() + "</a>.";
} else {
activityMessage = " sent a direct message in " + "<a href=\"/chat/" + conversation.getTitle() + "\">" + conversation.getTitle() + "</a>" + ": " + messageContent;
}
Activity activity = new Activity(UUID.randomUUID(), user.getId(), conversation.getId(), Instant.now(), "messageSent", activityMessage, conversation.getConversationUsers(), conversation.getIsPublic());
activityStore.addActivity(activity);
Email email = new Email();
email.sendEmailNotification(user, conversation);
}
Aggregations