Search in sources :

Example 11 with Activity

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);
}
Also used : Activity(codeu.model.data.Activity)

Example 12 with 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;
    }
}
Also used : User(codeu.model.data.User) ArrayList(java.util.ArrayList) Activity(codeu.model.data.Activity) UUID(java.util.UUID)

Example 13 with Activity

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);
    }
}
Also used : User(codeu.model.data.User) Activity(codeu.model.data.Activity) Conversation(codeu.model.data.Conversation)

Example 14 with 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);
}
Also used : Email(codeu.utils.Email) Activity(codeu.model.data.Activity)

Example 15 with Activity

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);
}
Also used : Email(codeu.utils.Email) Activity(codeu.model.data.Activity)

Aggregations

Activity (codeu.model.data.Activity)26 User (codeu.model.data.User)16 Test (org.junit.Test)13 UUID (java.util.UUID)11 ArrayList (java.util.ArrayList)8 Conversation (codeu.model.data.Conversation)6 Message (codeu.model.data.Message)2 Email (codeu.utils.Email)2 Instant (java.time.Instant)2 ActivityStore (codeu.model.store.basic.ActivityStore)1 UserStore (codeu.model.store.basic.UserStore)1 ImageStorage (codeu.utils.ImageStorage)1 HashSet (java.util.HashSet)1 HttpSession (javax.servlet.http.HttpSession)1 Part (javax.servlet.http.Part)1