mirror of
https://github.com/wassname/talk.git
synced 2026-07-05 17:56:10 +08:00
changed cursor to Cursor scalar type, changed SORT_ORDER
This commit is contained in:
@@ -124,7 +124,7 @@ class UserDetailContainer extends React.Component {
|
||||
}
|
||||
|
||||
const LOAD_MORE_QUERY = gql`
|
||||
query CoralAdmin_Moderation_LoadMore($limit: Int = 10, $cursor: Date, $author_id: ID!, $statuses: [COMMENT_STATUS!]) {
|
||||
query CoralAdmin_Moderation_LoadMore($limit: Int = 10, $cursor: Cursor, $author_id: ID!, $statuses: [COMMENT_STATUS!]) {
|
||||
comments(query: {limit: $limit, cursor: $cursor, author_id: $author_id, statuses: $statuses}) {
|
||||
...CoralAdmin_Moderation_CommentConnection
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ const initialState = {
|
||||
storySearchVisible: false,
|
||||
storySearchString: '',
|
||||
shortcutsNoteVisible: window.localStorage.getItem('coral:shortcutsNote') || 'show',
|
||||
sortOrder: 'REVERSE_CHRONOLOGICAL',
|
||||
sortOrder: 'DESC',
|
||||
};
|
||||
|
||||
export default function moderation (state = initialState, action) {
|
||||
|
||||
@@ -36,8 +36,8 @@ const ModerationMenu = ({
|
||||
label="Sort"
|
||||
value={sort}
|
||||
onChange={(sort) => selectSort(sort)}>
|
||||
<Option value={'REVERSE_CHRONOLOGICAL'}>{t('modqueue.newest_first')}</Option>
|
||||
<Option value={'CHRONOLOGICAL'}>{t('modqueue.oldest_first')}</Option>
|
||||
<Option value={'DESC'}>{t('modqueue.newest_first')}</Option>
|
||||
<Option value={'ASC'}>{t('modqueue.oldest_first')}</Option>
|
||||
</SelectField>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -279,7 +279,7 @@ const COMMENT_REJECTED_SUBSCRIPTION = gql`
|
||||
`;
|
||||
|
||||
const LOAD_MORE_QUERY = gql`
|
||||
query CoralAdmin_Moderation_LoadMore($limit: Int = 10, $cursor: Date, $sort: SORT_ORDER, $asset_id: ID, $statuses:[COMMENT_STATUS!], $action_type: ACTION_TYPE) {
|
||||
query CoralAdmin_Moderation_LoadMore($limit: Int = 10, $cursor: Cursor, $sort: SORT_ORDER, $asset_id: ID, $statuses:[COMMENT_STATUS!], $action_type: ACTION_TYPE) {
|
||||
comments(query: {limit: $limit, cursor: $cursor, asset_id: $asset_id, statuses: $statuses, sort: $sort, action_type: $action_type}) {
|
||||
nodes {
|
||||
...${getDefinitionName(Comment.fragments.comment)}
|
||||
|
||||
@@ -36,7 +36,7 @@ function shouldCommentBeAdded(root, queue, comment, sort) {
|
||||
return true;
|
||||
}
|
||||
const cursor = new Date(root[queue].endCursor);
|
||||
return sort === 'CHRONOLOGICAL'
|
||||
return sort === 'ASC'
|
||||
? new Date(comment.created_at) <= cursor
|
||||
: new Date(comment.created_at) >= cursor;
|
||||
}
|
||||
@@ -46,7 +46,7 @@ function addCommentToQueue(root, queue, comment, sort) {
|
||||
return root;
|
||||
}
|
||||
|
||||
const sortAlgo = sort === 'CHRONOLOGICAL' ? ascending : descending;
|
||||
const sortAlgo = sort === 'ASC' ? ascending : descending;
|
||||
const changes = {
|
||||
[`${queue}Count`]: {$set: root[`${queue}Count`] + 1},
|
||||
};
|
||||
|
||||
@@ -102,7 +102,7 @@ class StreamContainer extends React.Component {
|
||||
cursor: comment.replies.endCursor,
|
||||
parent_id,
|
||||
asset_id: this.props.root.asset.id,
|
||||
sort: 'CHRONOLOGICAL',
|
||||
sort: 'ASC',
|
||||
excludeIgnored: this.props.data.variables.excludeIgnored,
|
||||
},
|
||||
updateQuery: (prev, {fetchMoreResult:{comments}}) => {
|
||||
@@ -119,7 +119,7 @@ class StreamContainer extends React.Component {
|
||||
cursor: this.props.root.asset.comments.endCursor,
|
||||
parent_id: null,
|
||||
asset_id: this.props.root.asset.id,
|
||||
sort: 'REVERSE_CHRONOLOGICAL',
|
||||
sort: 'DESC',
|
||||
excludeIgnored: this.props.data.variables.excludeIgnored,
|
||||
},
|
||||
updateQuery: (prev, {fetchMoreResult:{comments}}) => {
|
||||
@@ -202,7 +202,7 @@ const COMMENTS_EDITED_SUBSCRIPTION = gql`
|
||||
`;
|
||||
|
||||
const LOAD_MORE_QUERY = gql`
|
||||
query CoralEmbedStream_LoadMoreComments($limit: Int = 5, $cursor: Date, $parent_id: ID, $asset_id: ID, $sort: SORT_ORDER, $excludeIgnored: Boolean) {
|
||||
query CoralEmbedStream_LoadMoreComments($limit: Int = 5, $cursor: Cursor, $parent_id: ID, $asset_id: ID, $sort: SORT_ORDER, $excludeIgnored: Boolean) {
|
||||
comments(query: {limit: $limit, cursor: $cursor, parent_id: $parent_id, asset_id: $asset_id, sort: $sort, excludeIgnored: $excludeIgnored}) {
|
||||
nodes {
|
||||
id
|
||||
|
||||
@@ -156,12 +156,12 @@ const ascending = (a, b) => {
|
||||
|
||||
const descending = (a, b) => ascending(a, b) * -1;
|
||||
|
||||
export function insertCommentsSorted(nodes, comments, sortOrder = 'CHRONOLOGICAL') {
|
||||
export function insertCommentsSorted(nodes, comments, sortOrder = 'ASC') {
|
||||
const added = nodes.concat(comments);
|
||||
if (sortOrder === 'CHRONOLOGICAL') {
|
||||
if (sortOrder === 'ASC') {
|
||||
return added.sort(ascending);
|
||||
}
|
||||
if (sortOrder === 'REVERSE_CHRONOLOGICAL') {
|
||||
if (sortOrder === 'DESC') {
|
||||
return added.sort(descending);
|
||||
}
|
||||
throw new Error(`Unknown sort order ${sortOrder}`);
|
||||
|
||||
@@ -38,7 +38,7 @@ class ProfileContainer extends Component {
|
||||
me: {
|
||||
comments: {
|
||||
nodes: {
|
||||
$apply: (nodes) => insertCommentsSorted(nodes, comments.nodes, 'REVERSE_CHRONOLOGICAL'),
|
||||
$apply: (nodes) => insertCommentsSorted(nodes, comments.nodes, 'DESC'),
|
||||
},
|
||||
hasNextPage: {$set: comments.hasNextPage},
|
||||
endCursor: {$set: comments.endCursor},
|
||||
@@ -112,7 +112,7 @@ const CommentFragment = gql`
|
||||
`;
|
||||
|
||||
const LOAD_MORE_QUERY = gql`
|
||||
query TalkSettings_LoadMoreComments($limit: Int, $cursor: Date) {
|
||||
query TalkSettings_LoadMoreComments($limit: Int, $cursor: Cursor) {
|
||||
comments(query: {limit: $limit, cursor: $cursor}) {
|
||||
...TalkSettings_CommentConnectionFragment
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ const getCommentsByQuery = async ({user}, {ids, statuses, asset_id, parent_id, a
|
||||
}
|
||||
|
||||
if (cursor) {
|
||||
if (sort === 'REVERSE_CHRONOLOGICAL') {
|
||||
if (sort === 'DESC') {
|
||||
comments = comments.where({
|
||||
created_at: {
|
||||
$lt: cursor
|
||||
@@ -328,7 +328,7 @@ const getCommentsByQuery = async ({user}, {ids, statuses, asset_id, parent_id, a
|
||||
}
|
||||
|
||||
let query = comments
|
||||
.sort({created_at: sort === 'REVERSE_CHRONOLOGICAL' ? -1 : 1});
|
||||
.sort({created_at: sort === 'DESC' ? -1 : 1});
|
||||
if (limit) {
|
||||
query = query.limit(limit + 1);
|
||||
}
|
||||
@@ -363,7 +363,7 @@ const genRecentReplies = (context, ids) => {
|
||||
}
|
||||
}},
|
||||
|
||||
// sort these by their created at timestamp, CHRONOLOGICAL'y as these are
|
||||
// sort these by their created at timestamp, ASC'y as these are
|
||||
// replies
|
||||
{$sort: {
|
||||
created_at: 1
|
||||
@@ -413,7 +413,7 @@ const genRecentComments = (_, ids) => {
|
||||
}
|
||||
}},
|
||||
|
||||
// sort these by their created at timestamp, CHRONOLOGICAL'y as these are
|
||||
// sort these by their created at timestamp, ASC'y as these are
|
||||
// replies
|
||||
{$sort: {
|
||||
created_at: 1
|
||||
|
||||
@@ -36,7 +36,7 @@ const getUsersByQuery = ({user}, {ids, limit, cursor, statuses = null, sort}) =>
|
||||
}
|
||||
|
||||
if (cursor) {
|
||||
if (sort === 'REVERSE_CHRONOLOGICAL') {
|
||||
if (sort === 'DESC') {
|
||||
users = users.where({
|
||||
created_at: {
|
||||
$lt: cursor
|
||||
@@ -52,7 +52,7 @@ const getUsersByQuery = ({user}, {ids, limit, cursor, statuses = null, sort}) =>
|
||||
}
|
||||
|
||||
return users
|
||||
.sort({created_at: sort === 'REVERSE_CHRONOLOGICAL' ? -1 : 1})
|
||||
.sort({created_at: sort === 'DESC' ? -1 : 1})
|
||||
.limit(limit);
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
const GraphQLScalarType = require('graphql').GraphQLScalarType;
|
||||
const Kind = require('graphql/language').Kind;
|
||||
|
||||
module.exports = new GraphQLScalarType({
|
||||
name: 'Cursor',
|
||||
description: 'Cursor represents a paginating cursor.',
|
||||
serialize(value) {
|
||||
if (value instanceof Date) {
|
||||
return value.toISOString();
|
||||
}
|
||||
|
||||
return value;
|
||||
},
|
||||
parseValue(value) {
|
||||
if (typeof value === 'string') {
|
||||
return new Date(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
},
|
||||
parseLiteral(ast) {
|
||||
switch (ast.kind) {
|
||||
case Kind.STRING:
|
||||
|
||||
// This handles an empty string.
|
||||
if (ast.value && ast.value.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Date(ast.value);
|
||||
default:
|
||||
return ast.value;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -5,8 +5,9 @@ const ActionSummary = require('./action_summary');
|
||||
const Action = require('./action');
|
||||
const AssetActionSummary = require('./asset_action_summary');
|
||||
const Asset = require('./asset');
|
||||
const Comment = require('./comment');
|
||||
const CommentStatusHistory = require('./comment_status_history');
|
||||
const Comment = require('./comment');
|
||||
const Cursor = require('./cursor');
|
||||
const Date = require('./date');
|
||||
const FlagActionSummary = require('./flag_action_summary');
|
||||
const FlagAction = require('./flag_action');
|
||||
@@ -31,8 +32,9 @@ let resolvers = {
|
||||
Action,
|
||||
AssetActionSummary,
|
||||
Asset,
|
||||
Comment,
|
||||
CommentStatusHistory,
|
||||
Comment,
|
||||
Cursor,
|
||||
Date,
|
||||
FlagActionSummary,
|
||||
FlagAction,
|
||||
|
||||
+13
-10
@@ -5,6 +5,9 @@
|
||||
# Date represented as an ISO8601 string.
|
||||
scalar Date
|
||||
|
||||
# Cursor represents a paginating cursor.
|
||||
scalar Cursor
|
||||
|
||||
################################################################################
|
||||
## Reliability
|
||||
################################################################################
|
||||
@@ -126,10 +129,10 @@ input UsersQuery {
|
||||
limit: Int = 10
|
||||
|
||||
# Skip results from the last created_at timestamp.
|
||||
cursor: Date
|
||||
cursor: Cursor
|
||||
|
||||
# Sort the results by created_at.
|
||||
sort: SORT_ORDER = REVERSE_CHRONOLOGICAL
|
||||
sort: SORT_ORDER = DESC
|
||||
}
|
||||
|
||||
# AssetsQuery allows teh ability to query assets by specific fields
|
||||
@@ -241,10 +244,10 @@ input CommentsQuery {
|
||||
limit: Int = 10
|
||||
|
||||
# Skip results from the last created_at timestamp.
|
||||
cursor: Date
|
||||
cursor: Cursor
|
||||
|
||||
# Sort the results by created_at.
|
||||
sort: SORT_ORDER = REVERSE_CHRONOLOGICAL
|
||||
sort: SORT_ORDER = DESC
|
||||
|
||||
# Filter by a specific tag name.
|
||||
tags: [String!]
|
||||
@@ -314,7 +317,7 @@ type Comment {
|
||||
recentReplies: [Comment!]
|
||||
|
||||
# the replies that were made to the comment.
|
||||
replies(sort: SORT_ORDER = CHRONOLOGICAL, limit: Int = 3, excludeIgnored: Boolean): CommentConnection!
|
||||
replies(sort: SORT_ORDER = ASC, limit: Int = 3, excludeIgnored: Boolean): CommentConnection!
|
||||
|
||||
# The count of replies on a comment.
|
||||
replyCount(excludeIgnored: Boolean): Int
|
||||
@@ -348,10 +351,10 @@ type CommentConnection {
|
||||
hasNextPage: Boolean!
|
||||
|
||||
# Cursor of first comment in subset.
|
||||
startCursor: Date
|
||||
startCursor: Cursor
|
||||
|
||||
# Cursor of last comment in subset.
|
||||
endCursor: Date
|
||||
endCursor: Cursor
|
||||
|
||||
# Subset of comments.
|
||||
nodes: [Comment!]!
|
||||
@@ -573,7 +576,7 @@ type Asset {
|
||||
# If `deep` is true, it will return comments of all depths,
|
||||
# otherwise only top-level comments are returned.
|
||||
comments(
|
||||
sort: SORT_ORDER = REVERSE_CHRONOLOGICAL,
|
||||
sort: SORT_ORDER = DESC,
|
||||
limit: Int = 10,
|
||||
excludeIgnored: Boolean,
|
||||
tags: [String!]
|
||||
@@ -652,10 +655,10 @@ type ValidationUserError implements UserError {
|
||||
enum SORT_ORDER {
|
||||
|
||||
# newest to oldest order.
|
||||
REVERSE_CHRONOLOGICAL
|
||||
DESC
|
||||
|
||||
# oldest to newer order.
|
||||
CHRONOLOGICAL
|
||||
ASC
|
||||
}
|
||||
|
||||
# All queries that can be executed.
|
||||
|
||||
@@ -18,7 +18,7 @@ class TabPaneContainer extends React.Component {
|
||||
limit: 5,
|
||||
cursor: this.props.root.asset.featuredComments.endCursor,
|
||||
asset_id: this.props.root.asset.id,
|
||||
sort: 'REVERSE_CHRONOLOGICAL',
|
||||
sort: 'DESC',
|
||||
excludeIgnored: this.props.data.variables.excludeIgnored,
|
||||
},
|
||||
updateQuery: (previous, {fetchMoreResult:{comments}}) => {
|
||||
@@ -26,7 +26,7 @@ class TabPaneContainer extends React.Component {
|
||||
asset: {
|
||||
featuredComments: {
|
||||
nodes: {
|
||||
$apply: (nodes) => insertCommentsSorted(nodes, comments.nodes, 'REVERSE_CHRONOLOGICAL'),
|
||||
$apply: (nodes) => insertCommentsSorted(nodes, comments.nodes, 'DESC'),
|
||||
},
|
||||
hasNextPage: {$set: comments.hasNextPage},
|
||||
endCursor: {$set: comments.endCursor},
|
||||
@@ -47,7 +47,7 @@ class TabPaneContainer extends React.Component {
|
||||
}
|
||||
|
||||
const LOAD_MORE_QUERY = gql`
|
||||
query TalkFeaturedComments_LoadMoreComments($limit: Int = 5, $cursor: Date, $asset_id: ID, $sort: SORT_ORDER, $excludeIgnored: Boolean) {
|
||||
query TalkFeaturedComments_LoadMoreComments($limit: Int = 5, $cursor: String, $asset_id: ID, $sort: SORT_ORDER, $excludeIgnored: Boolean) {
|
||||
comments(query: {limit: $limit, cursor: $cursor, tags: ["FEATURED"], asset_id: $asset_id, sort: $sort, excludeIgnored: $excludeIgnored}) {
|
||||
nodes {
|
||||
...${getDefinitionName(Comment.fragments.comment)}
|
||||
|
||||
@@ -60,7 +60,7 @@ export default {
|
||||
asset: {
|
||||
featuredComments: {
|
||||
nodes: {
|
||||
$apply: (nodes) => insertCommentsSorted(nodes, comment, 'REVERSE_CHRONOLOGICAL')
|
||||
$apply: (nodes) => insertCommentsSorted(nodes, comment, 'DESC')
|
||||
}
|
||||
},
|
||||
featuredCommentsCount: {
|
||||
|
||||
Reference in New Issue
Block a user