mirror of
https://github.com/wassname/talk.git
synced 2026-08-11 11:27:10 +08:00
Better detect edits
This commit is contained in:
@@ -112,6 +112,10 @@ function getOlderDate(a, b) {
|
||||
function determineLatestChange(comment) {
|
||||
let lc = null;
|
||||
|
||||
comment.body_history.forEach(item => {
|
||||
lc = getOlderDate(lc, item.created_at);
|
||||
});
|
||||
|
||||
comment.status_history.forEach(item => {
|
||||
lc = getOlderDate(lc, item.created_at);
|
||||
});
|
||||
@@ -124,12 +128,16 @@ function determineLatestChange(comment) {
|
||||
}
|
||||
|
||||
function reconstructPreviousCommentState(comment) {
|
||||
const history = comment.status_history;
|
||||
const statusHistory = comment.status_history;
|
||||
const bodyHistory = comment.body_history;
|
||||
const actions = comment.actions;
|
||||
const lastChangeDate = determineLatestChange(comment);
|
||||
const previousComment = {
|
||||
...comment,
|
||||
status_history: history.filter(
|
||||
body_history: bodyHistory.filter(
|
||||
item => new Date(item.created_at) < lastChangeDate
|
||||
),
|
||||
status_history: statusHistory.filter(
|
||||
item => new Date(item.created_at) < lastChangeDate
|
||||
),
|
||||
actions: actions.filter(item => new Date(item.created_at) < lastChangeDate),
|
||||
@@ -145,6 +153,9 @@ function reconstructPreviousCommentState(comment) {
|
||||
previousComment.status_history.length - 1
|
||||
].type;
|
||||
|
||||
previousComment.body =
|
||||
previousComment.body_history[previousComment.body_history.length - 1].body;
|
||||
|
||||
return previousComment;
|
||||
}
|
||||
|
||||
@@ -383,6 +394,11 @@ export function handleIndicatorChange(root, comment, queueConfig) {
|
||||
|
||||
export const subscriptionFields = `
|
||||
status
|
||||
body
|
||||
body_history {
|
||||
body
|
||||
created_at
|
||||
}
|
||||
actions {
|
||||
__typename
|
||||
created_at
|
||||
|
||||
@@ -453,6 +453,11 @@ type EditInfo {
|
||||
editableUntil: Date
|
||||
}
|
||||
|
||||
type CommentBodyHistory {
|
||||
body: String!
|
||||
created_at: Date!
|
||||
}
|
||||
|
||||
type CommentStatusHistory {
|
||||
type: COMMENT_STATUS!
|
||||
created_at: Date!
|
||||
@@ -471,6 +476,9 @@ type Comment {
|
||||
# The actual comment data.
|
||||
body: String!
|
||||
|
||||
# The body history of the comment.
|
||||
body_history: [CommentBodyHistory!]!
|
||||
|
||||
# the tags on the comment
|
||||
tags: [TagLink!]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user