marcinadd / projecty-web

Project management software based on spring
GNU General Public License v3.0
74 stars 74 forks source link

Add option to delete message #35

Closed marcinadd closed 4 years ago

fokion commented 4 years ago

I can give it a go

marcinadd commented 4 years ago

Ok. But don't forget that deleted message should be only for one user. I mean if user A deletes a message, user B should still have it.

fokion commented 4 years ago

I have started implementing it , by having a new table called associations where you associate a message with a user. When you create a new message you create new entries in the associations table where you have the user , the message and an id as an index ( so by creating a message you create an entry for the sender and one for the receiver) . You can now filter your messages that you get from the server based on this table ( so we hide the messages you deleted from your view)

marcinadd commented 4 years ago

Good idea.

  public void deleteMessageForUser(Message messageToBeDeleted, User user){
        Optional<Association> messageOptional = associationRepository.findByUser(user).stream()
                .filter(association -> messageToBeDeleted.equals(association.getMessage()))
                .findFirst();
        messageOptional.ifPresent(association -> associationRepository.delete(association));
    }
}

I regard that better option is to use findFirstByUserAndMessage(), it isn't?

fokion commented 4 years ago

yeap something like that , I have it in a fork . I want to add something more concrete in the unit test ( like test containers) as mocking with the current state is an issue

marcinadd commented 4 years ago

No problem. If you have any suggestions or enhancements just open a new issue.

fokion commented 4 years ago

37 I have a draft version of the code to have a look.

marcinadd commented 4 years ago

Ok. I'll look at it tomorrow.