-
-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Commenting will involve 2 main objects
- CommentThread
- Comment
Comments will be owned by a thread, when a user starts a new comment thread it will also include the first comment.
Because of the async nature we should consider the fact that 2 comments can be made without knowing about the other, and then the order of them will be confusing as it will look like one came after the other when it was not authored with the knowledge of the other comment. One way to solve this is for the comment to store the Id of the last comment it was aware of. Then when showing comments in the UI if the previous comment is not what's expected we could display a little
Tip
readonly fields use init
instead of set
public class CommentThread
{
public Guid Id { get; set; }
public DateTimeOffset? DeletedAt { get; set; }
public required string AuthorName { get; init; }
public required string AuthorId { get; init; }
public ThreadStatus Status { get; set; }
public Guid PEntityId { get; init; }//could be a string
public ParentEntityType EntityType { get; init; }
}
public enum ThreadStatus
{
Open = 0,
Closed = 1
}
public enum ParentEntityType
{
Unknown,
Entity,
Sense,
ExampleSentence,
}
Note
a comment thread is a harmony object, it should return the Parent entity Id as a reference, and it should delete itself if that Id should be removed.
Comments:
public class UserComment
{
public Guid Id { get; set; }
public Guid CommentThreadId { get; init; }
public CommentThread Thread {get; init; }//only used for EF querying purposes
public DateTimeOffset? DeletedAt { get; set; }
public DateTimeOffset CreatedAt { get; init; }
public DateTimeOffset UpdatedAt { get; set; }
public required string Text { get; set; }
public required string AuthorName { get; init; }
public required string AuthorId { get; init; }
}
Note
if the comment thread is deleted then so are the user comments.
Important
Comments can't be made on a closed thread, if you want to make a comment it should be reopened.
Tracking read status is a bit tricky. Particularly due to comment ordering issues, normally we could just track last comment seen per user per thread and that would be enough, however a comment could get synced in before that last comment and that would not detect the new comment.
Instead we will use a non synced table we track seen comments. It will just track comments which are seen, in order to list unread comments we can do an outer join between the comment and read comments tables in order to get unread comments. Comments get marked as read when a user opens the thread of that conversation. If the user has a thread open, and a new comment comes in we don't want to automatically mark it as read because they may not be looking or are away from their machine etc. Instead we will display a popup about a new comment which can be clicked to display it, then the comment can be marked as read.
When a new project is downloaded all comments will be unread, and we will give users a button to mark all comments as read.