mirror of
https://github.com/wassname/talk.git
synced 2026-07-11 05:50:17 +08:00
Reconstruct previous comment state more accurately
This commit is contained in:
@@ -25,6 +25,7 @@ export default withFragments({
|
||||
id
|
||||
role
|
||||
}
|
||||
created_at
|
||||
}
|
||||
${getSlotFragmentSpreads(slots, 'comment')}
|
||||
}
|
||||
|
||||
@@ -135,20 +135,17 @@ const fields = `
|
||||
status
|
||||
actions {
|
||||
__typename
|
||||
... on FlagAction {
|
||||
reason
|
||||
}
|
||||
user {
|
||||
id
|
||||
role
|
||||
}
|
||||
created_at
|
||||
}
|
||||
status_history {
|
||||
type
|
||||
assigned_by {
|
||||
id
|
||||
}
|
||||
created_at
|
||||
}
|
||||
updated_at
|
||||
created_at
|
||||
`;
|
||||
|
||||
const COMMENT_ADDED_SUBSCRIPTION = gql`
|
||||
|
||||
@@ -338,10 +338,30 @@ class ModerationContainer extends Component {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const subscriptionFields = `
|
||||
status
|
||||
actions {
|
||||
__typename
|
||||
created_at
|
||||
}
|
||||
status_history {
|
||||
type
|
||||
created_at
|
||||
assigned_by {
|
||||
id
|
||||
username
|
||||
}
|
||||
}
|
||||
created_at
|
||||
updated_at
|
||||
`;
|
||||
|
||||
const COMMENT_ADDED_SUBSCRIPTION = gql`
|
||||
subscription CommentAdded($asset_id: ID){
|
||||
commentAdded(asset_id: $asset_id, statuses: null){
|
||||
...${getDefinitionName(Comment.fragments.comment)}
|
||||
${subscriptionFields}
|
||||
}
|
||||
}
|
||||
${Comment.fragments.comment}
|
||||
@@ -351,6 +371,7 @@ const COMMENT_EDITED_SUBSCRIPTION = gql`
|
||||
subscription CommentEdited($asset_id: ID){
|
||||
commentEdited(asset_id: $asset_id){
|
||||
...${getDefinitionName(Comment.fragments.comment)}
|
||||
${subscriptionFields}
|
||||
}
|
||||
}
|
||||
${Comment.fragments.comment}
|
||||
@@ -360,6 +381,7 @@ const COMMENT_FLAGGED_SUBSCRIPTION = gql`
|
||||
subscription CommentFlagged($asset_id: ID){
|
||||
commentFlagged(asset_id: $asset_id){
|
||||
...${getDefinitionName(Comment.fragments.comment)}
|
||||
${subscriptionFields}
|
||||
}
|
||||
}
|
||||
${Comment.fragments.comment}
|
||||
@@ -369,14 +391,7 @@ const COMMENT_ACCEPTED_SUBSCRIPTION = gql`
|
||||
subscription CommentAccepted($asset_id: ID){
|
||||
commentAccepted(asset_id: $asset_id){
|
||||
...${getDefinitionName(Comment.fragments.comment)}
|
||||
status_history {
|
||||
type
|
||||
created_at
|
||||
assigned_by {
|
||||
id
|
||||
username
|
||||
}
|
||||
}
|
||||
${subscriptionFields}
|
||||
}
|
||||
}
|
||||
${Comment.fragments.comment}
|
||||
@@ -386,14 +401,7 @@ const COMMENT_REJECTED_SUBSCRIPTION = gql`
|
||||
subscription CommentRejected($asset_id: ID){
|
||||
commentRejected(asset_id: $asset_id){
|
||||
...${getDefinitionName(Comment.fragments.comment)}
|
||||
status_history {
|
||||
type
|
||||
created_at
|
||||
assigned_by {
|
||||
id
|
||||
username
|
||||
}
|
||||
}
|
||||
${subscriptionFields}
|
||||
}
|
||||
}
|
||||
${Comment.fragments.comment}
|
||||
@@ -403,14 +411,7 @@ const COMMENT_RESET_SUBSCRIPTION = gql`
|
||||
subscription CommentReset($asset_id: ID){
|
||||
commentReset(asset_id: $asset_id){
|
||||
...${getDefinitionName(Comment.fragments.comment)}
|
||||
status_history {
|
||||
type
|
||||
created_at
|
||||
assigned_by {
|
||||
id
|
||||
username
|
||||
}
|
||||
}
|
||||
${subscriptionFields}
|
||||
}
|
||||
}
|
||||
${Comment.fragments.comment}
|
||||
|
||||
@@ -91,20 +91,87 @@ function getCommentQueues(comment, queueConfig) {
|
||||
return queues;
|
||||
}
|
||||
|
||||
function getOlderDate(a, b) {
|
||||
if (a) {
|
||||
a = new Date(a);
|
||||
}
|
||||
if (b) {
|
||||
b = new Date(b);
|
||||
}
|
||||
|
||||
if (!b) {
|
||||
return a;
|
||||
}
|
||||
|
||||
if (!a) {
|
||||
return b;
|
||||
}
|
||||
return a < b ? b : a;
|
||||
}
|
||||
|
||||
function determineLatestChange(comment) {
|
||||
let lc = null;
|
||||
|
||||
// Skip it when comment itself was not updated.
|
||||
// We'll get use the one from the status_history instead
|
||||
// as they might diverge a little bit (status_history item is created
|
||||
// before the comment itself)
|
||||
if (comment.createdAt !== comment.updatedAt) {
|
||||
lc = getOlderDate(lc, comment.createdAt);
|
||||
lc = getOlderDate(lc, comment.updatedAt);
|
||||
}
|
||||
|
||||
comment.status_history.forEach(item => {
|
||||
lc = getOlderDate(lc, item.created_at);
|
||||
lc = getOlderDate(lc, item.updated_at);
|
||||
});
|
||||
|
||||
comment.actions.forEach(item => {
|
||||
lc = getOlderDate(lc, item.created_at);
|
||||
lc = getOlderDate(lc, item.updated_at);
|
||||
});
|
||||
|
||||
return lc;
|
||||
}
|
||||
|
||||
function reconstructPreviousCommentState(comment) {
|
||||
const history = comment.status_history;
|
||||
const actions = comment.actions;
|
||||
const lastChangeDate = determineLatestChange(comment);
|
||||
console.log(lastChangeDate);
|
||||
const previousComment = {
|
||||
...comment,
|
||||
status_history: history.filter(
|
||||
item => new Date(item.created_at) < lastChangeDate
|
||||
),
|
||||
actions: actions.filter(item => new Date(item.created_at) < lastChangeDate),
|
||||
};
|
||||
|
||||
// Comment did not exist previously.
|
||||
if (!previousComment.status_history.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
previousComment.status =
|
||||
previousComment.status_history[
|
||||
previousComment.status_history.length - 1
|
||||
].type;
|
||||
|
||||
return previousComment;
|
||||
}
|
||||
|
||||
/**
|
||||
* getPreviousCommentQueues determines queues that this comment previously belonged to.
|
||||
*/
|
||||
function getPreviousCommentQueues(comment, queueConfig) {
|
||||
return comment.status_history.length <= 1
|
||||
? []
|
||||
: getCommentQueues(
|
||||
{
|
||||
...comment,
|
||||
status:
|
||||
comment.status_history[comment.status_history.length - 2].type,
|
||||
},
|
||||
queueConfig
|
||||
);
|
||||
const previousCommentState = reconstructPreviousCommentState(comment);
|
||||
|
||||
console.log(previousCommentState, comment);
|
||||
if (!previousCommentState) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return getCommentQueues(previousCommentState, queueConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,6 +291,8 @@ export function handleCommentChange(
|
||||
// Queues that this comment needs to be placed.
|
||||
const nextQueues = getCommentQueues(comment, queueConfig);
|
||||
|
||||
console.log(prevQueues, nextQueues);
|
||||
|
||||
let notificationShown = false;
|
||||
const showNotificationOnce = () => {
|
||||
if (notificationShown) {
|
||||
@@ -318,13 +387,12 @@ export function handleIndicatorChange(root, comment, queueConfig) {
|
||||
for (const queue of indicatorQueues) {
|
||||
if (prevQueues.indexOf(queue) === -1 && nextQueues.indexOf(queue) >= 0) {
|
||||
next = increaseCommentCount(next, queue);
|
||||
} else if (
|
||||
prevQueues.indexOf(queue) >= 0 &&
|
||||
nextQueues.indexOf(queue) === -1
|
||||
) {
|
||||
}
|
||||
if (prevQueues.indexOf(queue) >= 0 && nextQueues.indexOf(queue) === -1) {
|
||||
next = decreaseCommentCount(next, queue);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(prevQueues, nextQueues, next);
|
||||
return next;
|
||||
}
|
||||
|
||||
@@ -502,6 +502,9 @@ type Comment {
|
||||
# The time when the comment was created
|
||||
created_at: Date!
|
||||
|
||||
# The time when the comment was updated.
|
||||
updated_at: Date
|
||||
|
||||
# describes how the comment can be edited
|
||||
editing: EditInfo
|
||||
|
||||
|
||||
+19
-34
@@ -39,27 +39,28 @@ class ModIndicatorSubscription extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
const fields = `
|
||||
status
|
||||
actions {
|
||||
__typename
|
||||
created_at
|
||||
}
|
||||
status_history {
|
||||
type
|
||||
assigned_by {
|
||||
id
|
||||
}
|
||||
created_at
|
||||
}
|
||||
updated_at
|
||||
created_at
|
||||
`;
|
||||
|
||||
const COMMENT_FEATURED_SUBSCRIPTION = gql`
|
||||
subscription TalkFeaturedComments_Indicator_CommentFeatured {
|
||||
commentFeatured {
|
||||
comment {
|
||||
status
|
||||
actions {
|
||||
__typename
|
||||
... on FlagAction {
|
||||
reason
|
||||
}
|
||||
user {
|
||||
id
|
||||
role
|
||||
}
|
||||
}
|
||||
status_history {
|
||||
type
|
||||
assigned_by {
|
||||
id
|
||||
}
|
||||
}
|
||||
${fields}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,23 +70,7 @@ const COMMENT_UNFEATURED_SUBSCRIPTION = gql`
|
||||
subscription TalkFeaturedComments_Indicator_CommentUnfeatured {
|
||||
commentUnfeatured {
|
||||
comment {
|
||||
status
|
||||
actions {
|
||||
__typename
|
||||
... on FlagAction {
|
||||
reason
|
||||
}
|
||||
user {
|
||||
id
|
||||
role
|
||||
}
|
||||
}
|
||||
status_history {
|
||||
type
|
||||
assigned_by {
|
||||
id
|
||||
}
|
||||
}
|
||||
${fields}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,19 +74,29 @@ class ModSubscription extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
const fields = `
|
||||
status
|
||||
actions {
|
||||
__typename
|
||||
created_at
|
||||
}
|
||||
status_history {
|
||||
type
|
||||
assigned_by {
|
||||
id
|
||||
}
|
||||
created_at
|
||||
}
|
||||
updated_at
|
||||
created_at
|
||||
`;
|
||||
|
||||
const COMMENT_FEATURED_SUBSCRIPTION = gql`
|
||||
subscription CommentFeatured($assetId: ID){
|
||||
commentFeatured(asset_id: $assetId) {
|
||||
comment {
|
||||
...${getDefinitionName(Comment.fragments.comment)}
|
||||
status_history {
|
||||
type
|
||||
created_at
|
||||
assigned_by {
|
||||
id
|
||||
username
|
||||
}
|
||||
}
|
||||
${fields}
|
||||
}
|
||||
user {
|
||||
id
|
||||
@@ -102,6 +112,7 @@ const COMMENT_UNFEATURED_SUBSCRIPTION = gql`
|
||||
commentUnfeatured(asset_id: $assetId){
|
||||
comment {
|
||||
...${getDefinitionName(Comment.fragments.comment)}
|
||||
${fields}
|
||||
}
|
||||
user {
|
||||
id
|
||||
|
||||
Reference in New Issue
Block a user