Skip to content

Commit

Permalink
Remove last_message column from conversations #95
Browse files Browse the repository at this point in the history
  • Loading branch information
Nonononoki committed Sep 8, 2021
1 parent 0ed5b4d commit 0c66d56
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
Expand Up @@ -5,16 +5,13 @@
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;

import com.nonononoki.alovoa.component.TextEncryptorConverter;
import com.nonononoki.alovoa.entity.User;
import com.nonononoki.alovoa.repo.UserBlockRepository;

Expand Down Expand Up @@ -45,10 +42,6 @@ public class Conversation {

private Date lastOpened;

@Convert(converter = TextEncryptorConverter.class)
@Column(columnDefinition = "mediumtext")
private String lastMessage;

public boolean containsUser(User user) {
return users.contains(user);
}
Expand Down
Expand Up @@ -30,11 +30,15 @@ public class ConversationDto {
private boolean read;

public static ConversationDto conversationToDto(Conversation c, User currentUser,
TextEncryptorConverter textEncryptor) throws InvalidKeyException, IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException, UnsupportedEncodingException {
TextEncryptorConverter textEncryptor)
throws InvalidKeyException, IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException,
NoSuchPaddingException, InvalidAlgorithmParameterException, UnsupportedEncodingException {
ConversationDto dto = new ConversationDto();
dto.setId(c.getId());
dto.setLastUpdated(c.getLastUpdated());
dto.setLastMessage(c.getLastMessage());
if(c.getMessages() != null && c.getMessages().size() > 0) {
dto.setLastMessage(c.getMessages().get(c.getMessages().size() - 1).getContent());
}
User u = c.getPartner(currentUser);
dto.setUserName(u.getFirstName());
if (u.getProfilePicture() != null) {
Expand Down
Expand Up @@ -98,7 +98,6 @@ public void send(Long convoId, String message)
c.getMessages().remove(msg);
}

c.setLastMessage(lastMessage);
c.setLastUpdated(new Date());
conversationRepo.saveAndFlush(c);

Expand Down

0 comments on commit 0c66d56

Please sign in to comment.