mirror of
https://github.com/wassname/talk.git
synced 2026-06-29 07:07:55 +08:00
Don't sort and ignore duplicate comments (embed-stream)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import update from 'immutability-helper';
|
||||
import {insertCommentsSorted} from 'coral-framework/utils';
|
||||
import {appendNewNodes} from 'coral-framework/utils';
|
||||
|
||||
function determineCommentDepth(comment) {
|
||||
let depth = 0;
|
||||
@@ -159,14 +159,7 @@ function findAndInsertFetchedComments(parent, comments, parent_id) {
|
||||
[connectionField]: {
|
||||
hasNextPage: {$set: comments.hasNextPage},
|
||||
endCursor: {$set: comments.endCursor},
|
||||
nodes: {$apply: (nodes) => {
|
||||
if (isAsset) {
|
||||
return nodes.concat(comments.nodes);
|
||||
}
|
||||
return insertCommentsSorted(nodes, comments.nodes.filter(
|
||||
(comment) => !nodes.some((node) => node.id === comment.id)
|
||||
));
|
||||
}},
|
||||
nodes: {$apply: (nodes) => appendNewNodes(nodes, comments.nodes)},
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -198,7 +191,7 @@ export function attachCommentToParent(topLevelComment, comment) {
|
||||
return update(topLevelComment, {
|
||||
replies: {
|
||||
nodes: {
|
||||
$apply: (nodes) => insertCommentsSorted(nodes, comment),
|
||||
$apply: (nodes) => appendNewNodes(nodes, [comment]),
|
||||
},
|
||||
},
|
||||
replyCount: {
|
||||
|
||||
@@ -154,25 +154,12 @@ export function getErrorMessages(error) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const ascending = (a, b) => {
|
||||
const dateA = new Date(a.created_at);
|
||||
const dateB = new Date(b.created_at);
|
||||
if (dateA < dateB) { return -1; }
|
||||
if (dateA > dateB) { return 1; }
|
||||
return 0;
|
||||
};
|
||||
export function appendNewNodes(nodesA, nodesB) {
|
||||
return nodesA.concat(nodesB.filter((nodeB) => !nodesA.some((nodeA) => nodeA.id === nodeB.id)));
|
||||
}
|
||||
|
||||
const descending = (a, b) => ascending(a, b) * -1;
|
||||
|
||||
export function insertCommentsSorted(nodes, comments, sortOrder = 'ASC') {
|
||||
const added = nodes.concat(comments);
|
||||
if (sortOrder === 'ASC') {
|
||||
return added.sort(ascending);
|
||||
}
|
||||
if (sortOrder === 'DESC') {
|
||||
return added.sort(descending);
|
||||
}
|
||||
throw new Error(`Unknown sort order ${sortOrder}`);
|
||||
export function prependNewNodes(nodesA, nodesB) {
|
||||
return nodesB.filter((nodeB) => !nodesA.some((nodeA) => nodeA.id === nodeB.id)).concat(nodesA);
|
||||
}
|
||||
|
||||
export const isTagged = (tags, which) => tags.some((t) => t.tag.name === which);
|
||||
|
||||
@@ -15,7 +15,7 @@ import CommentHistory from 'talk-plugin-history/CommentHistory';
|
||||
// TODO: Auth logic needs refactoring.
|
||||
import {showSignInDialog, checkLogin} from 'coral-embed-stream/src/actions/auth';
|
||||
|
||||
import {insertCommentsSorted} from 'plugin-api/beta/client/utils';
|
||||
import {appendNewNodes} from 'plugin-api/beta/client/utils';
|
||||
import update from 'immutability-helper';
|
||||
import {getSlotFragmentSpreads} from 'coral-framework/utils';
|
||||
|
||||
@@ -42,7 +42,7 @@ class ProfileContainer extends Component {
|
||||
me: {
|
||||
comments: {
|
||||
nodes: {
|
||||
$apply: (nodes) => insertCommentsSorted(nodes, comments.nodes, 'DESC'),
|
||||
$apply: (nodes) => appendNewNodes(nodes, comments.nodes),
|
||||
},
|
||||
hasNextPage: {$set: comments.hasNextPage},
|
||||
endCursor: {$set: comments.endCursor},
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export {
|
||||
isTagged,
|
||||
insertCommentsSorted,
|
||||
prependNewNodes,
|
||||
appendNewNodes,
|
||||
getSlotFragmentSpreads,
|
||||
forEachError,
|
||||
capitalize,
|
||||
|
||||
@@ -6,7 +6,7 @@ import {withFragments, connect} from 'plugin-api/beta/client/hocs';
|
||||
import Comment from '../containers/Comment';
|
||||
import {addNotification} from 'plugin-api/beta/client/actions/notification';
|
||||
import {viewComment} from 'coral-embed-stream/src/actions/stream';
|
||||
import {getDefinitionName} from 'plugin-api/beta/client/utils';
|
||||
import {appendNewNodes, getDefinitionName} from 'plugin-api/beta/client/utils';
|
||||
import update from 'immutability-helper';
|
||||
|
||||
class TabPaneContainer extends React.Component {
|
||||
@@ -27,7 +27,7 @@ class TabPaneContainer extends React.Component {
|
||||
asset: {
|
||||
featuredComments: {
|
||||
nodes: {
|
||||
$push: comments.nodes,
|
||||
$apply: (nodes) => appendNewNodes(nodes, comments.nodes),
|
||||
},
|
||||
hasNextPage: {$set: comments.hasNextPage},
|
||||
endCursor: {$set: comments.endCursor},
|
||||
|
||||
@@ -9,7 +9,7 @@ import ModTag from './containers/ModTag';
|
||||
import ModSubscription from './containers/ModSubscription';
|
||||
|
||||
import {findCommentInEmbedQuery} from 'coral-embed-stream/src/graphql/utils';
|
||||
import {insertCommentsSorted} from 'plugin-api/beta/client/utils';
|
||||
import {prependNewNodes} from 'plugin-api/beta/client/utils';
|
||||
|
||||
export default {
|
||||
reducer,
|
||||
@@ -60,7 +60,7 @@ export default {
|
||||
asset: {
|
||||
featuredComments: {
|
||||
nodes: {
|
||||
$apply: (nodes) => insertCommentsSorted(nodes, comment, 'DESC')
|
||||
$apply: (nodes) => prependNewNodes(nodes, [comment]),
|
||||
}
|
||||
},
|
||||
featuredCommentsCount: {
|
||||
|
||||
Reference in New Issue
Block a user