-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Communication: Allow user to save messages for later (#9705)
- Loading branch information
Showing
89 changed files
with
3,145 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/de/tum/cit/aet/artemis/communication/domain/PostingType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package de.tum.cit.aet.artemis.communication.domain; | ||
|
||
import java.util.Arrays; | ||
|
||
public enum PostingType { | ||
|
||
POST((short) 0), ANSWER((short) 1); | ||
|
||
private final short databaseKey; | ||
|
||
PostingType(short databaseKey) { | ||
this.databaseKey = databaseKey; | ||
} | ||
|
||
public short getDatabaseKey() { | ||
return databaseKey; | ||
} | ||
|
||
public static PostingType fromDatabaseKey(short databaseKey) { | ||
return Arrays.stream(PostingType.values()).filter(type -> type.getDatabaseKey() == databaseKey).findFirst() | ||
.orElseThrow(() -> new IllegalArgumentException("Unknown database key: " + databaseKey)); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/main/java/de/tum/cit/aet/artemis/communication/domain/SavedPost.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package de.tum.cit.aet.artemis.communication.domain; | ||
|
||
import java.time.ZonedDateTime; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
|
||
import de.tum.cit.aet.artemis.core.domain.DomainObject; | ||
import de.tum.cit.aet.artemis.core.domain.User; | ||
|
||
@Entity | ||
@Table(name = "saved_post") | ||
public class SavedPost extends DomainObject { | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "user_id", nullable = false) | ||
private User user; | ||
|
||
@Column(name = "post_id", nullable = false) | ||
private Long postId; | ||
|
||
@Enumerated | ||
@Column(name = "post_type", nullable = false) | ||
private PostingType postType; | ||
|
||
@Enumerated | ||
@Column(name = "status", nullable = false) | ||
private SavedPostStatus status; | ||
|
||
@Column(name = "completed_at") | ||
private ZonedDateTime completedAt; | ||
|
||
public SavedPost() { | ||
} | ||
|
||
public SavedPost(User user, Long postId, PostingType postType, SavedPostStatus status, ZonedDateTime completedAt) { | ||
this.user = user; | ||
this.postId = postId; | ||
this.postType = postType; | ||
this.status = status; | ||
this.completedAt = completedAt; | ||
} | ||
|
||
public Long getPostId() { | ||
return postId; | ||
} | ||
|
||
public void setPostId(Long postId) { | ||
this.postId = postId; | ||
} | ||
|
||
public void setStatus(SavedPostStatus status) { | ||
this.status = status; | ||
} | ||
|
||
public User getUser() { | ||
return user; | ||
} | ||
|
||
public SavedPostStatus getStatus() { | ||
return status; | ||
} | ||
|
||
public void setCompletedAt(ZonedDateTime completedAt) { | ||
this.completedAt = completedAt; | ||
} | ||
|
||
public void setPostType(PostingType postType) { | ||
this.postType = postType; | ||
} | ||
|
||
public PostingType getPostType() { | ||
return postType; | ||
} | ||
|
||
public ZonedDateTime getCompletedAt() { | ||
return completedAt; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/de/tum/cit/aet/artemis/communication/domain/SavedPostStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package de.tum.cit.aet.artemis.communication.domain; | ||
|
||
import java.util.Arrays; | ||
|
||
public enum SavedPostStatus { | ||
|
||
IN_PROGRESS((short) 0), COMPLETED((short) 1), ARCHIVED((short) 2); | ||
|
||
private final short databaseKey; | ||
|
||
SavedPostStatus(short databaseKey) { | ||
this.databaseKey = databaseKey; | ||
} | ||
|
||
public short getDatabaseKey() { | ||
return databaseKey; | ||
} | ||
|
||
public static SavedPostStatus fromDatabaseKey(short databaseKey) { | ||
return Arrays.stream(SavedPostStatus.values()).filter(type -> type.getDatabaseKey() == databaseKey).findFirst() | ||
.orElseThrow(() -> new IllegalArgumentException("Unknown database key: " + databaseKey)); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/de/tum/cit/aet/artemis/communication/dto/AuthorDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package de.tum.cit.aet.artemis.communication.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
import de.tum.cit.aet.artemis.core.domain.User; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
public record AuthorDTO(Long id, String name, String imageUrl) { | ||
|
||
public AuthorDTO(User user) { | ||
this(user.getId(), user.getName(), user.getImageUrl()); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/de/tum/cit/aet/artemis/communication/dto/PostingConversationDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package de.tum.cit.aet.artemis.communication.dto; | ||
|
||
import de.tum.cit.aet.artemis.communication.domain.ConversationType; | ||
import de.tum.cit.aet.artemis.communication.domain.conversation.Channel; | ||
import de.tum.cit.aet.artemis.communication.domain.conversation.Conversation; | ||
import de.tum.cit.aet.artemis.communication.domain.conversation.GroupChat; | ||
|
||
public record PostingConversationDTO(Long id, String title, ConversationType type) { | ||
|
||
public PostingConversationDTO(Conversation conversation) { | ||
this(conversation.getId(), determineTitle(conversation), determineType(conversation)); | ||
} | ||
|
||
private static String determineTitle(Conversation conversation) { | ||
if (conversation instanceof Channel) { | ||
return ((Channel) conversation).getName(); | ||
} | ||
else if (conversation instanceof GroupChat) { | ||
return ((GroupChat) conversation).getName(); | ||
} | ||
else { | ||
return "Chat"; | ||
} | ||
} | ||
|
||
private static ConversationType determineType(Conversation conversation) { | ||
if (conversation instanceof Channel) { | ||
return ConversationType.CHANNEL; | ||
} | ||
else { | ||
return ConversationType.DIRECT; | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/de/tum/cit/aet/artemis/communication/dto/PostingDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package de.tum.cit.aet.artemis.communication.dto; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
import de.tum.cit.aet.artemis.communication.domain.AnswerPost; | ||
import de.tum.cit.aet.artemis.communication.domain.Posting; | ||
import de.tum.cit.aet.artemis.communication.domain.PostingType; | ||
import de.tum.cit.aet.artemis.communication.domain.UserRole; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
public record PostingDTO(Long id, AuthorDTO author, UserRole role, ZonedDateTime creationDate, ZonedDateTime updatedDate, String content, boolean isSaved, short savedPostStatus, | ||
List<ReactionDTO> reactions, PostingConversationDTO conversation, short postingType, Long referencePostId) { | ||
|
||
public PostingDTO(Posting post, boolean isSaved, short savedPostStatus) { | ||
this(post.getId(), new AuthorDTO(post.getAuthor()), post.getAuthorRole(), post.getCreationDate(), post.getUpdatedDate(), post.getContent(), isSaved, savedPostStatus, | ||
post.getReactions().stream().map(ReactionDTO::new).toList(), new PostingConversationDTO(post.getConversation()), getSavedPostType(post).getDatabaseKey(), | ||
getReferencePostId(post)); | ||
} | ||
|
||
static PostingType getSavedPostType(Posting posting) { | ||
if (posting instanceof AnswerPost) { | ||
return PostingType.ANSWER; | ||
} | ||
else { | ||
return PostingType.POST; | ||
} | ||
} | ||
|
||
static Long getReferencePostId(Posting posting) { | ||
if (posting instanceof AnswerPost) { | ||
return ((AnswerPost) posting).getPost().getId(); | ||
} | ||
else { | ||
return posting.getId(); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/de/tum/cit/aet/artemis/communication/dto/ReactionDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package de.tum.cit.aet.artemis.communication.dto; | ||
|
||
import java.time.ZonedDateTime; | ||
|
||
import de.tum.cit.aet.artemis.communication.domain.Reaction; | ||
|
||
public record ReactionDTO(Long id, AuthorDTO user, ZonedDateTime creationDate, String emojiId) { | ||
|
||
public ReactionDTO(Reaction reaction) { | ||
this(reaction.getId(), new AuthorDTO(reaction.getUser()), reaction.getCreationDate(), reaction.getEmojiId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.