From 1dc400ba58822474bd24071c7ab075448631b116 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Mon, 29 Oct 2018 22:49:35 +0000 Subject: [PATCH] [next] Rename Asset to Story (#2044) * feat: rename asset -> story in server * feat: renamed asset -> story for client code and tests * feat: renamed article -> story --- DESIGN.md | 69 ------- src/core/build/createWebpackConfig.ts | 8 +- src/core/build/paths.ts | 4 +- src/core/client/embed/StreamEmbed.spec.ts | 4 +- src/core/client/embed/StreamEmbed.ts | 8 +- src/core/client/embed/Talk.ts | 12 +- .../__snapshots__/StreamEmbed.spec.ts.snap | 2 +- .../embed/__snapshots__/index.spec.ts.snap | 4 +- src/core/client/embed/index.html | 2 +- .../client/embed/{article.html => story.html} | 4 +- .../{articleButton.html => storyButton.html} | 4 +- .../client/embed/utils/parseHashQuery.spec.ts | 4 +- .../framework/helpers/getURLWithCommentID.tsx | 4 +- .../framework/testHelpers/denormalize.ts | 14 +- .../framework/utils/parseHashQuery.spec.ts | 4 +- .../stream/local/initLocalState.spec.ts | 8 +- .../client/stream/local/initLocalState.ts | 8 +- src/core/client/stream/local/local.graphql | 4 +- .../stream/mutations/CreateCommentMutation.ts | 14 +- .../stream/queries/CommentsCountQuery.tsx | 18 +- .../components/ConversationThread.spec.tsx | 6 +- .../components/ConversationThread.tsx | 12 +- .../components/PermalinkView.spec.tsx | 4 +- .../comments/components/PermalinkView.tsx | 10 +- .../comments/components/ReplyList.spec.tsx | 4 +- .../tabs/comments/components/ReplyList.tsx | 4 +- .../tabs/comments/components/Stream.spec.tsx | 12 +- .../tabs/comments/components/Stream.tsx | 12 +- .../ConversationThread.spec.tsx.snap | 6 +- .../__snapshots__/PermalinkView.spec.tsx.snap | 4 +- .../__snapshots__/ReplyList.spec.tsx.snap | 60 +++--- .../__snapshots__/Stream.spec.tsx.snap | 194 +++++++++--------- .../containers/CommentContainer.spec.tsx | 20 +- .../comments/containers/CommentContainer.tsx | 20 +- .../ConversationThreadContainer.tsx | 16 +- .../containers/LocalReplyListContainer.tsx | 12 +- .../containers/PermalinkButtonContainer.tsx | 12 +- .../containers/PermalinkViewContainer.tsx | 16 +- .../PostCommentFormContainer.spec.tsx | 12 +- .../containers/PostCommentFormContainer.tsx | 4 +- .../ReplyCommentFormContainer.spec.tsx | 28 +-- .../containers/ReplyCommentFormContainer.tsx | 10 +- .../containers/ReplyListContainer.spec.tsx | 12 +- .../containers/ReplyListContainer.tsx | 50 ++--- .../containers/StreamContainer.spec.tsx | 8 +- .../comments/containers/StreamContainer.tsx | 28 +-- .../CommentContainer.spec.tsx.snap | 32 +-- .../ReplyListContainer.spec.tsx.snap | 60 +++--- .../StreamContainer.spec.tsx.snap | 82 ++++---- .../queries/PermalinkViewQuery.spec.tsx | 2 +- .../comments/queries/PermalinkViewQuery.tsx | 26 +-- .../comments/queries/StreamQuery.spec.tsx | 2 +- .../tabs/comments/queries/StreamQuery.tsx | 24 +-- .../PermalinkViewQuery.spec.tsx.snap | 2 +- .../__snapshots__/StreamQuery.spec.tsx.snap | 2 +- .../components/CommentHistory.spec.tsx | 6 +- .../profile/components/CommentHistory.tsx | 4 +- .../components/HistoryComment.spec.tsx | 4 +- .../profile/components/HistoryComment.tsx | 4 +- .../tabs/profile/components/Profile.spec.tsx | 2 +- .../tabs/profile/components/Profile.tsx | 4 +- .../CommentHistory.spec.tsx.snap | 12 +- .../HistoryComment.spec.tsx.snap | 2 +- .../__snapshots__/Profile.spec.tsx.snap | 2 +- .../containers/CommentHistoryContainer.tsx | 12 +- .../containers/HistoryCommentContainer.tsx | 14 +- .../profile/containers/ProfileContainer.tsx | 12 +- .../tabs/profile/queries/ProfileQuery.tsx | 24 +-- ... permalinkViewStoryNotFound.spec.tsx.snap} | 4 +- .../postLocalReply.spec.tsx.snap | 8 +- .../showConversation.spec.tsx.snap | 2 +- .../stream/test/comments/editComment.spec.tsx | 20 +- .../stream/test/comments/loadMore.spec.tsx | 16 +- .../test/comments/permalinkView.spec.tsx | 14 +- .../permalinkViewCommentNotFound.spec.tsx | 14 +- .../permalinkViewLoadMoreParents.spec.tsx | 14 +- ...sx => permalinkViewStoryNotFound.spec.tsx} | 10 +- .../stream/test/comments/postComment.spec.tsx | 12 +- .../test/comments/postLocalReply.spec.tsx | 12 +- .../stream/test/comments/postReply.spec.tsx | 14 +- .../test/comments/renderReplies.spec.tsx | 10 +- .../test/comments/renderStream.spec.tsx | 10 +- .../test/comments/showAllReplies.spec.tsx | 14 +- .../test/comments/showConversation.spec.tsx | 8 +- src/core/client/stream/test/fixtures.ts | 48 ++--- .../__snapshots__/loadMore.spec.tsx.snap | 10 +- .../__snapshots__/renderProfile.spec.tsx.snap | 4 +- .../stream/test/profile/loadMore.spec.tsx | 16 +- .../test/profile/renderProfile.spec.tsx | 10 +- .../server/graph/tenant/loaders/assets.ts | 17 -- .../server/graph/tenant/loaders/comments.ts | 18 +- src/core/server/graph/tenant/loaders/index.ts | 4 +- .../server/graph/tenant/loaders/stories.ts | 17 ++ .../server/graph/tenant/mutators/comment.ts | 2 +- .../server/graph/tenant/resolvers/asset.ts | 14 -- .../server/graph/tenant/resolvers/comment.ts | 6 +- .../graph/tenant/resolvers/comment_counts.ts | 2 +- .../server/graph/tenant/resolvers/index.ts | 4 +- .../server/graph/tenant/resolvers/query.ts | 2 +- .../server/graph/tenant/resolvers/story.ts | 14 ++ .../server/graph/tenant/schema/schema.graphql | 74 +++---- src/core/server/models/comment.ts | 16 +- src/core/server/models/{asset.ts => story.ts} | 94 ++++----- src/core/server/models/tenant.ts | 2 +- src/core/server/services/comments/actions.ts | 14 +- src/core/server/services/comments/index.ts | 38 ++-- .../services/comments/moderation/index.ts | 4 +- .../comments/moderation/phases/assetClosed.ts | 15 -- .../moderation/phases/commentLength.ts | 4 +- .../moderation/phases/commentingDisabled.ts | 6 +- .../comments/moderation/phases/index.ts | 4 +- .../comments/moderation/phases/links.ts | 4 +- .../comments/moderation/phases/premod.ts | 6 +- .../comments/moderation/phases/spam.ts | 4 +- ...ssetClosed.spec.ts => storyClosed.spec.ts} | 24 +-- .../comments/moderation/phases/storyClosed.ts | 15 ++ .../comments/moderation/phases/wordlist.ts | 2 +- .../services/queue/tasks/scraper/index.ts | 38 ++-- .../services/{assets => stories}/index.ts | 24 +-- src/docs/workarounds.mdx | 2 +- src/locales/en-US/stream.ftl | 6 +- 121 files changed, 903 insertions(+), 972 deletions(-) delete mode 100644 DESIGN.md rename src/core/client/embed/{article.html => story.html} (98%) rename src/core/client/embed/{articleButton.html => storyButton.html} (98%) rename src/core/client/stream/test/comments/__snapshots__/{permalinkViewAssetNotFound.spec.tsx.snap => permalinkViewStoryNotFound.spec.tsx.snap} (89%) rename src/core/client/stream/test/comments/{permalinkViewAssetNotFound.spec.tsx => permalinkViewStoryNotFound.spec.tsx} (71%) delete mode 100644 src/core/server/graph/tenant/loaders/assets.ts create mode 100644 src/core/server/graph/tenant/loaders/stories.ts delete mode 100644 src/core/server/graph/tenant/resolvers/asset.ts create mode 100644 src/core/server/graph/tenant/resolvers/story.ts rename src/core/server/models/{asset.ts => story.ts} (72%) delete mode 100644 src/core/server/services/comments/moderation/phases/assetClosed.ts rename src/core/server/services/comments/moderation/phases/{assetClosed.spec.ts => storyClosed.spec.ts} (57%) create mode 100644 src/core/server/services/comments/moderation/phases/storyClosed.ts rename src/core/server/services/{assets => stories}/index.ts (50%) diff --git a/DESIGN.md b/DESIGN.md deleted file mode 100644 index 870fdb35b..000000000 --- a/DESIGN.md +++ /dev/null @@ -1,69 +0,0 @@ -# Design - -## HTTP Routes - -### Stream API - -/api/tenant/graphql -/api/tenant/auth - -### Tenant Management API - -/api/management/graphql -/api/management/auth - -## Folder structure - -```text -/graph/tenant <-- tenant's api (comments, assets, ...) -/graph/management <-- tenant management api -``` - -1. No tenants -2. Create a tenant <-- consuming the TMA - -## Database connections - -### Redis Clients - -1. Tenant RedisPubSub Subscriber * -2. Tenant RedisPubSub Publisher -3. Queue Subscriber * -4. Queue Publisher -5. Queue Client -6. Queue Blocking Client - -## Scripts - -### Embed - -Embed Script - Renders the iFrame <-- does not have a html page in production (should be on server?) - -/dist/static/assets/embed.js /static/embed.js - -### Stream - -Stream - Renders the comment stream <-- data - -/dist/static/assets/stream..css /static/assets/stream..css -/dist/static/assets/stream..js /static/assets/stream..js -/dist/static/stream.html /embed/stream - -### Admin - -Admin - Renders the Admin page <-- data - -/dist/static/assets/admin..css /static/assets/admin..css -/dist/static/assets/admin..js /static/assets/admin..js -/dist/static/admin.html /admin - -## Development Routes - -localhost:3000 - / -> /admin - /dev <-- server side html for dev/iframe integration - -localhost:8080 - / -> localhost:3000/dev - /embed/stream <-- stream html (now is at /) - /admin <-- stream html (now is not there) diff --git a/src/core/build/createWebpackConfig.ts b/src/core/build/createWebpackConfig.ts index 5f331d4f2..cb0ebe804 100644 --- a/src/core/build/createWebpackConfig.ts +++ b/src/core/build/createWebpackConfig.ts @@ -560,14 +560,14 @@ export default function createWebpackConfig({ ...htmlWebpackConfig, }), new HtmlWebpackPlugin({ - filename: "article.html", - template: paths.appEmbedArticleHTML, + filename: "story.html", + template: paths.appEmbedStoryHTML, inject: "head", ...htmlWebpackConfig, }), new HtmlWebpackPlugin({ - filename: "articleButton.html", - template: paths.appEmbedArticleButtonHTML, + filename: "storyButton.html", + template: paths.appEmbedStoryButtonHTML, inject: "head", ...htmlWebpackConfig, }), diff --git a/src/core/build/paths.ts b/src/core/build/paths.ts index d89eb3362..376518ef7 100644 --- a/src/core/build/paths.ts +++ b/src/core/build/paths.ts @@ -40,8 +40,8 @@ export default { appEmbedIndex: resolveSrc("core/client/embed/index.ts"), appEmbedHTML: resolveSrc("core/client/embed/index.html"), - appEmbedArticleHTML: resolveSrc("core/client/embed/article.html"), - appEmbedArticleButtonHTML: resolveSrc("core/client/embed/articleButton.html"), + appEmbedStoryHTML: resolveSrc("core/client/embed/story.html"), + appEmbedStoryButtonHTML: resolveSrc("core/client/embed/storyButton.html"), appDistStatic: resolveApp("dist/static"), appPublic: resolveApp("public"), diff --git a/src/core/client/embed/StreamEmbed.spec.ts b/src/core/client/embed/StreamEmbed.spec.ts index d3e86b7f8..b4dd07b7c 100644 --- a/src/core/client/embed/StreamEmbed.spec.ts +++ b/src/core/client/embed/StreamEmbed.spec.ts @@ -129,8 +129,8 @@ it("should pass correct values to pymControl", () => { id: "container-id", rootURL: "http://localhost/", commentID: "comment-id", - assetID: "asset-id", - assetURL: "asset-url", + storyID: "story-id", + storyURL: "story-url", }; let pymControlConfig: PymControlConfig | null = null; const fakeFactory: any = (cfg: PymControlConfig) => { diff --git a/src/core/client/embed/StreamEmbed.ts b/src/core/client/embed/StreamEmbed.ts index dc19648e1..6f89de186 100644 --- a/src/core/client/embed/StreamEmbed.ts +++ b/src/core/client/embed/StreamEmbed.ts @@ -24,8 +24,8 @@ import { ensureNoEndSlash } from "./utils"; import urls from "../framework/helpers/urls"; export interface StreamEmbedConfig { - assetID?: string; - assetURL?: string; + storyID?: string; + storyURL?: string; commentID?: string; autoRender?: boolean; title: string; @@ -112,8 +112,8 @@ export class StreamEmbed { ]; const query = qs.stringify({ - assetID: this.config.assetID, - assetURL: this.config.assetURL, + storyID: this.config.storyID, + storyURL: this.config.storyURL, commentID: this.config.commentID, }); diff --git a/src/core/client/embed/Talk.ts b/src/core/client/embed/Talk.ts index 57983a58a..1b98e6c8a 100644 --- a/src/core/client/embed/Talk.ts +++ b/src/core/client/embed/Talk.ts @@ -4,8 +4,8 @@ import qs from "query-string"; import { default as create, StreamEmbed } from "./StreamEmbed"; export interface Config { - assetID?: string; - assetURL?: string; + storyID?: string; + storyURL?: string; commentID?: string; rootURL?: string; id?: string; @@ -22,7 +22,7 @@ function getLocationOrigin() { ); } -function resolveAssetURL() { +function resolveStoryURL() { const canonical = document.querySelector( 'link[rel="canonical"]' ) as HTMLLinkElement; @@ -32,7 +32,7 @@ function resolveAssetURL() { // tslint:disable-next-line:no-console console.warn( - "This page does not include a canonical link tag. Talk has inferred this asset_url from the window object. Query params have been stripped, which may cause a single thread to be present across multiple pages." + "This page does not include a canonical link tag. Talk has inferred this story_url from the window object. Query params have been stripped, which may cause a single thread to be present across multiple pages." ); return getLocationOrigin() + window.location.pathname; @@ -49,8 +49,8 @@ export function createStreamEmbed(config: Config): StreamEmbed { return create({ title: "Talk Embed Stream", - assetID: config.assetID || query.assetID, - assetURL: config.assetURL || resolveAssetURL(), + storyID: config.storyID || query.storyID, + storyURL: config.storyURL || resolveStoryURL(), commentID: config.commentID || query.commentID, id: config.id || "talk-embed-stream", rootURL: config.rootURL || getLocationOrigin(), diff --git a/src/core/client/embed/__snapshots__/StreamEmbed.spec.ts.snap b/src/core/client/embed/__snapshots__/StreamEmbed.spec.ts.snap index bb509a554..65141b069 100644 --- a/src/core/client/embed/__snapshots__/StreamEmbed.spec.ts.snap +++ b/src/core/client/embed/__snapshots__/StreamEmbed.spec.ts.snap @@ -4,7 +4,7 @@ exports[`should pass correct values to pymControl 1`] = ` Object { "id": "container-id", "title": "StreamEmbed", - "url": "http://localhost/embed/stream?assetID=asset-id&assetURL=asset-url&commentID=comment-id", + "url": "http://localhost/embed/stream?commentID=comment-id&storyID=story-id&storyURL=story-url", } `; diff --git a/src/core/client/embed/__snapshots__/index.spec.ts.snap b/src/core/client/embed/__snapshots__/index.spec.ts.snap index bb6760c67..a4b6bdb7b 100644 --- a/src/core/client/embed/__snapshots__/index.spec.ts.snap +++ b/src/core/client/embed/__snapshots__/index.spec.ts.snap @@ -1,5 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Basic integration test should render iframe 1`] = `""`; +exports[`Basic integration test should render iframe 1`] = `""`; -exports[`Basic integration test should use canonical link 1`] = `""`; +exports[`Basic integration test should use canonical link 1`] = `""`; diff --git a/src/core/client/embed/index.html b/src/core/client/embed/index.html index 2be8f9be9..6498664ed 100644 --- a/src/core/client/embed/index.html +++ b/src/core/client/embed/index.html @@ -16,7 +16,7 @@

- Article | Article With Button + Story | Story With Button

Talk 5.0 – Embed Stream

diff --git a/src/core/client/embed/article.html b/src/core/client/embed/story.html similarity index 98% rename from src/core/client/embed/article.html rename to src/core/client/embed/story.html index 6a1d3c1cf..c4fd41b00 100644 --- a/src/core/client/embed/article.html +++ b/src/core/client/embed/story.html @@ -16,9 +16,9 @@

- Default | Article With Button + Default | Story With Button

-

Talk 5.0 – Article

+

Talk 5.0 – Story

Dismember a mouse and then regurgitate parts of it on the family room floor. Dont wait for the storm to pass, dance in the rain stand in front of the computer screen, so stares at human while pushing stuff off a table chew the plant meow hiss at vacuum cleaner. Terrorize the hundred-and-twenty-pound rottweiler and steal his bed, not diff --git a/src/core/client/embed/articleButton.html b/src/core/client/embed/storyButton.html similarity index 98% rename from src/core/client/embed/articleButton.html rename to src/core/client/embed/storyButton.html index bf0c0cf38..95dd556de 100644 --- a/src/core/client/embed/articleButton.html +++ b/src/core/client/embed/storyButton.html @@ -16,9 +16,9 @@

- Default | Article + Default | Story

-

Talk 5.0 – Article with Button

+

Talk 5.0 – Story with Button

Dismember a mouse and then regurgitate parts of it on the family room floor. Dont wait for the storm to pass, dance in the rain stand in front of the computer screen, so stares at human while pushing stuff off a table chew the plant meow hiss at vacuum cleaner. Terrorize the hundred-and-twenty-pound rottweiler and steal his bed, not diff --git a/src/core/client/embed/utils/parseHashQuery.spec.ts b/src/core/client/embed/utils/parseHashQuery.spec.ts index 93a00de8e..c90e0be9e 100644 --- a/src/core/client/embed/utils/parseHashQuery.spec.ts +++ b/src/core/client/embed/utils/parseHashQuery.spec.ts @@ -9,10 +9,10 @@ it("should parse hash", () => { }, ], [ - "#commentID=comment-id&assetURL=asset-url", + "#commentID=comment-id&storyURL=story-url", { commentID: "comment-id", - assetURL: "asset-url", + storyURL: "story-url", }, ], ["#", {}], diff --git a/src/core/client/framework/helpers/getURLWithCommentID.tsx b/src/core/client/framework/helpers/getURLWithCommentID.tsx index 421032782..316edb5b4 100644 --- a/src/core/client/framework/helpers/getURLWithCommentID.tsx +++ b/src/core/client/framework/helpers/getURLWithCommentID.tsx @@ -1,8 +1,8 @@ import { modifyQuery } from "talk-framework/utils"; export default function getURLWithCommentID( - assetURL: string, + storyURL: string, commentID?: string ) { - return modifyQuery(assetURL, { commentID }); + return modifyQuery(storyURL, { commentID }); } diff --git a/src/core/client/framework/testHelpers/denormalize.ts b/src/core/client/framework/testHelpers/denormalize.ts index 9c3567266..5f0c76bd1 100644 --- a/src/core/client/framework/testHelpers/denormalize.ts +++ b/src/core/client/framework/testHelpers/denormalize.ts @@ -25,20 +25,20 @@ export function denormalizeComments(commentList: any[]) { return commentList.map(c => denormalizeComment(c)); } -export function denormalizeAsset(asset: any) { +export function denormalizeStory(story: any) { const commentNodes = - (asset.comments && - asset.comments.edges.map((edge: any) => ({ + (story.comments && + story.comments.edges.map((edge: any) => ({ ...edge, node: denormalizeComment(edge.node), }))) || []; - const commentsPageInfo = (asset.comments && asset.comments.pageInfo) || { + const commentsPageInfo = (story.comments && story.comments.pageInfo) || { endCursor: null, hasNextPage: false, }; return { - ...asset, + ...story, comments: { edges: commentNodes, pageInfo: commentsPageInfo }, commentCounts: { totalVisible: commentNodes.length, @@ -46,6 +46,6 @@ export function denormalizeAsset(asset: any) { }; } -export function denormalizeAssets(assetList: any[]) { - return assetList.map(a => denormalizeAsset(a)); +export function denormalizeStories(storyList: any[]) { + return storyList.map(a => denormalizeStory(a)); } diff --git a/src/core/client/framework/utils/parseHashQuery.spec.ts b/src/core/client/framework/utils/parseHashQuery.spec.ts index 2cbb6eb4d..f8523bbe0 100644 --- a/src/core/client/framework/utils/parseHashQuery.spec.ts +++ b/src/core/client/framework/utils/parseHashQuery.spec.ts @@ -9,10 +9,10 @@ it("should parse hash", () => { }, ], [ - "#commentID=comment-id&assetURL=asset-url", + "#commentID=comment-id&storyURL=story-url", { commentID: "comment-id", - assetURL: "asset-url", + storyURL: "story-url", }, ], ["#", {}], diff --git a/src/core/client/stream/local/initLocalState.spec.ts b/src/core/client/stream/local/initLocalState.spec.ts index 584c78559..710c0caa1 100644 --- a/src/core/client/stream/local/initLocalState.spec.ts +++ b/src/core/client/stream/local/initLocalState.spec.ts @@ -28,20 +28,20 @@ it("init local state", async () => { expect(JSON.stringify(source.toJSON(), null, 2)).toMatchSnapshot(); }); -it("set assetID from query", async () => { +it("set storyID from query", async () => { const context: Partial = { localStorage: createPromisifiedStorage(), }; - const assetID = "asset-id"; + const storyID = "story-id"; const previousLocation = location.toString(); const previousState = window.history.state; window.history.replaceState( previousState, document.title, - `http://localhost/?assetID=${assetID}` + `http://localhost/?storyID=${storyID}` ); await initLocalState(environment, context as any); - expect(source.get(LOCAL_ID)!.assetID).toBe(assetID); + expect(source.get(LOCAL_ID)!.storyID).toBe(storyID); window.history.replaceState(previousState, document.title, previousLocation); }); diff --git a/src/core/client/stream/local/initLocalState.ts b/src/core/client/stream/local/initLocalState.ts index b722b630e..6febe0e6a 100644 --- a/src/core/client/stream/local/initLocalState.ts +++ b/src/core/client/stream/local/initLocalState.ts @@ -38,12 +38,12 @@ export default async function initLocalState( // Parse query params const query = qs.parse(location.search); - if (query.assetID) { - localRecord.setValue(query.assetID, "assetID"); + if (query.storyID) { + localRecord.setValue(query.storyID, "storyID"); } - if (query.assetURL) { - localRecord.setValue(query.assetURL, "assetURL"); + if (query.storyURL) { + localRecord.setValue(query.storyURL, "storyURL"); } if (query.commentID) { diff --git a/src/core/client/stream/local/local.graphql b/src/core/client/stream/local/local.graphql index 45887aff2..1408f33fc 100644 --- a/src/core/client/stream/local/local.graphql +++ b/src/core/client/stream/local/local.graphql @@ -29,8 +29,8 @@ extend type Comment { type Local { network: Network! - assetID: String - assetURL: String + storyID: String + storyURL: String commentID: String authPopup: AuthPopup! authToken: String diff --git a/src/core/client/stream/mutations/CreateCommentMutation.ts b/src/core/client/stream/mutations/CreateCommentMutation.ts index 7b9134e56..f16fa0880 100644 --- a/src/core/client/stream/mutations/CreateCommentMutation.ts +++ b/src/core/client/stream/mutations/CreateCommentMutation.ts @@ -25,7 +25,7 @@ function sharedUpdater( store: RecordSourceSelectorProxy, input: CreateCommentInput ) { - updateAsset(store, input); + updateStory(store, input); if (input.local) { localUpdate(store, input); } else { @@ -34,14 +34,14 @@ function sharedUpdater( updateProfile(environment, store, input); } -function updateAsset( +function updateStory( store: RecordSourceSelectorProxy, input: CreateCommentInput ) { // Updating Comment Count - const asset = store.get(input.assetID); - if (asset) { - const record = asset.getLinkedRecord("commentCounts"); + const story = store.get(input.storyID); + if (story) { + const record = story.getLinkedRecord("commentCounts"); if (record) { // TODO: when we have moderation, we'll need to be careful here. const currentCount = record.getValue("totalVisible"); @@ -63,7 +63,7 @@ function update(store: RecordSourceSelectorProxy, input: CreateCommentInput) { // Get parent proxy. const parentProxy = input.parentID ? store.get(input.parentID) - : store.get(input.assetID); + : store.get(input.storyID); const connectionKey = input.parentID ? "ReplyList_replies" @@ -171,7 +171,7 @@ function commit( mutation, variables: { input: { - assetID: input.assetID, + storyID: input.storyID, parentID: input.parentID, body: input.body, clientMutationId: clientMutationId.toString(), diff --git a/src/core/client/stream/queries/CommentsCountQuery.tsx b/src/core/client/stream/queries/CommentsCountQuery.tsx index e781f3e59..063826255 100644 --- a/src/core/client/stream/queries/CommentsCountQuery.tsx +++ b/src/core/client/stream/queries/CommentsCountQuery.tsx @@ -17,13 +17,13 @@ interface InnerProps extends PropTypesOf { class CommentsCountQuery extends Component { public render() { - const { assetID, assetURL } = this.props.local; + const { storyID, storyURL } = this.props.local; const { local: _, ...rest } = this.props; return ( query={graphql` - query CommentsCountQuery($assetID: ID, $assetURL: String) { - asset(id: $assetID, url: $assetURL) { + query CommentsCountQuery($storyID: ID, $storyURL: String) { + story(id: $storyID, url: $storyURL) { commentCounts { totalVisible } @@ -31,18 +31,18 @@ class CommentsCountQuery extends Component { } `} variables={{ - assetID, - assetURL, + storyID, + storyURL, }} render={({ error, props }) => { if (error) { return

{error.message}
; } - if (props && props.asset) { + if (props && props.story) { return ( ); @@ -58,8 +58,8 @@ class CommentsCountQuery extends Component { const enhanced = withLocalStateContainer( graphql` fragment CommentsCountQueryLocal on Local { - assetID - assetURL + storyID + storyURL } ` )(CommentsCountQuery); diff --git a/src/core/client/stream/tabs/comments/components/ConversationThread.spec.tsx b/src/core/client/stream/tabs/comments/components/ConversationThread.spec.tsx index 0812cf786..94a85d86a 100644 --- a/src/core/client/stream/tabs/comments/components/ConversationThread.spec.tsx +++ b/src/core/client/stream/tabs/comments/components/ConversationThread.spec.tsx @@ -14,7 +14,7 @@ describe("with 2 remaining parent comments", () => { const props: PropTypesOf = { className: "root", me: {}, - asset: {}, + story: {}, settings: {}, comment: {}, disableLoadMore: false, @@ -34,7 +34,7 @@ describe("with 2 remaining parent comments", () => { const props: PropTypesOf = { className: "root", me: {}, - asset: {}, + story: {}, settings: {}, comment: {}, disableLoadMore: true, @@ -56,7 +56,7 @@ it("renders with no parent comments", () => { const props: PropTypesOf = { className: "root", me: {}, - asset: {}, + story: {}, settings: {}, comment: {}, disableLoadMore: false, diff --git a/src/core/client/stream/tabs/comments/components/ConversationThread.tsx b/src/core/client/stream/tabs/comments/components/ConversationThread.tsx index 61ae17708..c786edac9 100644 --- a/src/core/client/stream/tabs/comments/components/ConversationThread.tsx +++ b/src/core/client/stream/tabs/comments/components/ConversationThread.tsx @@ -16,8 +16,8 @@ export interface ConversationThreadProps { className?: string; me: PropTypesOf["me"] & (PropTypesOf["me"] | null); - asset: PropTypesOf["asset"] & - PropTypesOf["asset"]; + story: PropTypesOf["story"] & + PropTypesOf["story"]; settings: PropTypesOf["settings"] & PropTypesOf["settings"]; comment: PropTypesOf["comment"]; @@ -43,7 +43,7 @@ const ConversationThread: StatelessComponent<
0}> {props.me && ( { const props: PropTypesOf = { me: {}, - asset: {}, + story: {}, settings: {}, comment: {}, showAllCommentsHref: "http://localhost/link", @@ -25,7 +25,7 @@ it("renders correctly", () => { it("renders comment not found", () => { const props: PropTypesOf = { me: {}, - asset: {}, + story: {}, settings: {}, comment: null, showAllCommentsHref: "http://localhost/link", diff --git a/src/core/client/stream/tabs/comments/components/PermalinkView.tsx b/src/core/client/stream/tabs/comments/components/PermalinkView.tsx index b036207de..ca4a87809 100644 --- a/src/core/client/stream/tabs/comments/components/PermalinkView.tsx +++ b/src/core/client/stream/tabs/comments/components/PermalinkView.tsx @@ -13,8 +13,8 @@ export interface PermalinkViewProps { me: PropTypesOf["me"] & PropTypesOf["me"] & PropTypesOf["me"]; - asset: PropTypesOf["asset"] & - PropTypesOf["asset"]; + story: PropTypesOf["story"] & + PropTypesOf["story"]; comment: | PropTypesOf["comment"] & PropTypesOf["comment"] @@ -29,7 +29,7 @@ const PermalinkView: StatelessComponent = ({ showAllCommentsHref, comment, settings, - asset, + story, onShowAllComments, me, }) => { @@ -71,14 +71,14 @@ const PermalinkView: StatelessComponent = ({
diff --git a/src/core/client/stream/tabs/comments/components/ReplyList.spec.tsx b/src/core/client/stream/tabs/comments/components/ReplyList.spec.tsx index 9b503ac0e..4d9afb095 100644 --- a/src/core/client/stream/tabs/comments/components/ReplyList.spec.tsx +++ b/src/core/client/stream/tabs/comments/components/ReplyList.spec.tsx @@ -12,7 +12,7 @@ const ReplyListN = removeFragmentRefs(ReplyList); it("renders correctly", () => { const props: PropTypesOf = { - asset: { id: "asset-id" }, + story: { id: "story-id" }, comment: { id: "comment-id" }, comments: [ { id: "comment-1" }, @@ -38,7 +38,7 @@ it("renders correctly", () => { describe("when there is more", () => { const props: PropTypesOf = { - asset: { id: "asset-id" }, + story: { id: "story-id" }, comment: { id: "comment-id" }, comments: [{ id: "comment-1" }, { id: "comment-2" }], onShowAll: sinon.spy(), diff --git a/src/core/client/stream/tabs/comments/components/ReplyList.tsx b/src/core/client/stream/tabs/comments/components/ReplyList.tsx index 9d9ab0b39..63ae32a8d 100644 --- a/src/core/client/stream/tabs/comments/components/ReplyList.tsx +++ b/src/core/client/stream/tabs/comments/components/ReplyList.tsx @@ -9,7 +9,7 @@ import CommentContainer from "../containers/CommentContainer"; import Indent from "./Indent"; export interface ReplyListProps { - asset: PropTypesOf["asset"]; + story: PropTypesOf["story"]; me: PropTypesOf["me"]; comment: { id: string; @@ -42,7 +42,7 @@ const ReplyList: StatelessComponent = props => { key={comment.id} me={props.me} comment={comment} - asset={props.asset} + story={props.story} settings={props.settings} indentLevel={props.indentLevel} localReply={props.localReply} diff --git a/src/core/client/stream/tabs/comments/components/Stream.spec.tsx b/src/core/client/stream/tabs/comments/components/Stream.spec.tsx index b0043b2fe..6ecb587cf 100644 --- a/src/core/client/stream/tabs/comments/components/Stream.spec.tsx +++ b/src/core/client/stream/tabs/comments/components/Stream.spec.tsx @@ -12,8 +12,8 @@ const StreamN = removeFragmentRefs(Stream); it("renders correctly", () => { const props: PropTypesOf = { - asset: { - id: "asset-id", + story: { + id: "story-id", isClosed: false, }, comments: [{ id: "comment-1" }, { id: "comment-2" }], @@ -35,8 +35,8 @@ it("renders correctly", () => { describe("when use is logged in", () => { it("renders correctly", () => { const props: PropTypesOf = { - asset: { - id: "asset-id", + story: { + id: "story-id", isClosed: false, }, comments: [{ id: "comment-1" }, { id: "comment-2" }], @@ -58,8 +58,8 @@ describe("when use is logged in", () => { describe("when there is more", () => { const props: PropTypesOf = { - asset: { - id: "asset-id", + story: { + id: "story-id", isClosed: false, }, comments: [{ id: "comment-1" }, { id: "comment-2" }], diff --git a/src/core/client/stream/tabs/comments/components/Stream.tsx b/src/core/client/stream/tabs/comments/components/Stream.tsx index fcc9c474e..815455365 100644 --- a/src/core/client/stream/tabs/comments/components/Stream.tsx +++ b/src/core/client/stream/tabs/comments/components/Stream.tsx @@ -13,11 +13,11 @@ import PostCommentFormFake from "./PostCommentFormFake"; import * as styles from "./Stream.css"; export interface StreamProps { - asset: { + story: { id: string; isClosed?: boolean; - } & PropTypesOf["asset"] & - PropTypesOf["asset"]; + } & PropTypesOf["story"] & + PropTypesOf["story"]; settings: PropTypesOf["settings"] & PropTypesOf["settings"]; comments: ReadonlyArray< @@ -40,7 +40,7 @@ const Stream: StatelessComponent = props => { {props.me ? ( - + ) : ( )} @@ -56,13 +56,13 @@ const Stream: StatelessComponent = props => { me={props.me} settings={props.settings} comment={comment} - asset={props.asset} + story={props.story} /> ))} diff --git a/src/core/client/stream/tabs/comments/components/__snapshots__/ConversationThread.spec.tsx.snap b/src/core/client/stream/tabs/comments/components/__snapshots__/ConversationThread.spec.tsx.snap index 604420bfa..fd5b6efc8 100644 --- a/src/core/client/stream/tabs/comments/components/__snapshots__/ConversationThread.spec.tsx.snap +++ b/src/core/client/stream/tabs/comments/components/__snapshots__/ConversationThread.spec.tsx.snap @@ -5,11 +5,11 @@ exports[`renders with no parent comments 1`] = ` className="root ConversationThread-root" >
`; @@ -66,11 +66,11 @@ exports[`with 2 remaining parent comments renders correctly 1`] = ` end={true} > @@ -129,11 +129,11 @@ exports[`with 2 remaining parent comments renders with disabled load more 1`] = end={true} > diff --git a/src/core/client/stream/tabs/comments/components/__snapshots__/PermalinkView.spec.tsx.snap b/src/core/client/stream/tabs/comments/components/__snapshots__/PermalinkView.spec.tsx.snap index 1bb7fdc42..fded9cedd 100644 --- a/src/core/client/stream/tabs/comments/components/__snapshots__/PermalinkView.spec.tsx.snap +++ b/src/core/client/stream/tabs/comments/components/__snapshots__/PermalinkView.spec.tsx.snap @@ -106,19 +106,19 @@ exports[`renders correctly 1`] = `
diff --git a/src/core/client/stream/tabs/comments/components/__snapshots__/ReplyList.spec.tsx.snap b/src/core/client/stream/tabs/comments/components/__snapshots__/ReplyList.spec.tsx.snap index debd13a5b..666ab4bd9 100644 --- a/src/core/client/stream/tabs/comments/components/__snapshots__/ReplyList.spec.tsx.snap +++ b/src/core/client/stream/tabs/comments/components/__snapshots__/ReplyList.spec.tsx.snap @@ -9,11 +9,6 @@ exports[`renders correctly 1`] = ` key="comment-1" > @@ -78,11 +78,6 @@ exports[`when there is more disables load more button 1`] = ` key="comment-1" > @@ -140,12 +140,6 @@ exports[`when there is more disables load more button 1`] = ` key="comment-1" > diff --git a/src/core/client/stream/tabs/comments/containers/CommentContainer.spec.tsx b/src/core/client/stream/tabs/comments/containers/CommentContainer.spec.tsx index c225bd148..35cf6bc73 100644 --- a/src/core/client/stream/tabs/comments/containers/CommentContainer.spec.tsx +++ b/src/core/client/stream/tabs/comments/containers/CommentContainer.spec.tsx @@ -13,8 +13,8 @@ const CommentContainerN = removeFragmentRefs(CommentContainer); it("renders username and body", () => { const props: PropTypesOf = { me: null, - asset: { - url: "http://localhost/asset", + story: { + url: "http://localhost/story", }, comment: { id: "comment-id", @@ -51,8 +51,8 @@ it("renders username and body", () => { it("renders body only", () => { const props: PropTypesOf = { me: null, - asset: { - url: "http://localhost/asset", + story: { + url: "http://localhost/story", }, comment: { id: "comment-id", @@ -87,8 +87,8 @@ it("renders body only", () => { it("hide reply button", () => { const props: PropTypesOf = { me: null, - asset: { - url: "http://localhost/asset", + story: { + url: "http://localhost/story", }, comment: { id: "comment-id", @@ -125,8 +125,8 @@ it("hide reply button", () => { it("shows conversation link", () => { const props: PropTypesOf = { me: null, - asset: { - url: "http://localhost/asset", + story: { + url: "http://localhost/story", }, settings: { reaction: { @@ -165,8 +165,8 @@ it("shows conversation link", () => { it("renders in reply to", () => { const props: PropTypesOf = { me: null, - asset: { - url: "http://localhost/asset", + story: { + url: "http://localhost/story", }, comment: { id: "comment-id", diff --git a/src/core/client/stream/tabs/comments/containers/CommentContainer.tsx b/src/core/client/stream/tabs/comments/containers/CommentContainer.tsx index 8d0de18b6..c11c05551 100644 --- a/src/core/client/stream/tabs/comments/containers/CommentContainer.tsx +++ b/src/core/client/stream/tabs/comments/containers/CommentContainer.tsx @@ -6,10 +6,10 @@ import { isBeforeDate } from "talk-common/utils"; import { getURLWithCommentID } from "talk-framework/helpers"; import withFragmentContainer from "talk-framework/lib/relay/withFragmentContainer"; import { PropTypesOf } from "talk-framework/types"; -import { CommentContainer_asset as AssetData } from "talk-stream/__generated__/CommentContainer_asset.graphql"; import { CommentContainer_comment as CommentData } from "talk-stream/__generated__/CommentContainer_comment.graphql"; import { CommentContainer_me as MeData } from "talk-stream/__generated__/CommentContainer_me.graphql"; import { CommentContainer_settings as SettingsData } from "talk-stream/__generated__/CommentContainer_settings.graphql"; +import { CommentContainer_story as StoryData } from "talk-stream/__generated__/CommentContainer_story.graphql"; import { SetCommentIDMutation, ShowAuthPopupMutation, @@ -32,7 +32,7 @@ import ReplyCommentFormContainer from "./ReplyCommentFormContainer"; interface InnerProps { me: MeData | null; comment: CommentData; - asset: AssetData; + story: StoryData; settings: SettingsData; indentLevel?: number; showAuthPopup: ShowAuthPopupMutation; @@ -137,7 +137,7 @@ export class CommentContainer extends Component { const { comment, settings, - asset, + story, indentLevel, localReply, disableReplies, @@ -196,7 +196,7 @@ export class CommentContainer extends Component { /> )} { }`} onClick={this.handleShowConversation} href={getURLWithCommentID( - this.props.asset.url, + this.props.story.url, this.props.comment.id )} /> @@ -223,7 +223,7 @@ export class CommentContainer extends Component { {showReplyDialog && ( @@ -242,11 +242,11 @@ const enhanced = withSetCommentIDMutation( ...ReactionButtonContainer_me } `, - asset: graphql` - fragment CommentContainer_asset on Asset { + story: graphql` + fragment CommentContainer_story on Story { url - ...ReplyCommentFormContainer_asset - ...PermalinkButtonContainer_asset + ...ReplyCommentFormContainer_story + ...PermalinkButtonContainer_story } `, comment: graphql` diff --git a/src/core/client/stream/tabs/comments/containers/ConversationThreadContainer.tsx b/src/core/client/stream/tabs/comments/containers/ConversationThreadContainer.tsx index 2d31d97eb..ac49b218e 100644 --- a/src/core/client/stream/tabs/comments/containers/ConversationThreadContainer.tsx +++ b/src/core/client/stream/tabs/comments/containers/ConversationThreadContainer.tsx @@ -4,10 +4,10 @@ import { graphql, RelayPaginationProp } from "react-relay"; import { withContext } from "talk-framework/lib/bootstrap"; import { withPaginationContainer } from "talk-framework/lib/relay"; -import { ConversationThreadContainer_asset as AssetData } from "talk-stream/__generated__/ConversationThreadContainer_asset.graphql"; import { ConversationThreadContainer_comment as CommentData } from "talk-stream/__generated__/ConversationThreadContainer_comment.graphql"; import { ConversationThreadContainer_me as MeData } from "talk-stream/__generated__/ConversationThreadContainer_me.graphql"; import { ConversationThreadContainer_settings as SettingsData } from "talk-stream/__generated__/ConversationThreadContainer_settings.graphql"; +import { ConversationThreadContainer_story as StoryData } from "talk-stream/__generated__/ConversationThreadContainer_story.graphql"; import { ConversationThreadContainerPaginationQueryVariables } from "talk-stream/__generated__/ConversationThreadContainerPaginationQuery.graphql"; import { SetCommentIDMutation, @@ -18,7 +18,7 @@ import ConversationThread from "../components/ConversationThread"; interface ConversationThreadContainerProps { comment: CommentData; - asset: AssetData; + story: StoryData; settings: SettingsData; me: MeData | null; setCommentID: SetCommentIDMutation; @@ -51,12 +51,12 @@ class ConversationThreadContainer extends React.Component< }; public render() { - const { comment, asset, me, settings } = this.props; + const { comment, story, me, settings } = this.props; const hasMore = this.props.relay.hasMore(); return ( edge.node)} @@ -95,10 +95,10 @@ const enhanced = withContext(ctx => ({ FragmentVariables >( { - asset: graphql` - fragment ConversationThreadContainer_asset on Asset { - ...CommentContainer_asset - ...LocalReplyListContainer_asset + story: graphql` + fragment ConversationThreadContainer_story on Story { + ...CommentContainer_story + ...LocalReplyListContainer_story } `, settings: graphql` diff --git a/src/core/client/stream/tabs/comments/containers/LocalReplyListContainer.tsx b/src/core/client/stream/tabs/comments/containers/LocalReplyListContainer.tsx index aa4711093..8dbad3183 100644 --- a/src/core/client/stream/tabs/comments/containers/LocalReplyListContainer.tsx +++ b/src/core/client/stream/tabs/comments/containers/LocalReplyListContainer.tsx @@ -3,17 +3,17 @@ import { graphql } from "react-relay"; import withFragmentContainer from "talk-framework/lib/relay/withFragmentContainer"; import { PropTypesOf } from "talk-framework/types"; -import { LocalReplyListContainer_asset as AssetData } from "talk-stream/__generated__/LocalReplyListContainer_asset.graphql"; import { LocalReplyListContainer_comment as CommentData } from "talk-stream/__generated__/LocalReplyListContainer_comment.graphql"; import { LocalReplyListContainer_me as MeData } from "talk-stream/__generated__/LocalReplyListContainer_me.graphql"; import { LocalReplyListContainer_settings as SettingsData } from "talk-stream/__generated__/LocalReplyListContainer_settings.graphql"; +import { LocalReplyListContainer_story as StoryData } from "talk-stream/__generated__/LocalReplyListContainer_story.graphql"; import ReplyList from "../components/ReplyList"; interface InnerProps { indentLevel: number; me: MeData; - asset: AssetData; + story: StoryData; comment: CommentData; settings: SettingsData; } @@ -35,7 +35,7 @@ export class LocalReplyListContainer extends Component { settings={this.props.settings} comment={this.props.comment} comments={this.props.comment.localReplies} - asset={this.props.asset} + story={this.props.story} indentLevel={this.props.indentLevel} disableReplies /> @@ -49,9 +49,9 @@ const enhanced = withFragmentContainer({ ...CommentContainer_me } `, - asset: graphql` - fragment LocalReplyListContainer_asset on Asset { - ...CommentContainer_asset + story: graphql` + fragment LocalReplyListContainer_story on Story { + ...CommentContainer_story } `, comment: graphql` diff --git a/src/core/client/stream/tabs/comments/containers/PermalinkButtonContainer.tsx b/src/core/client/stream/tabs/comments/containers/PermalinkButtonContainer.tsx index 2dc1a1d0b..d23e01a0a 100644 --- a/src/core/client/stream/tabs/comments/containers/PermalinkButtonContainer.tsx +++ b/src/core/client/stream/tabs/comments/containers/PermalinkButtonContainer.tsx @@ -2,30 +2,30 @@ import React, { StatelessComponent } from "react"; import { graphql } from "react-relay"; import { getURLWithCommentID } from "talk-framework/helpers"; import { withFragmentContainer } from "talk-framework/lib/relay"; -import { PermalinkButtonContainer_asset as AssetData } from "talk-stream/__generated__/PermalinkButtonContainer_asset.graphql"; +import { PermalinkButtonContainer_story as StoryData } from "talk-stream/__generated__/PermalinkButtonContainer_story.graphql"; import PermalinkButton from "../components/PermalinkButton"; interface InnerProps { - asset: AssetData; + story: StoryData; commentID: string; } export const PermalinkButtonContainerProps: StatelessComponent = ({ - asset, + story, commentID, }) => { return ( ); }; const enhanced = withFragmentContainer({ - asset: graphql` - fragment PermalinkButtonContainer_asset on Asset { + story: graphql` + fragment PermalinkButtonContainer_story on Story { url } `, diff --git a/src/core/client/stream/tabs/comments/containers/PermalinkViewContainer.tsx b/src/core/client/stream/tabs/comments/containers/PermalinkViewContainer.tsx index cc0c0719c..00c8ea278 100644 --- a/src/core/client/stream/tabs/comments/containers/PermalinkViewContainer.tsx +++ b/src/core/client/stream/tabs/comments/containers/PermalinkViewContainer.tsx @@ -5,10 +5,10 @@ import { graphql } from "react-relay"; import { getURLWithCommentID } from "talk-framework/helpers"; import { withContext } from "talk-framework/lib/bootstrap"; import { withFragmentContainer } from "talk-framework/lib/relay"; -import { PermalinkViewContainer_asset as AssetData } from "talk-stream/__generated__/PermalinkViewContainer_asset.graphql"; import { PermalinkViewContainer_comment as CommentData } from "talk-stream/__generated__/PermalinkViewContainer_comment.graphql"; import { PermalinkViewContainer_me as MeData } from "talk-stream/__generated__/PermalinkViewContainer_me.graphql"; import { PermalinkViewContainer_settings as SettingsData } from "talk-stream/__generated__/PermalinkViewContainer_settings.graphql"; +import { PermalinkViewContainer_story as StoryData } from "talk-stream/__generated__/PermalinkViewContainer_story.graphql"; import { SetCommentIDMutation, withSetCommentIDMutation, @@ -18,7 +18,7 @@ import PermalinkView from "../components/PermalinkView"; interface PermalinkViewContainerProps { comment: CommentData | null; - asset: AssetData; + story: StoryData; settings: SettingsData; me: MeData | null; setCommentID: SetCommentIDMutation; @@ -45,11 +45,11 @@ class PermalinkViewContainer extends React.Component< } public render() { - const { comment, asset, me, settings } = this.props; + const { comment, story, me, settings } = this.props; return ( ({ }))( withSetCommentIDMutation( withFragmentContainer({ - asset: graphql` - fragment PermalinkViewContainer_asset on Asset { - ...ConversationThreadContainer_asset - ...ReplyListContainer1_asset + story: graphql` + fragment PermalinkViewContainer_story on Story { + ...ConversationThreadContainer_story + ...ReplyListContainer1_story } `, comment: graphql` diff --git a/src/core/client/stream/tabs/comments/containers/PostCommentFormContainer.spec.tsx b/src/core/client/stream/tabs/comments/containers/PostCommentFormContainer.spec.tsx index ff72be551..432151618 100644 --- a/src/core/client/stream/tabs/comments/containers/PostCommentFormContainer.spec.tsx +++ b/src/core/client/stream/tabs/comments/containers/PostCommentFormContainer.spec.tsx @@ -14,7 +14,7 @@ it("renders correctly", async () => { const props: PropTypesOf = { // tslint:disable-next-line:no-empty createComment: (() => {}) as any, - assetID: "asset-id", + storyID: "story-id", sessionStorage: createPromisifiedStorage(), }; @@ -28,7 +28,7 @@ it("renders with initialValues", async () => { const props: PropTypesOf = { // tslint:disable-next-line:no-empty createComment: (() => {}) as any, - assetID: "asset-id", + storyID: "story-id", sessionStorage: createPromisifiedStorage(), }; @@ -44,7 +44,7 @@ it("save values", async () => { const props: PropTypesOf = { // tslint:disable-next-line:no-empty createComment: (() => {}) as any, - assetID: "asset-id", + storyID: "story-id", sessionStorage: createPromisifiedStorage(), }; @@ -61,7 +61,7 @@ it("save values", async () => { }); it("creates a comment", async () => { - const assetID = "asset-id"; + const storyID = "story-id"; const input = { body: "Hello World!" }; const createCommentStub = sinon.stub(); const form = { reset: noop }; @@ -74,7 +74,7 @@ it("creates a comment", async () => { const props: PropTypesOf = { // tslint:disable-next-line:no-empty createComment: createCommentStub, - assetID, + storyID, sessionStorage: createPromisifiedStorage(), }; @@ -89,7 +89,7 @@ it("creates a comment", async () => { .onSubmit(input, form); expect( createCommentStub.calledWith({ - assetID, + storyID, ...input, }) ).toBeTruthy(); diff --git a/src/core/client/stream/tabs/comments/containers/PostCommentFormContainer.tsx b/src/core/client/stream/tabs/comments/containers/PostCommentFormContainer.tsx index 17e5f65c5..ba45dd2c9 100644 --- a/src/core/client/stream/tabs/comments/containers/PostCommentFormContainer.tsx +++ b/src/core/client/stream/tabs/comments/containers/PostCommentFormContainer.tsx @@ -15,7 +15,7 @@ import PostCommentForm, { interface InnerProps { createComment: CreateCommentMutation; - assetID: string; + storyID: string; sessionStorage: PromisifiedStorage; } @@ -54,7 +54,7 @@ export class PostCommentFormContainer extends Component { ) => { try { await this.props.createComment({ - assetID: this.props.assetID, + storyID: this.props.storyID, ...input, }); form.reset({}); diff --git a/src/core/client/stream/tabs/comments/containers/ReplyCommentFormContainer.spec.tsx b/src/core/client/stream/tabs/comments/containers/ReplyCommentFormContainer.spec.tsx index f2bcef6c1..902393d6c 100644 --- a/src/core/client/stream/tabs/comments/containers/ReplyCommentFormContainer.spec.tsx +++ b/src/core/client/stream/tabs/comments/containers/ReplyCommentFormContainer.spec.tsx @@ -20,8 +20,8 @@ function getContextKey(commentID: string) { it("renders correctly", async () => { const props: PropTypesOf = { createComment: noop as any, - asset: { - id: "asset-id", + story: { + id: "story-id", }, comment: { id: "comment-id", @@ -42,8 +42,8 @@ it("renders correctly", async () => { it("renders with initialValues", async () => { const props: PropTypesOf = { createComment: noop as any, - asset: { - id: "asset-id", + story: { + id: "story-id", }, comment: { id: "comment-id", @@ -69,8 +69,8 @@ it("renders with initialValues", async () => { it("save values", async () => { const props: PropTypesOf = { createComment: noop as any, - asset: { - id: "asset-id", + story: { + id: "story-id", }, comment: { id: "comment-id", @@ -100,7 +100,7 @@ it("save values", async () => { }); it("creates a comment", async () => { - const assetID = "asset-id"; + const storyID = "story-id"; const input = { body: "Hello World!", local: false }; const createCommentStub = sinon.stub(); const form = { reset: noop }; @@ -108,8 +108,8 @@ it("creates a comment", async () => { const props: PropTypesOf = { createComment: createCommentStub, - asset: { - id: "asset-id", + story: { + id: "story-id", }, comment: { id: "comment-id", @@ -136,7 +136,7 @@ it("creates a comment", async () => { .onSubmit(input, form); expect( createCommentStub.calledWith({ - assetID, + storyID, parentID: props.comment.id, ...input, }) @@ -149,8 +149,8 @@ it("closes on cancel", async () => { const onCloseStub = sinon.stub(); const props: PropTypesOf = { createComment: noop as any, - asset: { - id: "asset-id", + story: { + id: "story-id", }, comment: { id: "comment-id", @@ -187,8 +187,8 @@ it("autofocuses", async () => { const rte = { focus: focusStub }; const props: PropTypesOf = { createComment: noop as any, - asset: { - id: "asset-id", + story: { + id: "story-id", }, comment: { id: "comment-id", diff --git a/src/core/client/stream/tabs/comments/containers/ReplyCommentFormContainer.tsx b/src/core/client/stream/tabs/comments/containers/ReplyCommentFormContainer.tsx index 27c8f0ca1..f309b6d29 100644 --- a/src/core/client/stream/tabs/comments/containers/ReplyCommentFormContainer.tsx +++ b/src/core/client/stream/tabs/comments/containers/ReplyCommentFormContainer.tsx @@ -7,8 +7,8 @@ import { BadUserInputError } from "talk-framework/lib/errors"; import { withFragmentContainer } from "talk-framework/lib/relay"; import { PromisifiedStorage } from "talk-framework/lib/storage"; import { PropTypesOf } from "talk-framework/types"; -import { ReplyCommentFormContainer_asset as AssetData } from "talk-stream/__generated__/ReplyCommentFormContainer_asset.graphql"; import { ReplyCommentFormContainer_comment as CommentData } from "talk-stream/__generated__/ReplyCommentFormContainer_comment.graphql"; +import { ReplyCommentFormContainer_story as StoryData } from "talk-stream/__generated__/ReplyCommentFormContainer_story.graphql"; import { CreateCommentMutation, withCreateCommentMutation, @@ -22,7 +22,7 @@ interface InnerProps { createComment: CreateCommentMutation; sessionStorage: PromisifiedStorage; comment: CommentData; - asset: AssetData; + story: StoryData; onClose?: () => void; autofocus: boolean; localReply?: boolean; @@ -75,7 +75,7 @@ export class ReplyCommentFormContainer extends Component { ) => { try { await this.props.createComment({ - assetID: this.props.asset.id, + storyID: this.props.story.id, parentID: this.props.comment.id, local: this.props.localReply, ...input, @@ -129,8 +129,8 @@ const enhanced = withContext(({ sessionStorage, browserInfo }) => ({ }))( withCreateCommentMutation( withFragmentContainer({ - asset: graphql` - fragment ReplyCommentFormContainer_asset on Asset { + story: graphql` + fragment ReplyCommentFormContainer_story on Story { id } `, diff --git a/src/core/client/stream/tabs/comments/containers/ReplyListContainer.spec.tsx b/src/core/client/stream/tabs/comments/containers/ReplyListContainer.spec.tsx index 6d440b197..aaad2d63e 100644 --- a/src/core/client/stream/tabs/comments/containers/ReplyListContainer.spec.tsx +++ b/src/core/client/stream/tabs/comments/containers/ReplyListContainer.spec.tsx @@ -13,8 +13,8 @@ const ReplyListContainerN = removeFragmentRefs(ReplyListContainer); it("renders correctly", () => { const props: PropTypesOf = { - asset: { - id: "asset-id", + story: { + id: "story-id", }, comment: { id: "comment-id", @@ -43,8 +43,8 @@ it("renders correctly", () => { it("renders correctly when replies are empty", () => { const props: PropTypesOf = { - asset: { - id: "asset-id", + story: { + id: "story-id", }, comment: { id: "comment-id", @@ -72,8 +72,8 @@ it("renders correctly when replies are empty", () => { describe("when has more replies", () => { let finishLoading: ((error?: Error) => void) | null = null; const props: PropTypesOf = { - asset: { - id: "asset-id", + story: { + id: "story-id", }, comment: { id: "comment-id", diff --git a/src/core/client/stream/tabs/comments/containers/ReplyListContainer.tsx b/src/core/client/stream/tabs/comments/containers/ReplyListContainer.tsx index d9f26cab1..183a62ad3 100644 --- a/src/core/client/stream/tabs/comments/containers/ReplyListContainer.tsx +++ b/src/core/client/stream/tabs/comments/containers/ReplyListContainer.tsx @@ -4,10 +4,10 @@ import { withProps } from "recompose"; import { withPaginationContainer } from "talk-framework/lib/relay"; import { PropTypesOf } from "talk-framework/types"; -import { ReplyListContainer1_asset as AssetData } from "talk-stream/__generated__/ReplyListContainer1_asset.graphql"; import { ReplyListContainer1_comment as CommentData } from "talk-stream/__generated__/ReplyListContainer1_comment.graphql"; import { ReplyListContainer1_me as MeData } from "talk-stream/__generated__/ReplyListContainer1_me.graphql"; import { ReplyListContainer1_settings as SettingsData } from "talk-stream/__generated__/ReplyListContainer1_settings.graphql"; +import { ReplyListContainer1_story as StoryData } from "talk-stream/__generated__/ReplyListContainer1_story.graphql"; import { COMMENT_SORT, ReplyListContainer1PaginationQueryVariables, @@ -24,7 +24,7 @@ type ReplyNode5 = UnpackArray["node"]; export interface BaseProps { me: MeData | null; - asset: AssetData; + story: StoryData; comment: CommentData; settings: SettingsData; relay: RelayPaginationProp; @@ -62,7 +62,7 @@ export class ReplyListContainer extends React.Component { ), @@ -74,7 +74,7 @@ export class ReplyListContainer extends React.Component { me={this.props.me} comment={this.props.comment} comments={comments} - asset={this.props.asset} + story={this.props.story} settings={this.props.settings} onShowAll={this.showAll} hasMore={this.props.relay.hasMore()} @@ -108,7 +108,7 @@ function createReplyListContainer( indentLevel: number, fragments: { me: GraphQLTaggedNode; - asset: GraphQLTaggedNode; + story: GraphQLTaggedNode; comment: GraphQLTaggedNode; settings: GraphQLTaggedNode; }, @@ -168,10 +168,10 @@ const ReplyListContainer5 = createReplyListContainer( ...CommentContainer_settings } `, - asset: graphql` - fragment ReplyListContainer5_asset on Asset { - ...CommentContainer_asset - ...LocalReplyListContainer_asset + story: graphql` + fragment ReplyListContainer5_story on Story { + ...CommentContainer_story + ...LocalReplyListContainer_story } `, comment: graphql` @@ -230,10 +230,10 @@ const ReplyListContainer4 = createReplyListContainer( ...CommentContainer_settings } `, - asset: graphql` - fragment ReplyListContainer4_asset on Asset { - ...ReplyListContainer5_asset - ...CommentContainer_asset + story: graphql` + fragment ReplyListContainer4_story on Story { + ...ReplyListContainer5_story + ...CommentContainer_story } `, comment: graphql` @@ -290,10 +290,10 @@ const ReplyListContainer3 = createReplyListContainer( ...CommentContainer_settings } `, - asset: graphql` - fragment ReplyListContainer3_asset on Asset { - ...ReplyListContainer4_asset - ...CommentContainer_asset + story: graphql` + fragment ReplyListContainer3_story on Story { + ...ReplyListContainer4_story + ...CommentContainer_story } `, comment: graphql` @@ -350,10 +350,10 @@ const ReplyListContainer2 = createReplyListContainer( ...CommentContainer_settings } `, - asset: graphql` - fragment ReplyListContainer2_asset on Asset { - ...ReplyListContainer3_asset - ...CommentContainer_asset + story: graphql` + fragment ReplyListContainer2_story on Story { + ...ReplyListContainer3_story + ...CommentContainer_story } `, comment: graphql` @@ -410,10 +410,10 @@ const ReplyListContainer1 = createReplyListContainer( ...CommentContainer_settings } `, - asset: graphql` - fragment ReplyListContainer1_asset on Asset { - ...ReplyListContainer2_asset - ...CommentContainer_asset + story: graphql` + fragment ReplyListContainer1_story on Story { + ...ReplyListContainer2_story + ...CommentContainer_story } `, comment: graphql` diff --git a/src/core/client/stream/tabs/comments/containers/StreamContainer.spec.tsx b/src/core/client/stream/tabs/comments/containers/StreamContainer.spec.tsx index 8ba69289f..5876f902e 100644 --- a/src/core/client/stream/tabs/comments/containers/StreamContainer.spec.tsx +++ b/src/core/client/stream/tabs/comments/containers/StreamContainer.spec.tsx @@ -13,8 +13,8 @@ const StreamContainerN = removeFragmentRefs(StreamContainer); it("renders correctly", () => { const props: PropTypesOf = { - asset: { - id: "asset-id", + story: { + id: "story-id", isClosed: false, comments: { edges: [{ node: { id: "comment-1" } }, { node: { id: "comment-2" } }], @@ -39,8 +39,8 @@ it("renders correctly", () => { describe("when has more comments", () => { let finishLoading: ((error?: Error) => void) | null = null; const props: PropTypesOf = { - asset: { - id: "asset-id", + story: { + id: "story-id", isClosed: false, comments: { edges: [{ node: { id: "comment-1" } }, { node: { id: "comment-2" } }], diff --git a/src/core/client/stream/tabs/comments/containers/StreamContainer.tsx b/src/core/client/stream/tabs/comments/containers/StreamContainer.tsx index e9127c913..059d54dd5 100644 --- a/src/core/client/stream/tabs/comments/containers/StreamContainer.tsx +++ b/src/core/client/stream/tabs/comments/containers/StreamContainer.tsx @@ -3,9 +3,9 @@ import { graphql, RelayPaginationProp } from "react-relay"; import { withPaginationContainer } from "talk-framework/lib/relay"; import { PropTypesOf } from "talk-framework/types"; -import { StreamContainer_asset as AssetData } from "talk-stream/__generated__/StreamContainer_asset.graphql"; import { StreamContainer_me as MeData } from "talk-stream/__generated__/StreamContainer_me.graphql"; import { StreamContainer_settings as SettingsData } from "talk-stream/__generated__/StreamContainer_settings.graphql"; +import { StreamContainer_story as StoryData } from "talk-stream/__generated__/StreamContainer_story.graphql"; import { COMMENT_SORT, StreamContainerPaginationQueryVariables, @@ -14,7 +14,7 @@ import { import Stream from "../components/Stream"; interface InnerProps { - asset: AssetData; + story: StoryData; settings: SettingsData; me: MeData | null; relay: RelayPaginationProp; @@ -35,10 +35,10 @@ export class StreamContainer extends React.Component { }; public render() { - const comments = this.props.asset.comments.edges.map(edge => edge.node); + const comments = this.props.story.comments.edges.map(edge => edge.node); return ( ( { - asset: graphql` - fragment StreamContainer_asset on Asset + story: graphql` + fragment StreamContainer_story on Story @argumentDefinitions( count: { type: "Int!", defaultValue: 5 } cursor: { type: "Cursor" } @@ -97,8 +97,8 @@ const enhanced = withPaginationContainer< } } } - ...CommentContainer_asset - ...ReplyListContainer1_asset + ...CommentContainer_story + ...ReplyListContainer1_story } `, me: graphql` @@ -118,7 +118,7 @@ const enhanced = withPaginationContainer< { direction: "forward", getConnectionFromProps(props) { - return props.asset && props.asset.comments; + return props.story && props.story.comments; }, // This is also the default implementation of `getFragmentVariables` if it isn't provided. getFragmentVariables(prevVars, totalCount) { @@ -132,9 +132,9 @@ const enhanced = withPaginationContainer< count, cursor, orderBy: fragmentVariables.orderBy, - // assetID isn't specified as an @argument for the fragment, but it should be a + // storyID isn't specified as an @argument for the fragment, but it should be a // variable available for the fragment under the query root. - assetID: props.asset.id, + storyID: props.story.id, }; }, query: graphql` @@ -144,10 +144,10 @@ const enhanced = withPaginationContainer< $count: Int! $cursor: Cursor $orderBy: COMMENT_SORT! - $assetID: ID + $storyID: ID ) { - asset(id: $assetID) { - ...StreamContainer_asset + story(id: $storyID) { + ...StreamContainer_story @arguments(count: $count, cursor: $cursor, orderBy: $orderBy) } } diff --git a/src/core/client/stream/tabs/comments/containers/__snapshots__/CommentContainer.spec.tsx.snap b/src/core/client/stream/tabs/comments/containers/__snapshots__/CommentContainer.spec.tsx.snap index 6921cae4b..2e77b0068 100644 --- a/src/core/client/stream/tabs/comments/containers/__snapshots__/CommentContainer.spec.tsx.snap +++ b/src/core/client/stream/tabs/comments/containers/__snapshots__/CommentContainer.spec.tsx.snap @@ -10,12 +10,12 @@ exports[`hide reply button 1`] = ` diff --git a/src/core/client/stream/tabs/comments/containers/__snapshots__/ReplyListContainer.spec.tsx.snap b/src/core/client/stream/tabs/comments/containers/__snapshots__/ReplyListContainer.spec.tsx.snap index 9fdedd985..409d0a4f3 100644 --- a/src/core/client/stream/tabs/comments/containers/__snapshots__/ReplyListContainer.spec.tsx.snap +++ b/src/core/client/stream/tabs/comments/containers/__snapshots__/ReplyListContainer.spec.tsx.snap @@ -2,11 +2,6 @@ exports[`renders correctly 1`] = ` , "showConversationLink": false, }, Object { "id": "comment-2", "replyListElement": , "showConversationLink": false, }, @@ -93,6 +88,11 @@ exports[`renders correctly 1`] = ` }, } } + story={ + Object { + "id": "story-id", + } + } /> `; @@ -100,11 +100,6 @@ exports[`renders correctly when replies are empty 1`] = `""`; exports[`when has more replies renders hasMore 1`] = ` `; exports[`when has more replies when showing all disables show all button 1`] = ` `; exports[`when has more replies when showing all enable show all button after loading is done 1`] = ` `; diff --git a/src/core/client/stream/tabs/comments/containers/__snapshots__/StreamContainer.spec.tsx.snap b/src/core/client/stream/tabs/comments/containers/__snapshots__/StreamContainer.spec.tsx.snap index 990b9c2fe..46bd7c114 100644 --- a/src/core/client/stream/tabs/comments/containers/__snapshots__/StreamContainer.spec.tsx.snap +++ b/src/core/client/stream/tabs/comments/containers/__snapshots__/StreamContainer.spec.tsx.snap @@ -2,26 +2,6 @@ exports[`renders correctly 1`] = ` -`; - -exports[`when has more comments renders hasMore 1`] = ` - +`; + +exports[`when has more comments renders hasMore 1`] = ` + -`; - -exports[`when has more comments when loading more disables load more button 1`] = ` - +`; + +exports[`when has more comments when loading more disables load more button 1`] = ` + -`; - -exports[`when has more comments when loading more enable load more button after loading is done 1`] = ` - +`; + +exports[`when has more comments when loading more enable load more button after loading is done 1`] = ` + `; diff --git a/src/core/client/stream/tabs/comments/queries/PermalinkViewQuery.spec.tsx b/src/core/client/stream/tabs/comments/queries/PermalinkViewQuery.spec.tsx index 01b91218a..3f95a8b6d 100644 --- a/src/core/client/stream/tabs/comments/queries/PermalinkViewQuery.spec.tsx +++ b/src/core/client/stream/tabs/comments/queries/PermalinkViewQuery.spec.tsx @@ -6,7 +6,7 @@ import { render } from "./PermalinkViewQuery"; it("renders permalink view container", () => { const data = { props: { - asset: {}, + story: {}, comment: {}, } as any, error: null, diff --git a/src/core/client/stream/tabs/comments/queries/PermalinkViewQuery.tsx b/src/core/client/stream/tabs/comments/queries/PermalinkViewQuery.tsx index 2f108f994..8e6b6db8d 100644 --- a/src/core/client/stream/tabs/comments/queries/PermalinkViewQuery.tsx +++ b/src/core/client/stream/tabs/comments/queries/PermalinkViewQuery.tsx @@ -26,10 +26,10 @@ export const render = ({ return
{error.message}
; } if (props) { - if (!props.asset) { + if (!props.story) { return ( - -
Asset not found
+ +
Story not found
); } @@ -38,7 +38,7 @@ export const render = ({ me={props.me} settings={props.settings} comment={props.comment} - asset={props.asset} + story={props.story} /> ); } @@ -46,20 +46,20 @@ export const render = ({ }; const PermalinkViewQuery: StatelessComponent = ({ - local: { commentID, assetID, assetURL }, + local: { commentID, storyID, storyURL }, }) => ( query={graphql` query PermalinkViewQuery( $commentID: ID! - $assetID: ID - $assetURL: String + $storyID: ID + $storyURL: String ) { me { ...PermalinkViewContainer_me } - asset(id: $assetID, url: $assetURL) { - ...PermalinkViewContainer_asset + story(id: $storyID, url: $storyURL) { + ...PermalinkViewContainer_story } comment(id: $commentID) { ...PermalinkViewContainer_comment @@ -71,8 +71,8 @@ const PermalinkViewQuery: StatelessComponent = ({ `} variables={{ commentID: commentID!, - assetID, - assetURL, + storyID, + storyURL, }} render={render} /> @@ -81,9 +81,9 @@ const PermalinkViewQuery: StatelessComponent = ({ const enhanced = withLocalStateContainer( graphql` fragment PermalinkViewQueryLocal on Local { - assetID + storyID commentID - assetURL + storyURL } ` )(PermalinkViewQuery); diff --git a/src/core/client/stream/tabs/comments/queries/StreamQuery.spec.tsx b/src/core/client/stream/tabs/comments/queries/StreamQuery.spec.tsx index 91a1a768c..1d992d4ee 100644 --- a/src/core/client/stream/tabs/comments/queries/StreamQuery.spec.tsx +++ b/src/core/client/stream/tabs/comments/queries/StreamQuery.spec.tsx @@ -6,7 +6,7 @@ import { render } from "./StreamQuery"; it("renders stream container", () => { const data = { props: { - asset: {}, + story: {}, } as any, error: null, }; diff --git a/src/core/client/stream/tabs/comments/queries/StreamQuery.tsx b/src/core/client/stream/tabs/comments/queries/StreamQuery.tsx index 4a7f2c2ed..0f27f2be6 100644 --- a/src/core/client/stream/tabs/comments/queries/StreamQuery.tsx +++ b/src/core/client/stream/tabs/comments/queries/StreamQuery.tsx @@ -24,10 +24,10 @@ export const render = ({ } if (props) { - if (!props.asset) { + if (!props.story) { return ( - -
Asset not found
+ +
Story not found
); } @@ -35,7 +35,7 @@ export const render = ({ ); } @@ -44,16 +44,16 @@ export const render = ({ }; const StreamQuery: StatelessComponent = ({ - local: { assetID, assetURL }, + local: { storyID, storyURL }, }) => ( query={graphql` - query StreamQuery($assetID: ID, $assetURL: String) { + query StreamQuery($storyID: ID, $storyURL: String) { me { ...StreamContainer_me } - asset(id: $assetID, url: $assetURL) { - ...StreamContainer_asset + story(id: $storyID, url: $storyURL) { + ...StreamContainer_story } settings { ...StreamContainer_settings @@ -61,8 +61,8 @@ const StreamQuery: StatelessComponent = ({ } `} variables={{ - assetID, - assetURL, + storyID, + storyURL, }} render={render} /> @@ -71,8 +71,8 @@ const StreamQuery: StatelessComponent = ({ const enhanced = withLocalStateContainer( graphql` fragment StreamQueryLocal on Local { - assetID - assetURL + storyID + storyURL } ` )(StreamQuery); diff --git a/src/core/client/stream/tabs/comments/queries/__snapshots__/PermalinkViewQuery.spec.tsx.snap b/src/core/client/stream/tabs/comments/queries/__snapshots__/PermalinkViewQuery.spec.tsx.snap index c25801800..ec6352698 100644 --- a/src/core/client/stream/tabs/comments/queries/__snapshots__/PermalinkViewQuery.spec.tsx.snap +++ b/src/core/client/stream/tabs/comments/queries/__snapshots__/PermalinkViewQuery.spec.tsx.snap @@ -10,7 +10,7 @@ exports[`renders loading 1`] = ``; exports[`renders permalink view container 1`] = ` `; diff --git a/src/core/client/stream/tabs/comments/queries/__snapshots__/StreamQuery.spec.tsx.snap b/src/core/client/stream/tabs/comments/queries/__snapshots__/StreamQuery.spec.tsx.snap index cd2a53005..c84ddc81f 100644 --- a/src/core/client/stream/tabs/comments/queries/__snapshots__/StreamQuery.spec.tsx.snap +++ b/src/core/client/stream/tabs/comments/queries/__snapshots__/StreamQuery.spec.tsx.snap @@ -10,6 +10,6 @@ exports[`renders loading 1`] = ``; exports[`renders stream container 1`] = ` `; diff --git a/src/core/client/stream/tabs/profile/components/CommentHistory.spec.tsx b/src/core/client/stream/tabs/profile/components/CommentHistory.spec.tsx index f9bde3692..78db55a30 100644 --- a/src/core/client/stream/tabs/profile/components/CommentHistory.spec.tsx +++ b/src/core/client/stream/tabs/profile/components/CommentHistory.spec.tsx @@ -11,7 +11,7 @@ const CommentHistoryN = removeFragmentRefs(CommentHistory); it("renders correctly", () => { const props: PropTypesOf = { - asset: {}, + story: {}, comments: [{ id: "comment-1" }, { id: "comment-2" }], onLoadMore: noop, hasMore: false, @@ -24,7 +24,7 @@ it("renders correctly", () => { describe("has more", () => { it("renders correctly", () => { const props: PropTypesOf = { - asset: {}, + story: {}, comments: [{ id: "comment-1" }, { id: "comment-2" }], onLoadMore: noop, hasMore: true, @@ -35,7 +35,7 @@ describe("has more", () => { }); it("disables load more", () => { const props: PropTypesOf = { - asset: {}, + story: {}, comments: [{ id: "comment-1" }, { id: "comment-2" }], onLoadMore: noop, hasMore: true, diff --git a/src/core/client/stream/tabs/profile/components/CommentHistory.tsx b/src/core/client/stream/tabs/profile/components/CommentHistory.tsx index 50648f246..b9b8bc5da 100644 --- a/src/core/client/stream/tabs/profile/components/CommentHistory.tsx +++ b/src/core/client/stream/tabs/profile/components/CommentHistory.tsx @@ -7,7 +7,7 @@ import { Button, HorizontalGutter, Typography } from "talk-ui/components"; import HistoryCommentContainer from "../containers/HistoryCommentContainer"; interface CommentHistoryProps { - asset: PropTypesOf["asset"]; + story: PropTypesOf["story"]; comments: Array< { id: string } & PropTypesOf["comment"] >; @@ -25,7 +25,7 @@ const CommentHistory: StatelessComponent = props => { {props.comments.map(comment => ( ))} diff --git a/src/core/client/stream/tabs/profile/components/HistoryComment.spec.tsx b/src/core/client/stream/tabs/profile/components/HistoryComment.spec.tsx index 1791765b6..2fe5ba906 100644 --- a/src/core/client/stream/tabs/profile/components/HistoryComment.spec.tsx +++ b/src/core/client/stream/tabs/profile/components/HistoryComment.spec.tsx @@ -14,8 +14,8 @@ it("renders correctly", () => { body: "Hello World", createdAt: "2018-07-06T18:24:00.000Z", replyCount: 4, - asset: { - title: "Asset Title", + story: { + title: "Story Title", }, conversationURL: "http://localhost/conversation", onGotoConversation: noop, diff --git a/src/core/client/stream/tabs/profile/components/HistoryComment.tsx b/src/core/client/stream/tabs/profile/components/HistoryComment.tsx index 4aca65531..827709ac3 100644 --- a/src/core/client/stream/tabs/profile/components/HistoryComment.tsx +++ b/src/core/client/stream/tabs/profile/components/HistoryComment.tsx @@ -17,7 +17,7 @@ export interface HistoryCommentProps { body: string | null; createdAt: string; replyCount: number | null; - asset: { + story: { title: string | null; }; conversationURL: string; @@ -27,7 +27,7 @@ export interface HistoryCommentProps { const HistoryComment: StatelessComponent = props => { return ( - + {"Story: {$title}"} {props.createdAt} diff --git a/src/core/client/stream/tabs/profile/components/Profile.spec.tsx b/src/core/client/stream/tabs/profile/components/Profile.spec.tsx index c02477631..69c92942a 100644 --- a/src/core/client/stream/tabs/profile/components/Profile.spec.tsx +++ b/src/core/client/stream/tabs/profile/components/Profile.spec.tsx @@ -10,7 +10,7 @@ const ProfileN = removeFragmentRefs(Profile); it("renders correctly", () => { const props: PropTypesOf = { - asset: {}, + story: {}, me: {}, }; const wrapper = shallow(); diff --git a/src/core/client/stream/tabs/profile/components/Profile.tsx b/src/core/client/stream/tabs/profile/components/Profile.tsx index 58df61b21..5af8dee37 100644 --- a/src/core/client/stream/tabs/profile/components/Profile.tsx +++ b/src/core/client/stream/tabs/profile/components/Profile.tsx @@ -6,7 +6,7 @@ import { HorizontalGutter } from "talk-ui/components"; import CommentHistoryContainer from "../containers/CommentHistoryContainer"; export interface ProfileProps { - asset: PropTypesOf["asset"]; + story: PropTypesOf["story"]; me: PropTypesOf["me"] & PropTypesOf["me"]; } @@ -15,7 +15,7 @@ const Profile: StatelessComponent = props => { return ( - + ); }; diff --git a/src/core/client/stream/tabs/profile/components/__snapshots__/CommentHistory.spec.tsx.snap b/src/core/client/stream/tabs/profile/components/__snapshots__/CommentHistory.spec.tsx.snap index ec5b69a83..6eae11185 100644 --- a/src/core/client/stream/tabs/profile/components/__snapshots__/CommentHistory.spec.tsx.snap +++ b/src/core/client/stream/tabs/profile/components/__snapshots__/CommentHistory.spec.tsx.snap @@ -14,22 +14,22 @@ exports[`has more disables load more 1`] = ` `; diff --git a/src/core/client/stream/tabs/profile/components/__snapshots__/HistoryComment.spec.tsx.snap b/src/core/client/stream/tabs/profile/components/__snapshots__/HistoryComment.spec.tsx.snap index 9c4dc16ae..ad55b5b74 100644 --- a/src/core/client/stream/tabs/profile/components/__snapshots__/HistoryComment.spec.tsx.snap +++ b/src/core/client/stream/tabs/profile/components/__snapshots__/HistoryComment.spec.tsx.snap @@ -3,7 +3,7 @@ exports[`renders correctly 1`] = ` `; diff --git a/src/core/client/stream/tabs/profile/containers/CommentHistoryContainer.tsx b/src/core/client/stream/tabs/profile/containers/CommentHistoryContainer.tsx index 8c10ee259..7f215e9c5 100644 --- a/src/core/client/stream/tabs/profile/containers/CommentHistoryContainer.tsx +++ b/src/core/client/stream/tabs/profile/containers/CommentHistoryContainer.tsx @@ -2,15 +2,15 @@ import React from "react"; import { graphql, RelayPaginationProp } from "react-relay"; import { withPaginationContainer } from "talk-framework/lib/relay"; -import { CommentHistoryContainer_asset as AssetData } from "talk-stream/__generated__/CommentHistoryContainer_asset.graphql"; import { CommentHistoryContainer_me as MeData } from "talk-stream/__generated__/CommentHistoryContainer_me.graphql"; +import { CommentHistoryContainer_story as StoryData } from "talk-stream/__generated__/CommentHistoryContainer_story.graphql"; import { CommentHistoryContainerPaginationQueryVariables } from "talk-stream/__generated__/CommentHistoryContainerPaginationQuery.graphql"; import CommentHistory from "../components/CommentHistory"; interface CommentHistoryContainerProps { me: MeData; - asset: AssetData; + story: StoryData; relay: RelayPaginationProp; } @@ -25,7 +25,7 @@ export class CommentHistoryContainer extends React.Component< const comments = this.props.me.comments.edges.map(edge => edge.node); return ( ( { - asset: graphql` - fragment CommentHistoryContainer_asset on Asset { - ...HistoryCommentContainer_asset + story: graphql` + fragment CommentHistoryContainer_story on Story { + ...HistoryCommentContainer_story } `, me: graphql` diff --git a/src/core/client/stream/tabs/profile/containers/HistoryCommentContainer.tsx b/src/core/client/stream/tabs/profile/containers/HistoryCommentContainer.tsx index 8e0a21cca..6a9baa482 100644 --- a/src/core/client/stream/tabs/profile/containers/HistoryCommentContainer.tsx +++ b/src/core/client/stream/tabs/profile/containers/HistoryCommentContainer.tsx @@ -3,8 +3,8 @@ import { graphql } from "react-relay"; import { getURLWithCommentID } from "talk-framework/helpers"; import { withFragmentContainer } from "talk-framework/lib/relay"; -import { HistoryCommentContainer_asset as AssetData } from "talk-stream/__generated__/HistoryCommentContainer_asset.graphql"; import { HistoryCommentContainer_comment as CommentData } from "talk-stream/__generated__/HistoryCommentContainer_comment.graphql"; +import { HistoryCommentContainer_story as StoryData } from "talk-stream/__generated__/HistoryCommentContainer_story.graphql"; import { SetCommentIDMutation, withSetCommentIDMutation, @@ -13,7 +13,7 @@ import HistoryComment from "../components/HistoryComment"; interface HistoryCommentContainerProps { setCommentID: SetCommentIDMutation; - asset: AssetData; + story: StoryData; comment: CommentData; } @@ -21,7 +21,7 @@ export class HistoryCommentContainer extends React.Component< HistoryCommentContainerProps > { private handleGoToConversation = (e: React.MouseEvent) => { - if (this.props.asset.id === this.props.comment.asset.id) { + if (this.props.story.id === this.props.comment.story.id) { this.props.setCommentID({ id: this.props.comment.id }); e.preventDefault(); } @@ -31,7 +31,7 @@ export class HistoryCommentContainer extends React.Component< ({ - asset: graphql` - fragment HistoryCommentContainer_asset on Asset { + story: graphql` + fragment HistoryCommentContainer_story on Story { id } `, @@ -53,7 +53,7 @@ const enhanced = withSetCommentIDMutation( body createdAt replyCount - asset { + story { id title url diff --git a/src/core/client/stream/tabs/profile/containers/ProfileContainer.tsx b/src/core/client/stream/tabs/profile/containers/ProfileContainer.tsx index 390110f27..b014ce44d 100644 --- a/src/core/client/stream/tabs/profile/containers/ProfileContainer.tsx +++ b/src/core/client/stream/tabs/profile/containers/ProfileContainer.tsx @@ -2,25 +2,25 @@ import React from "react"; import { graphql } from "react-relay"; import { withFragmentContainer } from "talk-framework/lib/relay"; -import { ProfileContainer_asset as AssetData } from "talk-stream/__generated__/ProfileContainer_asset.graphql"; import { ProfileContainer_me as MeData } from "talk-stream/__generated__/ProfileContainer_me.graphql"; +import { ProfileContainer_story as StoryData } from "talk-stream/__generated__/ProfileContainer_story.graphql"; import Profile from "../components/Profile"; interface ProfileContainerProps { me: MeData; - asset: AssetData; + story: StoryData; } export class StreamContainer extends React.Component { public render() { - return ; + return ; } } const enhanced = withFragmentContainer({ - asset: graphql` - fragment ProfileContainer_asset on Asset { - ...CommentHistoryContainer_asset + story: graphql` + fragment ProfileContainer_story on Story { + ...CommentHistoryContainer_story } `, me: graphql` diff --git a/src/core/client/stream/tabs/profile/queries/ProfileQuery.tsx b/src/core/client/stream/tabs/profile/queries/ProfileQuery.tsx index e98212f77..d9d8dfdd3 100644 --- a/src/core/client/stream/tabs/profile/queries/ProfileQuery.tsx +++ b/src/core/client/stream/tabs/profile/queries/ProfileQuery.tsx @@ -33,27 +33,27 @@ export const render = ({
); } - if (!props.asset) { + if (!props.story) { return ( - -
Asset not found
+ +
Story not found
); } - return ; + return ; } return ; }; const ProfileQuery: StatelessComponent = ({ - local: { assetID, assetURL }, + local: { storyID, storyURL }, }) => ( query={graphql` - query ProfileQuery($assetID: ID, $assetURL: String) { - asset(id: $assetID, url: $assetURL) { - ...ProfileContainer_asset + query ProfileQuery($storyID: ID, $storyURL: String) { + story(id: $storyID, url: $storyURL) { + ...ProfileContainer_story } me { ...ProfileContainer_me @@ -61,8 +61,8 @@ const ProfileQuery: StatelessComponent = ({ } `} variables={{ - assetID, - assetURL, + storyID, + storyURL, }} render={render} /> @@ -71,8 +71,8 @@ const ProfileQuery: StatelessComponent = ({ const enhanced = withLocalStateContainer( graphql` fragment ProfileQueryLocal on Local { - assetID - assetURL + storyID + storyURL } ` )(ProfileQuery); diff --git a/src/core/client/stream/test/comments/__snapshots__/permalinkViewAssetNotFound.spec.tsx.snap b/src/core/client/stream/test/comments/__snapshots__/permalinkViewStoryNotFound.spec.tsx.snap similarity index 89% rename from src/core/client/stream/test/comments/__snapshots__/permalinkViewAssetNotFound.spec.tsx.snap rename to src/core/client/stream/test/comments/__snapshots__/permalinkViewStoryNotFound.spec.tsx.snap index 209fbe533..251c501e0 100644 --- a/src/core/client/stream/test/comments/__snapshots__/permalinkViewAssetNotFound.spec.tsx.snap +++ b/src/core/client/stream/test/comments/__snapshots__/permalinkViewStoryNotFound.spec.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`renders permalink view with unknown asset 1`] = ` +exports[`renders permalink view with unknown story 1`] = `
@@ -33,7 +33,7 @@ exports[`renders permalink view with unknown asset 1`] = ` role="tabpanel" >
- Asset not found + Story not found
diff --git a/src/core/client/stream/test/comments/__snapshots__/postLocalReply.spec.tsx.snap b/src/core/client/stream/test/comments/__snapshots__/postLocalReply.spec.tsx.snap index 860a55c52..27b9ee6a5 100644 --- a/src/core/client/stream/test/comments/__snapshots__/postLocalReply.spec.tsx.snap +++ b/src/core/client/stream/test/comments/__snapshots__/postLocalReply.spec.tsx.snap @@ -1011,7 +1011,7 @@ exports[`post a reply: open reply form 1`] = ` s.throws(), s => s - .withArgs(undefined, { id: assets[0].id, url: null }) - .returns(assets[0]) + .withArgs(undefined, { id: stories[0].id, url: null }) + .returns(stories[0]) ), me: sinon.stub().returns(users[0]), settings: sinon.stub().returns(settings), @@ -27,7 +27,7 @@ function createTestRenderer() { s .withArgs(undefined, { input: { - commentID: assets[0].comments.edges[0].node.id, + commentID: stories[0].comments.edges[0].node.id, body: "Edited!", clientMutationId: "0", }, @@ -35,7 +35,7 @@ function createTestRenderer() { .returns({ // TODO: add a type assertion here to ensure that if the type changes, that the test will fail comment: { - id: assets[0].comments.edges[0].node.id, + id: stories[0].comments.edges[0].node.id, body: "Edited! (from server)", editing: { edited: true, @@ -52,7 +52,7 @@ function createTestRenderer() { logNetwork: false, resolvers, initLocalState: localRecord => { - localRecord.setValue(assets[0].id, "assetID"); + localRecord.setValue(stories[0].id, "storyID"); }, }); return testRenderer; @@ -63,7 +63,7 @@ afterAll(() => { }); it("edit a comment", async () => { - timekeeper.freeze(assets[0].comments.edges[0].node.createdAt); + timekeeper.freeze(stories[0].comments.edges[0].node.createdAt); const testRenderer = createTestRenderer(); // Wait for loading. @@ -95,7 +95,7 @@ it("edit a comment", async () => { }); it("cancel edit", async () => { - timekeeper.freeze(assets[0].comments.edges[0].node.createdAt); + timekeeper.freeze(stories[0].comments.edges[0].node.createdAt); const testRenderer = createTestRenderer(); await timeout(); @@ -113,7 +113,7 @@ it("cancel edit", async () => { }); it("shows expiry message", async () => { - timekeeper.freeze(assets[0].comments.edges[0].node.createdAt); + timekeeper.freeze(stories[0].comments.edges[0].node.createdAt); const testRenderer = createTestRenderer(); await timeout(); diff --git a/src/core/client/stream/test/comments/loadMore.spec.tsx b/src/core/client/stream/test/comments/loadMore.spec.tsx index bcbde1021..8edf35b86 100644 --- a/src/core/client/stream/test/comments/loadMore.spec.tsx +++ b/src/core/client/stream/test/comments/loadMore.spec.tsx @@ -4,13 +4,13 @@ import sinon from "sinon"; import { timeout } from "talk-common/utils"; import { createSinonStub } from "talk-framework/testHelpers"; -import { assets, comments, settings } from "../fixtures"; +import { comments, settings, stories } from "../fixtures"; import create from "./create"; let testRenderer: ReactTestRenderer; beforeEach(() => { - const assetStub = { - ...assets[0], + const storyStub = { + ...stories[0], comments: createSinonStub( s => s.throws(), s => @@ -54,17 +54,17 @@ beforeEach(() => { const resolvers = { Query: { - asset: createSinonStub( + story: createSinonStub( s => s.throws(), s => s .withArgs( undefined, sinon - .match({ id: assetStub.id, url: null }) - .or(sinon.match({ id: assetStub.id })) + .match({ id: storyStub.id, url: null }) + .or(sinon.match({ id: storyStub.id })) ) - .returns(assetStub) + .returns(storyStub) ), settings: sinon.stub().returns(settings), }, @@ -75,7 +75,7 @@ beforeEach(() => { logNetwork: false, resolvers, initLocalState: localRecord => { - localRecord.setValue(assetStub.id, "assetID"); + localRecord.setValue(storyStub.id, "storyID"); }, })); }); diff --git a/src/core/client/stream/test/comments/permalinkView.spec.tsx b/src/core/client/stream/test/comments/permalinkView.spec.tsx index 10d5cbc15..5cd33971d 100644 --- a/src/core/client/stream/test/comments/permalinkView.spec.tsx +++ b/src/core/client/stream/test/comments/permalinkView.spec.tsx @@ -4,7 +4,7 @@ import sinon from "sinon"; import { timeout } from "talk-common/utils"; import { createSinonStub } from "talk-framework/testHelpers"; -import { assets, comments, commentWithReplies, settings } from "../fixtures"; +import { comments, commentWithReplies, settings, stories } from "../fixtures"; import create from "./create"; let testRenderer: ReactTestRenderer; @@ -29,8 +29,8 @@ beforeEach(() => { }, }; - const assetStub = { - ...assets[0], + const storyStub = { + ...stories[0], comments: { pageInfo: { hasNextPage: false, @@ -50,12 +50,12 @@ beforeEach(() => { s => s.throws(), s => s.withArgs(undefined, { id: commentStub.id }).returns(commentStub) ), - asset: createSinonStub( + story: createSinonStub( s => s.throws(), s => s - .withArgs(undefined, { id: assetStub.id, url: null }) - .returns(assetStub) + .withArgs(undefined, { id: storyStub.id, url: null }) + .returns(storyStub) ), settings: sinon.stub().returns(settings), }, @@ -66,7 +66,7 @@ beforeEach(() => { logNetwork: false, resolvers, initLocalState: localRecord => { - localRecord.setValue(assetStub.id, "assetID"); + localRecord.setValue(storyStub.id, "storyID"); localRecord.setValue(commentStub.id, "commentID"); }, })); diff --git a/src/core/client/stream/test/comments/permalinkViewCommentNotFound.spec.tsx b/src/core/client/stream/test/comments/permalinkViewCommentNotFound.spec.tsx index 434eab212..5162388a6 100644 --- a/src/core/client/stream/test/comments/permalinkViewCommentNotFound.spec.tsx +++ b/src/core/client/stream/test/comments/permalinkViewCommentNotFound.spec.tsx @@ -4,7 +4,7 @@ import sinon from "sinon"; import { timeout } from "talk-common/utils"; import { createSinonStub } from "talk-framework/testHelpers"; -import { assets, comments, settings } from "../fixtures"; +import { comments, settings, stories } from "../fixtures"; import create from "./create"; let testRenderer: ReactTestRenderer; @@ -13,8 +13,8 @@ beforeEach(() => { ...comments[0], }; - const assetStub = { - ...assets[0], + const storyStub = { + ...stories[0], comments: { pageInfo: { hasNextPage: false, @@ -31,12 +31,12 @@ beforeEach(() => { const resolvers = { Query: { comment: () => null, - asset: createSinonStub( + story: createSinonStub( s => s.throws(), s => s - .withArgs(undefined, { id: assetStub.id, url: null }) - .returns(assetStub) + .withArgs(undefined, { id: storyStub.id, url: null }) + .returns(storyStub) ), settings: sinon.stub().returns(settings), }, @@ -47,7 +47,7 @@ beforeEach(() => { logNetwork: false, resolvers, initLocalState: localRecord => { - localRecord.setValue(assetStub.id, "assetID"); + localRecord.setValue(storyStub.id, "storyID"); localRecord.setValue("unknown-comment-id", "commentID"); }, })); diff --git a/src/core/client/stream/test/comments/permalinkViewLoadMoreParents.spec.tsx b/src/core/client/stream/test/comments/permalinkViewLoadMoreParents.spec.tsx index 0f50ce58c..87d5cd998 100644 --- a/src/core/client/stream/test/comments/permalinkViewLoadMoreParents.spec.tsx +++ b/src/core/client/stream/test/comments/permalinkViewLoadMoreParents.spec.tsx @@ -4,7 +4,7 @@ import sinon from "sinon"; import { timeout } from "talk-common/utils"; import { createSinonStub } from "talk-framework/testHelpers"; -import { assets, comments, settings } from "../fixtures"; +import { comments, settings, stories } from "../fixtures"; import create from "./create"; let testRenderer: ReactTestRenderer; @@ -43,8 +43,8 @@ beforeEach(() => { ), }; - const assetStub = { - ...assets[0], + const storyStub = { + ...stories[0], comments: { pageInfo: { hasNextPage: false, @@ -64,12 +64,12 @@ beforeEach(() => { s => s.throws(), s => s.withArgs(undefined, { id: commentStub.id }).returns(commentStub) ), - asset: createSinonStub( + story: createSinonStub( s => s.throws(), s => s - .withArgs(undefined, { id: assetStub.id, url: null }) - .returns(assetStub) + .withArgs(undefined, { id: storyStub.id, url: null }) + .returns(storyStub) ), settings: sinon.stub().returns(settings), }, @@ -80,7 +80,7 @@ beforeEach(() => { logNetwork: false, resolvers, initLocalState: localRecord => { - localRecord.setValue(assetStub.id, "assetID"); + localRecord.setValue(storyStub.id, "storyID"); localRecord.setValue(commentStub.id, "commentID"); }, })); diff --git a/src/core/client/stream/test/comments/permalinkViewAssetNotFound.spec.tsx b/src/core/client/stream/test/comments/permalinkViewStoryNotFound.spec.tsx similarity index 71% rename from src/core/client/stream/test/comments/permalinkViewAssetNotFound.spec.tsx rename to src/core/client/stream/test/comments/permalinkViewStoryNotFound.spec.tsx index 84d161158..460c1dbd3 100644 --- a/src/core/client/stream/test/comments/permalinkViewAssetNotFound.spec.tsx +++ b/src/core/client/stream/test/comments/permalinkViewStoryNotFound.spec.tsx @@ -3,15 +3,15 @@ import sinon from "sinon"; import { timeout } from "talk-common/utils"; -import { settings } from "../fixtures"; -import create from "./create"; +import create from "talk-stream/test/comments/create"; +import { settings } from "talk-stream/test/fixtures"; let testRenderer: ReactTestRenderer; beforeEach(() => { const resolvers = { Query: { comment: () => null, - asset: () => null, + story: () => null, settings: sinon.stub().returns(settings), }, }; @@ -21,13 +21,13 @@ beforeEach(() => { logNetwork: false, resolvers, initLocalState: localRecord => { - localRecord.setValue("unknown-asset-id", "assetID"); + localRecord.setValue("unknown-story-id", "storyID"); localRecord.setValue("unknown-comment-id", "commentID"); }, })); }); -it("renders permalink view with unknown asset", async () => { +it("renders permalink view with unknown story", async () => { // Wait for loading. await timeout(); expect(testRenderer.toJSON()).toMatchSnapshot(); diff --git a/src/core/client/stream/test/comments/postComment.spec.tsx b/src/core/client/stream/test/comments/postComment.spec.tsx index 35ce4c4f2..e2994ef53 100644 --- a/src/core/client/stream/test/comments/postComment.spec.tsx +++ b/src/core/client/stream/test/comments/postComment.spec.tsx @@ -5,7 +5,7 @@ import timekeeper from "timekeeper"; import { timeout } from "talk-common/utils"; import { createSinonStub } from "talk-framework/testHelpers"; -import { assets, baseComment, settings, users } from "../fixtures"; +import { baseComment, settings, stories, users } from "../fixtures"; import create from "./create"; let testRenderer: ReactTestRenderer; @@ -14,12 +14,12 @@ beforeEach(() => { Query: { settings: sinon.stub().returns(settings), me: sinon.stub().returns(users[0]), - asset: createSinonStub( + story: createSinonStub( s => s.throws(), s => s - .withArgs(undefined, { id: assets[0].id, url: null }) - .returns(assets[0]) + .withArgs(undefined, { id: stories[0].id, url: null }) + .returns(stories[0]) ), }, Mutation: { @@ -29,7 +29,7 @@ beforeEach(() => { s .withArgs(undefined, { input: { - assetID: assets[0].id, + storyID: stories[0].id, body: "Hello world!", clientMutationId: "0", }, @@ -56,7 +56,7 @@ beforeEach(() => { logNetwork: false, resolvers, initLocalState: localRecord => { - localRecord.setValue(assets[0].id, "assetID"); + localRecord.setValue(stories[0].id, "storyID"); }, })); }); diff --git a/src/core/client/stream/test/comments/postLocalReply.spec.tsx b/src/core/client/stream/test/comments/postLocalReply.spec.tsx index 3e665cf80..1bf80315c 100644 --- a/src/core/client/stream/test/comments/postLocalReply.spec.tsx +++ b/src/core/client/stream/test/comments/postLocalReply.spec.tsx @@ -6,9 +6,9 @@ import { timeout } from "talk-common/utils"; import { createSinonStub } from "talk-framework/testHelpers"; import { - assetWithDeepestReplies, baseComment, settings, + storyWithDeepestReplies, users, } from "../fixtures"; import create from "./create"; @@ -19,12 +19,12 @@ beforeEach(() => { Query: { settings: sinon.stub().returns(settings), me: sinon.stub().returns(users[0]), - asset: createSinonStub( + story: createSinonStub( s => s.throws(), s => s - .withArgs(undefined, { id: assetWithDeepestReplies.id, url: null }) - .returns(assetWithDeepestReplies) + .withArgs(undefined, { id: storyWithDeepestReplies.id, url: null }) + .returns(storyWithDeepestReplies) ), }, Mutation: { @@ -34,7 +34,7 @@ beforeEach(() => { s .withArgs(undefined, { input: { - assetID: assetWithDeepestReplies.id, + storyID: storyWithDeepestReplies.id, parentID: "comment-with-deepest-replies-5", body: "Hello world!", clientMutationId: "0", @@ -61,7 +61,7 @@ beforeEach(() => { logNetwork: false, resolvers, initLocalState: localRecord => { - localRecord.setValue(assetWithDeepestReplies.id, "assetID"); + localRecord.setValue(storyWithDeepestReplies.id, "storyID"); }, })); }); diff --git a/src/core/client/stream/test/comments/postReply.spec.tsx b/src/core/client/stream/test/comments/postReply.spec.tsx index ee7b34566..62f3d8465 100644 --- a/src/core/client/stream/test/comments/postReply.spec.tsx +++ b/src/core/client/stream/test/comments/postReply.spec.tsx @@ -5,7 +5,7 @@ import timekeeper from "timekeeper"; import { timeout } from "talk-common/utils"; import { createSinonStub } from "talk-framework/testHelpers"; -import { assets, baseComment, settings, users } from "../fixtures"; +import { baseComment, settings, stories, users } from "../fixtures"; import create from "./create"; let testRenderer: ReactTestRenderer; @@ -14,12 +14,12 @@ beforeEach(() => { Query: { settings: sinon.stub().returns(settings), me: sinon.stub().returns(users[0]), - asset: createSinonStub( + story: createSinonStub( s => s.throws(), s => s - .withArgs(undefined, { id: assets[0].id, url: null }) - .returns(assets[0]) + .withArgs(undefined, { id: stories[0].id, url: null }) + .returns(stories[0]) ), }, Mutation: { @@ -29,8 +29,8 @@ beforeEach(() => { s .withArgs(undefined, { input: { - assetID: assets[0].id, - parentID: assets[0].comments.edges[0].node.id, + storyID: stories[0].id, + parentID: stories[0].comments.edges[0].node.id, body: "Hello world!", clientMutationId: "0", }, @@ -56,7 +56,7 @@ beforeEach(() => { logNetwork: false, resolvers, initLocalState: localRecord => { - localRecord.setValue(assets[0].id, "assetID"); + localRecord.setValue(stories[0].id, "storyID"); }, })); }); diff --git a/src/core/client/stream/test/comments/renderReplies.spec.tsx b/src/core/client/stream/test/comments/renderReplies.spec.tsx index abf029955..086f38c19 100644 --- a/src/core/client/stream/test/comments/renderReplies.spec.tsx +++ b/src/core/client/stream/test/comments/renderReplies.spec.tsx @@ -4,19 +4,19 @@ import sinon from "sinon"; import { timeout } from "talk-common/utils"; import { createSinonStub } from "talk-framework/testHelpers"; -import { assetWithDeepReplies, settings } from "../fixtures"; +import { settings, storyWithDeepReplies } from "../fixtures"; import create from "./create"; let testRenderer: ReactTestRenderer; beforeEach(() => { const resolvers = { Query: { - asset: createSinonStub( + story: createSinonStub( s => s.throws(), s => s - .withArgs(undefined, { id: assetWithDeepReplies.id, url: null }) - .returns(assetWithDeepReplies) + .withArgs(undefined, { id: storyWithDeepReplies.id, url: null }) + .returns(storyWithDeepReplies) ), settings: sinon.stub().returns(settings), }, @@ -27,7 +27,7 @@ beforeEach(() => { logNetwork: false, resolvers, initLocalState: localRecord => { - localRecord.setValue(assetWithDeepReplies.id, "assetID"); + localRecord.setValue(storyWithDeepReplies.id, "storyID"); }, })); }); diff --git a/src/core/client/stream/test/comments/renderStream.spec.tsx b/src/core/client/stream/test/comments/renderStream.spec.tsx index 301fc57dd..5c9f46d35 100644 --- a/src/core/client/stream/test/comments/renderStream.spec.tsx +++ b/src/core/client/stream/test/comments/renderStream.spec.tsx @@ -4,19 +4,19 @@ import sinon from "sinon"; import { timeout } from "talk-common/utils"; import { createSinonStub } from "talk-framework/testHelpers"; -import { assets, settings } from "../fixtures"; +import { settings, stories } from "../fixtures"; import create from "./create"; let testRenderer: ReactTestRenderer; beforeEach(() => { const resolvers = { Query: { - asset: createSinonStub( + story: createSinonStub( s => s.throws(), s => s - .withArgs(undefined, { id: assets[0].id, url: null }) - .returns(assets[0]) + .withArgs(undefined, { id: stories[0].id, url: null }) + .returns(stories[0]) ), settings: sinon.stub().returns(settings), }, @@ -27,7 +27,7 @@ beforeEach(() => { logNetwork: false, resolvers, initLocalState: localRecord => { - localRecord.setValue(assets[0].id, "assetID"); + localRecord.setValue(stories[0].id, "storyID"); }, })); }); diff --git a/src/core/client/stream/test/comments/showAllReplies.spec.tsx b/src/core/client/stream/test/comments/showAllReplies.spec.tsx index b5122028d..833413bc3 100644 --- a/src/core/client/stream/test/comments/showAllReplies.spec.tsx +++ b/src/core/client/stream/test/comments/showAllReplies.spec.tsx @@ -4,7 +4,7 @@ import sinon from "sinon"; import { timeout } from "talk-common/utils"; import { createSinonStub } from "talk-framework/testHelpers"; -import { assets, comments, settings } from "../fixtures"; +import { comments, settings, stories } from "../fixtures"; import create from "./create"; let testRenderer: ReactTestRenderer; @@ -48,8 +48,8 @@ beforeEach(() => { ), }; - const assetStub = { - ...assets[0], + const storyStub = { + ...stories[0], comments: { pageInfo: { hasNextPage: false, @@ -70,12 +70,12 @@ beforeEach(() => { s => s.throws(), s => s.withArgs(undefined, { id: commentStub.id }).returns(commentStub) ), - asset: createSinonStub( + story: createSinonStub( s => s.throws(), s => s - .withArgs(undefined, { id: assetStub.id, url: null }) - .returns(assetStub) + .withArgs(undefined, { id: storyStub.id, url: null }) + .returns(storyStub) ), }, }; @@ -85,7 +85,7 @@ beforeEach(() => { logNetwork: false, resolvers, initLocalState: localRecord => { - localRecord.setValue(assetStub.id, "assetID"); + localRecord.setValue(storyStub.id, "storyID"); }, })); }); diff --git a/src/core/client/stream/test/comments/showConversation.spec.tsx b/src/core/client/stream/test/comments/showConversation.spec.tsx index f9fb2f13e..aa8a4d907 100644 --- a/src/core/client/stream/test/comments/showConversation.spec.tsx +++ b/src/core/client/stream/test/comments/showConversation.spec.tsx @@ -4,16 +4,16 @@ import sinon from "sinon"; import { timeout } from "talk-common/utils"; import { createSinonStub } from "talk-framework/testHelpers"; -import { assetWithDeepestReplies, comments, settings } from "../fixtures"; +import { comments, settings, storyWithDeepestReplies } from "../fixtures"; import create from "./create"; let testRenderer: ReactTestRenderer; beforeEach(() => { const resolvers = { Query: { - asset: createSinonStub( + story: createSinonStub( s => s.throws(), - s => s.returns(assetWithDeepestReplies) + s => s.returns(storyWithDeepestReplies) ), comment: createSinonStub( s => s.throws(), @@ -34,7 +34,7 @@ beforeEach(() => { logNetwork: false, resolvers, initLocalState: localRecord => { - localRecord.setValue(assetWithDeepestReplies.id, "assetID"); + localRecord.setValue(storyWithDeepestReplies.id, "storyID"); }, })); }); diff --git a/src/core/client/stream/test/fixtures.ts b/src/core/client/stream/test/fixtures.ts index dbaf708b3..ba1910a22 100644 --- a/src/core/client/stream/test/fixtures.ts +++ b/src/core/client/stream/test/fixtures.ts @@ -1,8 +1,8 @@ import { - denormalizeAsset, - denormalizeAssets, denormalizeComment, denormalizeComments, + denormalizeStories, + denormalizeStory, } from "talk-framework/testHelpers"; export const settings = { @@ -214,7 +214,7 @@ export const commentWithDeepestReplies = denormalizeComment({ }, }); -export const baseAsset = { +export const baseStory = { isClosed: false, comments: { edges: [], @@ -227,11 +227,11 @@ export const baseAsset = { }, }; -export const assets = denormalizeAssets([ +export const stories = denormalizeStories([ { - ...baseAsset, - id: "asset-1", - url: "http://localhost/assets/asset-1", + ...baseStory, + id: "story-1", + url: "http://localhost/stories/story-1", comments: { edges: [ { node: comments[0], cursor: comments[0].createdAt }, @@ -243,9 +243,9 @@ export const assets = denormalizeAssets([ }, }, { - ...baseAsset, - id: "asset-2", - url: "http://localhost/assets/asset-2", + ...baseStory, + id: "story-2", + url: "http://localhost/stories/story-2", comments: { edges: [ { node: comments[2], cursor: comments[2].createdAt }, @@ -258,10 +258,10 @@ export const assets = denormalizeAssets([ }, ]); -export const assetWithReplies = denormalizeAsset({ - ...baseAsset, - id: "asset-with-replies", - url: "http://localhost/assets/asset-with-replies", +export const storyWithReplies = denormalizeStory({ + ...baseStory, + id: "story-with-replies", + url: "http://localhost/stories/story-with-replies", comments: { edges: [ { node: comments[0], cursor: comments[0].createdAt }, @@ -273,10 +273,10 @@ export const assetWithReplies = denormalizeAsset({ }, }); -export const assetWithDeepReplies = denormalizeAsset({ - ...baseAsset, - id: "asset-with-deep-replies", - url: "http://localhost/assets/asset-with-replies", +export const storyWithDeepReplies = denormalizeStory({ + ...baseStory, + id: "story-with-deep-replies", + url: "http://localhost/stories/story-with-replies", comments: { edges: [ { node: comments[0], cursor: comments[0].createdAt }, @@ -291,10 +291,10 @@ export const assetWithDeepReplies = denormalizeAsset({ }, }); -export const assetWithDeepestReplies = denormalizeAsset({ - ...baseAsset, - id: "asset-with-deepest-replies", - url: "http://localhost/assets/asset-with-replies", +export const storyWithDeepestReplies = denormalizeStory({ + ...baseStory, + id: "story-with-deepest-replies", + url: "http://localhost/stories/story-with-replies", comments: { edges: [ { @@ -314,11 +314,11 @@ export const meWithComments = { comments: { edges: [ { - node: { ...assets[0].comments.edges[0].node, asset: assets[0] }, + node: { ...stories[0].comments.edges[0].node, story: stories[0] }, cursor: comments[0].createdAt, }, { - node: { ...assets[1].comments.edges[0].node, asset: assets[1] }, + node: { ...stories[1].comments.edges[0].node, story: stories[1] }, cursor: comments[1].createdAt, }, ], diff --git a/src/core/client/stream/test/profile/__snapshots__/loadMore.spec.tsx.snap b/src/core/client/stream/test/profile/__snapshots__/loadMore.spec.tsx.snap index 59976be4e..392adb7fa 100644 --- a/src/core/client/stream/test/profile/__snapshots__/loadMore.spec.tsx.snap +++ b/src/core/client/stream/test/profile/__snapshots__/loadMore.spec.tsx.snap @@ -141,7 +141,7 @@ exports[`loads more comments 1`] = ` > { s.withArgs({ first: 5, orderBy: "CREATED_AT_DESC" }).returns({ edges: [ { - node: { ...comments[0], asset: assets[0] }, + node: { ...comments[0], story: stories[0] }, cursor: comments[0].createdAt, }, { - node: { ...comments[1], asset: assets[0] }, + node: { ...comments[1], story: stories[0] }, cursor: comments[1].createdAt, }, ], @@ -40,7 +40,7 @@ beforeEach(() => { .returns({ edges: [ { - node: { ...comments[2], asset: assets[0] }, + node: { ...comments[2], story: stories[0] }, cursor: comments[2].createdAt, }, ], @@ -54,12 +54,12 @@ beforeEach(() => { const resolvers = { Query: { - asset: createSinonStub( + story: createSinonStub( s => s.throws(), s => s - .withArgs(undefined, { id: assets[0].id, url: null }) - .returns(assets[0]) + .withArgs(undefined, { id: stories[0].id, url: null }) + .returns(stories[0]) ), me: sinon.stub().returns(meStub), }, @@ -70,7 +70,7 @@ beforeEach(() => { logNetwork: false, resolvers, initLocalState: localRecord => { - localRecord.setValue(assets[0].id, "assetID"); + localRecord.setValue(stories[0].id, "storyID"); }, })); }); diff --git a/src/core/client/stream/test/profile/renderProfile.spec.tsx b/src/core/client/stream/test/profile/renderProfile.spec.tsx index 519febb13..c3395a2f9 100644 --- a/src/core/client/stream/test/profile/renderProfile.spec.tsx +++ b/src/core/client/stream/test/profile/renderProfile.spec.tsx @@ -4,19 +4,19 @@ import sinon from "sinon"; import { timeout } from "talk-common/utils"; import { createSinonStub } from "talk-framework/testHelpers"; -import { assets, meWithComments } from "../fixtures"; +import { meWithComments, stories } from "../fixtures"; import create from "./create"; let testRenderer: ReactTestRenderer; beforeEach(() => { const resolvers = { Query: { - asset: createSinonStub( + story: createSinonStub( s => s.throws(), s => s - .withArgs(undefined, { id: assets[0].id, url: null }) - .returns(assets[0]) + .withArgs(undefined, { id: stories[0].id, url: null }) + .returns(stories[0]) ), me: sinon.stub().returns(meWithComments), }, @@ -27,7 +27,7 @@ beforeEach(() => { logNetwork: false, resolvers, initLocalState: localRecord => { - localRecord.setValue(assets[0].id, "assetID"); + localRecord.setValue(stories[0].id, "storyID"); }, })); }); diff --git a/src/core/server/graph/tenant/loaders/assets.ts b/src/core/server/graph/tenant/loaders/assets.ts deleted file mode 100644 index aa20c8aed..000000000 --- a/src/core/server/graph/tenant/loaders/assets.ts +++ /dev/null @@ -1,17 +0,0 @@ -import DataLoader from "dataloader"; - -import TenantContext from "talk-server/graph/tenant/context"; -import { - Asset, - FindOrCreateAssetInput, - retrieveManyAssets, -} from "talk-server/models/asset"; -import { findOrCreate } from "talk-server/services/assets"; - -export default (ctx: TenantContext) => ({ - findOrCreate: (input: FindOrCreateAssetInput) => - findOrCreate(ctx.mongo, ctx.tenant, input, ctx.queue.scraper), - asset: new DataLoader(ids => - retrieveManyAssets(ctx.mongo, ctx.tenant.id, ids) - ), -}); diff --git a/src/core/server/graph/tenant/loaders/comments.ts b/src/core/server/graph/tenant/loaders/comments.ts index cef69f6ac..61339bcb8 100644 --- a/src/core/server/graph/tenant/loaders/comments.ts +++ b/src/core/server/graph/tenant/loaders/comments.ts @@ -2,11 +2,11 @@ import DataLoader from "dataloader"; import Context from "talk-server/graph/tenant/context"; import { - AssetToCommentsArgs, CommentToParentsArgs, CommentToRepliesArgs, GQLActionPresence, GQLCOMMENT_SORT, + StoryToCommentsArgs, } from "talk-server/graph/tenant/schema/__generated__/types"; import { ACTION_ITEM_TYPE, @@ -14,9 +14,9 @@ import { } from "talk-server/models/action"; import { Comment, - retrieveCommentAssetConnection, retrieveCommentParentsConnection, retrieveCommentRepliesConnection, + retrieveCommentStoryConnection, retrieveCommentUserConnection, retrieveManyComments, } from "talk-server/models/comment"; @@ -61,29 +61,29 @@ export default (ctx: Context) => ({ first = 10, orderBy = GQLCOMMENT_SORT.CREATED_AT_DESC, after, - }: AssetToCommentsArgs + }: StoryToCommentsArgs ) => retrieveCommentUserConnection(ctx.mongo, ctx.tenant.id, userID, { first, orderBy, after, }), - forAsset: ( - assetID: string, + forStory: ( + storyID: string, // Apply the graph schema defaults at the loader. { first = 10, orderBy = GQLCOMMENT_SORT.CREATED_AT_DESC, after, - }: AssetToCommentsArgs + }: StoryToCommentsArgs ) => - retrieveCommentAssetConnection(ctx.mongo, ctx.tenant.id, assetID, { + retrieveCommentStoryConnection(ctx.mongo, ctx.tenant.id, storyID, { first, orderBy, after, }).then(primeCommentsFromConnection(ctx)), forParent: ( - assetID: string, + storyID: string, parentID: string, // Apply the graph schema defaults at the loader. { @@ -95,7 +95,7 @@ export default (ctx: Context) => ({ retrieveCommentRepliesConnection( ctx.mongo, ctx.tenant.id, - assetID, + storyID, parentID, { first, diff --git a/src/core/server/graph/tenant/loaders/index.ts b/src/core/server/graph/tenant/loaders/index.ts index d4a00cc28..2c00687b3 100644 --- a/src/core/server/graph/tenant/loaders/index.ts +++ b/src/core/server/graph/tenant/loaders/index.ts @@ -1,10 +1,10 @@ import Context from "talk-server/graph/tenant/context"; -import Assets from "./assets"; import Comments from "./comments"; +import Stories from "./stories"; import Users from "./users"; export default (ctx: Context) => ({ - Assets: Assets(ctx), + Stories: Stories(ctx), Comments: Comments(ctx), Users: Users(ctx), }); diff --git a/src/core/server/graph/tenant/loaders/stories.ts b/src/core/server/graph/tenant/loaders/stories.ts new file mode 100644 index 000000000..057eee7d6 --- /dev/null +++ b/src/core/server/graph/tenant/loaders/stories.ts @@ -0,0 +1,17 @@ +import DataLoader from "dataloader"; + +import TenantContext from "talk-server/graph/tenant/context"; +import { + FindOrCreateStoryInput, + retrieveManyStories, + Story, +} from "talk-server/models/story"; +import { findOrCreate } from "talk-server/services/stories"; + +export default (ctx: TenantContext) => ({ + findOrCreate: (input: FindOrCreateStoryInput) => + findOrCreate(ctx.mongo, ctx.tenant, input, ctx.queue.scraper), + story: new DataLoader(ids => + retrieveManyStories(ctx.mongo, ctx.tenant.id, ids) + ), +}); diff --git a/src/core/server/graph/tenant/mutators/comment.ts b/src/core/server/graph/tenant/mutators/comment.ts index 01c734185..6d092fe4c 100644 --- a/src/core/server/graph/tenant/mutators/comment.ts +++ b/src/core/server/graph/tenant/mutators/comment.ts @@ -27,7 +27,7 @@ export default (ctx: TenantContext) => ({ ctx.user!, { author_id: ctx.user!.id, - asset_id: input.assetID, + story_id: input.storyID, body: input.body, parent_id: input.parentID, }, diff --git a/src/core/server/graph/tenant/resolvers/asset.ts b/src/core/server/graph/tenant/resolvers/asset.ts deleted file mode 100644 index b017c992e..000000000 --- a/src/core/server/graph/tenant/resolvers/asset.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { GQLAssetTypeResolver } from "talk-server/graph/tenant/schema/__generated__/types"; -import { decodeActionCounts } from "talk-server/models/action"; -import { Asset } from "talk-server/models/asset"; - -const Asset: GQLAssetTypeResolver = { - comments: (asset, input, ctx) => - ctx.loaders.Comments.forAsset(asset.id, input), - // TODO: implement this. - isClosed: () => false, - actionCounts: asset => decodeActionCounts(asset.action_counts), - commentCounts: asset => asset.comment_counts, -}; - -export default Asset; diff --git a/src/core/server/graph/tenant/resolvers/comment.ts b/src/core/server/graph/tenant/resolvers/comment.ts index c7179ac4e..d9b2717cd 100644 --- a/src/core/server/graph/tenant/resolvers/comment.ts +++ b/src/core/server/graph/tenant/resolvers/comment.ts @@ -23,7 +23,7 @@ const Comment: GQLCommentTypeResolver = { ctx.loaders.Users.user.load(comment.author_id), replies: (comment, input, ctx) => comment.reply_count > 0 - ? ctx.loaders.Comments.forParent(comment.asset_id, comment.id, input) + ? ctx.loaders.Comments.forParent(comment.story_id, comment.id, input) : createConnection(), actionCounts: comment => decodeActionCounts(comment.action_counts), myActionPresence: (comment, input, ctx) => @@ -84,8 +84,8 @@ const Comment: GQLCommentTypeResolver = { comment.parent_id ? ctx.loaders.Comments.parents(comment, input) : createConnection(), - asset: (comment, input, ctx) => - ctx.loaders.Assets.asset.load(comment.asset_id), + story: (comment, input, ctx) => + ctx.loaders.Stories.story.load(comment.story_id), }; export default Comment; diff --git a/src/core/server/graph/tenant/resolvers/comment_counts.ts b/src/core/server/graph/tenant/resolvers/comment_counts.ts index b88a54c3b..2a643bb9c 100644 --- a/src/core/server/graph/tenant/resolvers/comment_counts.ts +++ b/src/core/server/graph/tenant/resolvers/comment_counts.ts @@ -2,7 +2,7 @@ import { GQLCOMMENT_STATUS, GQLCommentCountsTypeResolver, } from "talk-server/graph/tenant/schema/__generated__/types"; -import { CommentStatusCounts } from "talk-server/models/asset"; +import { CommentStatusCounts } from "talk-server/models/story"; const CommentCounts: GQLCommentCountsTypeResolver = { totalVisible: commentCounts => diff --git a/src/core/server/graph/tenant/resolvers/index.ts b/src/core/server/graph/tenant/resolvers/index.ts index 999760912..f4a0417a2 100644 --- a/src/core/server/graph/tenant/resolvers/index.ts +++ b/src/core/server/graph/tenant/resolvers/index.ts @@ -1,17 +1,16 @@ import Cursor from "talk-server/graph/common/scalars/cursor"; import { GQLResolver } from "talk-server/graph/tenant/schema/__generated__/types"; -import Asset from "./asset"; import AuthIntegrations from "./auth_integrations"; import Comment from "./comment"; import CommentCounts from "./comment_counts"; import Mutation from "./mutation"; import Profile from "./profile"; import Query from "./query"; +import Story from "./story"; import User from "./user"; const Resolvers: GQLResolver = { - Asset, AuthIntegrations, Comment, CommentCounts, @@ -19,6 +18,7 @@ const Resolvers: GQLResolver = { Mutation, Profile, Query, + Story, User, }; diff --git a/src/core/server/graph/tenant/resolvers/query.ts b/src/core/server/graph/tenant/resolvers/query.ts index 295b6c459..6fba12b65 100644 --- a/src/core/server/graph/tenant/resolvers/query.ts +++ b/src/core/server/graph/tenant/resolvers/query.ts @@ -1,7 +1,7 @@ import { GQLQueryTypeResolver } from "talk-server/graph/tenant/schema/__generated__/types"; const Query: GQLQueryTypeResolver = { - asset: (source, args, ctx) => ctx.loaders.Assets.findOrCreate(args), + story: (source, args, ctx) => ctx.loaders.Stories.findOrCreate(args), comment: (source, { id }, ctx) => id ? ctx.loaders.Comments.comment.load(id) : null, settings: (source, args, ctx) => ctx.tenant, diff --git a/src/core/server/graph/tenant/resolvers/story.ts b/src/core/server/graph/tenant/resolvers/story.ts new file mode 100644 index 000000000..aeb5d2304 --- /dev/null +++ b/src/core/server/graph/tenant/resolvers/story.ts @@ -0,0 +1,14 @@ +import { GQLStoryTypeResolver } from "talk-server/graph/tenant/schema/__generated__/types"; +import { decodeActionCounts } from "talk-server/models/action"; +import { Story } from "talk-server/models/story"; + +const Story: GQLStoryTypeResolver = { + comments: (story, input, ctx) => + ctx.loaders.Comments.forStory(story.id, input), + // TODO: implement this. + isClosed: () => false, + actionCounts: story => decodeActionCounts(story.action_counts), + commentCounts: story => story.comment_counts, +}; + +export default Story; diff --git a/src/core/server/graph/tenant/schema/schema.graphql b/src/core/server/graph/tenant/schema/schema.graphql index 5bea357e0..fe3fefa8b 100644 --- a/src/core/server/graph/tenant/schema/schema.graphql +++ b/src/core/server/graph/tenant/schema/schema.graphql @@ -544,7 +544,7 @@ type Settings { domains: [String!] @auth(roles: [ADMIN]) """ - moderation is the moderation mode for all Asset's on the site. + moderation is the moderation mode for all Stories on the site. """ moderation: MODERATION_MODE @auth(roles: [ADMIN]) @@ -598,12 +598,12 @@ type Settings { """ closedTimeout is the amount of seconds from the created_at timestamp that a - given asset will be considered closed. + given story will be considered closed. """ closedTimeout: Int! """ - closedMessage is the message shown to the user when the given Asset is + closedMessage is the message shown to the user when the given Story is closed. """ closedMessage: String @@ -806,7 +806,7 @@ enum COMMENT_STATUS { REJECTED """ - The comment was created while the asset's premoderation option was on, and + The comment was created while the stories premoderation option was on, and new comments that haven't been moderated yet are referred to as "premoderated" or "premod" comments. """ @@ -820,7 +820,7 @@ enum COMMENT_STATUS { } """ -Comment is a comment left by a User on an Asset or another Comment as a reply. +Comment is a comment left by a User on an Story or another Comment as a reply. """ type Comment { """ @@ -881,7 +881,7 @@ type Comment { """ rootParent is the highest level parent Comment. This Comment would have been - left on the Asset itself. + left on the Story itself. """ rootParent: Comment @@ -908,9 +908,9 @@ type Comment { myActionPresence: ActionPresence """ - asset is the Asset that the Comment was written on. + story is the Story that the Comment was written on. """ - asset: Asset! + story: Story! } type PageInfo { @@ -987,7 +987,7 @@ type CommentStatusCounts { REJECTED: Int! """ - The comment was created while the asset's premoderation option was on, and + The comment was created while the stories premoderation option was on, and new comments that haven't been moderated yet are referred to as "premoderated" or "premod" comments. """ @@ -1010,7 +1010,7 @@ type CommentCounts { } ################################################################################ -## Asset +## Story ################################################################################ enum COMMENT_SORT { @@ -1021,26 +1021,26 @@ enum COMMENT_SORT { } """ -Asset is an Article or Page where Comments are written on by Users. +Story is an Article or Page where Comments are written on by Users. """ -type Asset { +type Story { """ - id is the identifier of the Asset. + id is the identifier of the Story. """ id: ID! """ - url is the url that the Asset is located on. + url is the url that the Story is located on. """ url: String! """ - title is the title of the scraped Asset. + title is the title of the scraped Story. """ title: String """ - comments are the comments on the Asset. + comments are the comments on the Story. """ comments( first: Int = 10 @@ -1049,23 +1049,23 @@ type Asset { ): CommentsConnection! """ - actionCounts stores the counts of all the actions against this Asset and it's + actionCounts stores the counts of all the actions against this Story and it's Comments. """ actionCounts: ActionCounts! @auth(roles: [ADMIN, MODERATOR]) """ - author is the authors listed in the meta tags for the Asset. + author is the authors listed in the meta tags for the Story. """ author: String """ - closedAt is the Time that the Asset is closed for commenting. + closedAt is the Time that the Story is closed for commenting. """ closedAt: Time """ - isClosed returns true when the Asset is currently closed for commenting. + isClosed returns true when the Story is currently closed for commenting. """ isClosed: Boolean! @@ -1075,19 +1075,19 @@ type Asset { commentCounts: CommentCounts! """ - createdAt is the date that the Asset was created at. + createdAt is the date that the Story was created at. """ createdAt: Time! } """ -AssetEdge represents a unique Asset in a AssetConnection. +StoryEdge represents a unique Story in a StoryConnection. """ -type AssetEdge { +type StoryEdge { """ - node is the Asset for this edge. + node is the Story for this edge. """ - node: Asset! + node: Story! """ @@ -1096,13 +1096,13 @@ type AssetEdge { } """ -AssetsConnection represents a subset of a Asset list. +StoriesConnection represents a subset of a Story list. """ -type AssetsConnection { +type StoriesConnection { """ - edges are a subset of AssetEdge's. + edges are a subset of StoryEdge's. """ - edges: [AssetEdge!]! + edges: [StoryEdge!]! """ pageInfo is @@ -1121,9 +1121,9 @@ type Query { comment(id: ID!): Comment """ - asset is the Asset specified by its ID/URL. + story is the Story specified by its ID/URL. """ - asset(id: ID, url: String): Asset + story(id: ID, url: String): Story """ me is the current logged in User. @@ -1149,9 +1149,9 @@ CreateCommentInput provides the input for the createComment Mutation. """ input CreateCommentInput { """ - assetID is the ID of the Asset where we are creating a comment on. + storyID is the ID of the Story where we are creating a comment on. """ - assetID: ID! + storyID: ID! """ parentID is the optional ID of the Comment that we are replying to. @@ -1449,7 +1449,7 @@ input SettingsInput { domains: [String!] """ - moderation is the moderation mode for all Asset's on the site. + moderation is the moderation mode for all Stories on the site. """ moderation: MODERATION_MODE @@ -1503,12 +1503,12 @@ input SettingsInput { """ closedTimeout is the amount of seconds from the created_at timestamp that a - given asset will be considered closed. + given story will be considered closed. """ closedTimeout: Int """ - closedMessage is the message shown to the user when the given Asset is + closedMessage is the message shown to the user when the given Story is closed. """ closedMessage: String @@ -1851,5 +1851,5 @@ type Mutation { ################################################################################ type Subscription { - commentCreated(assetID: ID!): Comment + commentCreated(storyID: ID!): Comment } diff --git a/src/core/server/models/comment.ts b/src/core/server/models/comment.ts index 82ff21beb..02a7ae8a6 100644 --- a/src/core/server/models/comment.ts +++ b/src/core/server/models/comment.ts @@ -38,7 +38,7 @@ export interface Comment extends TenantResource { readonly id: string; parent_id?: string; author_id: string; - asset_id: string; + story_id: string; body: string; body_history: BodyHistoryItem[]; status: GQLCOMMENT_STATUS; @@ -288,14 +288,14 @@ function cursorGetterFactory( export async function retrieveCommentRepliesConnection( db: Db, tenantID: string, - assetID: string, + storyID: string, parentID: string, input: ConnectionInput ) { // Create the query. const query = new Query(collection(db)).where({ tenant_id: tenantID, - asset_id: assetID, + story_id: storyID, parent_id: parentID, }); @@ -400,23 +400,23 @@ export async function retrieveCommentParentsConnection( } /** - * retrieveAssetConnection returns a Connection for a given Asset's + * retrieveStoryConnection returns a Connection for a given Stories * comments. * * @param db database connection - * @param assetID the Asset id for the comment to retrieve + * @param storyID the Story id for the comment to retrieve * @param input connection configuration */ -export async function retrieveCommentAssetConnection( +export async function retrieveCommentStoryConnection( db: Db, tenantID: string, - assetID: string, + storyID: string, input: ConnectionInput ) { // Create the query. const query = new Query(collection(db)).where({ tenant_id: tenantID, - asset_id: assetID, + story_id: storyID, parent_id: null, }); diff --git a/src/core/server/models/asset.ts b/src/core/server/models/story.ts similarity index 72% rename from src/core/server/models/asset.ts rename to src/core/server/models/story.ts index 8c5dc4856..f3a59552d 100644 --- a/src/core/server/models/asset.ts +++ b/src/core/server/models/story.ts @@ -9,7 +9,7 @@ import { ModerationSettings } from "talk-server/models/settings"; import { TenantResource } from "talk-server/models/tenant"; function collection(db: Db) { - return db.collection>("assets"); + return db.collection>("stories"); } // TODO: (wyattjoh) write a test to verify that this set of counts is always in sync with GQLCOMMENT_STATUS. @@ -21,7 +21,7 @@ export interface CommentStatusCounts { [GQLCOMMENT_STATUS.SYSTEM_WITHHELD]: number; } -export interface Asset extends TenantResource { +export interface Story extends TenantResource { readonly id: string; url: string; scraped?: Date; @@ -39,40 +39,40 @@ export interface Asset extends TenantResource { publication_date?: Date; /** - * action_counts stores all the action counts for all Comment's on this Asset. + * action_counts stores all the action counts for all Comment's on this Story. */ action_counts: EncodedActionCounts; /** - * comment_counts stores the different counts for each comment on the Asset + * comment_counts stores the different counts for each comment on the Story * according to their statuses. */ comment_counts: CommentStatusCounts; /** * settings provides a point where the settings can be overridden for a - * specific Asset. + * specific Story. */ settings?: Partial; } -export interface UpsertAssetInput { +export interface UpsertStoryInput { id?: string; url: string; } -export async function upsertAsset( +export async function upsertStory( db: Db, tenantID: string, - { id, url }: UpsertAssetInput + { id, url }: UpsertStoryInput ) { const now = new Date(); - // TODO: verify that the url for the given Asset is whitelisted by the tenant. + // TODO: verify that the url for the given Story is whitelisted by the tenant. - // Create the asset, optionally sourcing the id from the input, additionally + // Create the story, optionally sourcing the id from the input, additionally // porting in the tenant_id. - const update: { $setOnInsert: Asset } = { + const update: { $setOnInsert: Story } = { $setOnInsert: { id: id ? id : uuid.v4(), url, @@ -84,8 +84,8 @@ export async function upsertAsset( }; // Perform the find and update operation to try and find and or create the - // asset. - const { value: asset } = await collection(db).findOneAndUpdate( + // story. + const { value: story } = await collection(db).findOneAndUpdate( { url, tenant_id: tenantID, @@ -100,26 +100,26 @@ export async function upsertAsset( returnOriginal: false, } ); - if (!asset) { + if (!story) { return null; } - if (!asset.scraped) { - // TODO: create scrape job to collect asset metadata + if (!story.scraped) { + // TODO: create scrape job to collect story metadata } - return asset; + return story; } /** * updateCommentStatusCount increments the number of status counts for the - * given Asset ID. + * given Story ID. * * @param mongo the database handle - * @param tenantID the tenant that the Asset is on. - * @param id the ID of the Asset. + * @param tenantID the tenant that the Story is on. + * @param id the ID of the Story. * @param commentStatusCounts the update document that contains a positive or - * negative number of comments to increment on the given Asset. + * negative number of comments to increment on the given Story. */ export async function updateCommentStatusCount( mongo: Db, @@ -127,7 +127,7 @@ export async function updateCommentStatusCount( id: string, commentStatusCounts: Partial ) { - const { value: asset } = await collection(mongo).findOneAndUpdate( + const { value: story } = await collection(mongo).findOneAndUpdate( { id, tenant_id: tenantID, @@ -140,7 +140,7 @@ export async function updateCommentStatusCount( { returnOriginal: false } ); - return asset; + return story; } function createEmptyCommentCounts(): CommentStatusCounts { @@ -153,39 +153,39 @@ function createEmptyCommentCounts(): CommentStatusCounts { }; } -export interface FindOrCreateAssetInput { +export interface FindOrCreateStoryInput { id?: string; url?: string; } -export async function findOrCreateAsset( +export async function findOrCreateStory( db: Db, tenantID: string, - { id, url }: FindOrCreateAssetInput + { id, url }: FindOrCreateStoryInput ) { if (id) { if (url) { // The URL was specified, this is an upsert operation. - return upsertAsset(db, tenantID, { + return upsertStory(db, tenantID, { id, url, }); } // The URL was not specified, this is a lookup operation. - return retrieveAsset(db, tenantID, id); + return retrieveStory(db, tenantID, id); } // The ID was not specified, this is an upsert operation. Check to see that // the URL exists. if (!url) { - throw new Error("cannot upsert an asset without the url"); + throw new Error("cannot upsert an story without the url"); } - return upsertAsset(db, tenantID, { url }); + return upsertStory(db, tenantID, { url }); } -export async function retrieveAssetByURL( +export async function retrieveStoryByURL( db: Db, tenantID: string, url: string @@ -193,11 +193,11 @@ export async function retrieveAssetByURL( return collection(db).findOne({ url, tenant_id: tenantID }); } -export async function retrieveAsset(db: Db, tenantID: string, id: string) { +export async function retrieveStory(db: Db, tenantID: string, id: string) { return collection(db).findOne({ id, tenant_id: tenantID }); } -export async function retrieveManyAssets( +export async function retrieveManyStories( db: Db, tenantID: string, ids: string[] @@ -207,12 +207,12 @@ export async function retrieveManyAssets( tenant_id: tenantID, }); - const assets = await cursor.toArray(); + const stories = await cursor.toArray(); - return ids.map(id => assets.find(asset => asset.id === id) || null); + return ids.map(id => stories.find(story => story.id === id) || null); } -export async function retrieveManyAssetsByURL( +export async function retrieveManyStoriesByURL( db: Db, tenantID: string, urls: string[] @@ -222,21 +222,21 @@ export async function retrieveManyAssetsByURL( tenant_id: tenantID, }); - const assets = await cursor.toArray(); + const stories = await cursor.toArray(); - return urls.map(url => assets.find(asset => asset.url === url) || null); + return urls.map(url => stories.find(story => story.url === url) || null); } -export type UpdateAssetInput = Omit< - Partial, +export type UpdateStoryInput = Omit< + Partial, "id" | "tenant_id" | "url" | "created_at" >; -export async function updateAsset( +export async function updateStory( db: Db, tenantID: string, id: string, - input: UpdateAssetInput + input: UpdateStoryInput ) { // Only update fields that have been updated. const update = { @@ -259,15 +259,15 @@ export async function updateAsset( } /** - * updateAssetActionCounts will update the given comment's action counts on - * the Asset. + * updateStoryActionCounts will update the given comment's action counts on + * the Story. * * @param mongo the database handle * @param tenantID the id of the Tenant - * @param id the id of the Asset being updated - * @param actionCounts the action counts to merge into the Asset + * @param id the id of the Story being updated + * @param actionCounts the action counts to merge into the Story */ -export async function updateAssetActionCounts( +export async function updateStoryActionCounts( mongo: Db, tenantID: string, id: string, diff --git a/src/core/server/models/tenant.ts b/src/core/server/models/tenant.ts index 3030e3cdd..aed12243d 100644 --- a/src/core/server/models/tenant.ts +++ b/src/core/server/models/tenant.ts @@ -15,7 +15,7 @@ export interface TenantResource { } /** - * Tenant describes a given Tenant on Talk that has Assets, Comments, and Users. + * Tenant describes a given Tenant on Talk that has Stories, Comments, and Users. */ export interface Tenant extends Settings { readonly id: string; diff --git a/src/core/server/services/comments/actions.ts b/src/core/server/services/comments/actions.ts index e788757c9..f152d1b10 100644 --- a/src/core/server/services/comments/actions.ts +++ b/src/core/server/services/comments/actions.ts @@ -11,12 +11,12 @@ import { encodeActionCounts, invertEncodedActionCounts, } from "talk-server/models/action"; -import { updateAssetActionCounts } from "talk-server/models/asset"; import { retrieveComment, updateCommentActionCounts, } from "talk-server/models/comment"; import { Comment } from "talk-server/models/comment"; +import { updateStoryActionCounts } from "talk-server/models/story"; import { Tenant } from "talk-server/models/tenant"; import { User } from "talk-server/models/user"; @@ -47,11 +47,11 @@ export async function addCommentActions( actionCounts ); - // Update the Asset with the updated action counts. - await updateAssetActionCounts( + // Update the Story with the updated action counts. + await updateStoryActionCounts( mongo, tenant.id, - comment.asset_id, + comment.story_id, actionCounts ); @@ -109,11 +109,11 @@ export async function removeCommentAction( actionCounts ); - // Update the Asset with the updated action counts. - await updateAssetActionCounts( + // Update the Story with the updated action counts. + await updateStoryActionCounts( mongo, tenant.id, - comment.asset_id, + comment.story_id, actionCounts ); diff --git a/src/core/server/services/comments/index.ts b/src/core/server/services/comments/index.ts index 82e10c97c..4339f6d73 100644 --- a/src/core/server/services/comments/index.ts +++ b/src/core/server/services/comments/index.ts @@ -2,10 +2,6 @@ import { Db } from "mongodb"; import { Omit } from "talk-common/types"; import { ACTION_ITEM_TYPE, CreateActionInput } from "talk-server/models/action"; -import { - retrieveAsset, - updateCommentStatusCount, -} from "talk-server/models/asset"; import { createComment, CreateCommentInput, @@ -14,6 +10,10 @@ import { pushChildCommentIDOntoParent, retrieveComment, } from "talk-server/models/comment"; +import { + retrieveStory, + updateCommentStatusCount, +} from "talk-server/models/story"; import { Tenant } from "talk-server/models/tenant"; import { User } from "talk-server/models/user"; import { addCommentActions } from "talk-server/services/comments/actions"; @@ -32,14 +32,14 @@ export async function create( input: CreateComment, req?: Request ) { - // Grab the asset that we'll use to check moderation pieces with. - const asset = await retrieveAsset(mongo, tenant.id, input.asset_id); - if (!asset) { + // Grab the story that we'll use to check moderation pieces with. + const story = await retrieveStory(mongo, tenant.id, input.story_id); + if (!story) { // TODO: (wyattjoh) return better error. - throw new Error("asset referenced does not exist"); + throw new Error("story referenced does not exist"); } - // TODO: (wyattjoh) Check that the asset was visible. + // TODO: (wyattjoh) Check that the story was visible. const grandparentIDs: string[] = []; if (input.parent_id) { @@ -62,7 +62,7 @@ export async function create( // Run the comment through the moderation phases. const { actions, status, metadata } = await processForModeration({ - asset, + story, tenant, comment: input, author, @@ -105,8 +105,8 @@ export async function create( ); } - // Increment the status count for the particular status on the Asset. - await updateCommentStatusCount(mongo, tenant.id, asset.id, { + // Increment the status count for the particular status on the Story. + await updateCommentStatusCount(mongo, tenant.id, story.id, { [status]: 1, }); @@ -132,16 +132,16 @@ export async function edit( throw new Error("comment not found"); } - // Grab the asset that we'll use to check moderation pieces with. - const asset = await retrieveAsset(mongo, tenant.id, comment.asset_id); - if (!asset) { + // Grab the story that we'll use to check moderation pieces with. + const story = await retrieveStory(mongo, tenant.id, comment.story_id); + if (!story) { // TODO: (wyattjoh) return better error. - throw new Error("asset referenced does not exist"); + throw new Error("story referenced does not exist"); } // Run the comment through the moderation phases. const { status, metadata, actions } = await processForModeration({ - asset, + story, tenant, comment: input, author, @@ -186,9 +186,9 @@ export async function edit( } if (comment.status !== editedComment.status) { - // Increment the status count for the particular status on the Asset, and + // Increment the status count for the particular status on the Story, and // decrement the status on the comment's previous status. - await updateCommentStatusCount(mongo, tenant.id, asset.id, { + await updateCommentStatusCount(mongo, tenant.id, story.id, { [comment.status]: -1, [editedComment.status]: 1, }); diff --git a/src/core/server/services/comments/moderation/index.ts b/src/core/server/services/comments/moderation/index.ts index 7bf497f75..01c6a8c5a 100644 --- a/src/core/server/services/comments/moderation/index.ts +++ b/src/core/server/services/comments/moderation/index.ts @@ -1,8 +1,8 @@ import { Omit, Promiseable } from "talk-common/types"; import { GQLCOMMENT_STATUS } from "talk-server/graph/tenant/schema/__generated__/types"; import { CreateActionInput } from "talk-server/models/action"; -import { Asset } from "talk-server/models/asset"; import { Comment } from "talk-server/models/comment"; +import { Story } from "talk-server/models/story"; import { Tenant } from "talk-server/models/tenant"; import { User } from "talk-server/models/user"; import { Request } from "talk-server/types/express"; @@ -18,7 +18,7 @@ export interface PhaseResult { } export interface ModerationPhaseContext { - asset: Asset; + story: Story; tenant: Tenant; comment: Partial; author: User; diff --git a/src/core/server/services/comments/moderation/phases/assetClosed.ts b/src/core/server/services/comments/moderation/phases/assetClosed.ts deleted file mode 100644 index 2aec0db0b..000000000 --- a/src/core/server/services/comments/moderation/phases/assetClosed.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { - IntermediateModerationPhase, - IntermediatePhaseResult, -} from "talk-server/services/comments/moderation"; - -// This phase checks to see if the asset being processed is closed or not. -export const assetClosed: IntermediateModerationPhase = ({ - asset, -}): IntermediatePhaseResult | void => { - // Check to see if the asset has closed commenting... - if (asset.closedAt && asset.closedAt.valueOf() <= Date.now()) { - // TODO: (wyattjoh) return better error. - throw new Error("asset is currently closed for commenting"); - } -}; diff --git a/src/core/server/services/comments/moderation/phases/commentLength.ts b/src/core/server/services/comments/moderation/phases/commentLength.ts index 0015c813f..56dfc9269 100644 --- a/src/core/server/services/comments/moderation/phases/commentLength.ts +++ b/src/core/server/services/comments/moderation/phases/commentLength.ts @@ -35,7 +35,7 @@ const testCharCount = ( }; export const commentLength: IntermediateModerationPhase = ({ - asset, + story, tenant, comment, }): IntermediatePhaseResult | void => { @@ -44,7 +44,7 @@ export const commentLength: IntermediateModerationPhase = ({ // Reject if the comment is too long or too short. if ( testCharCount(tenant, length) || - (asset.settings && testCharCount(asset.settings, length)) + (story.settings && testCharCount(story.settings, length)) ) { return { status: GQLCOMMENT_STATUS.REJECTED, diff --git a/src/core/server/services/comments/moderation/phases/commentingDisabled.ts b/src/core/server/services/comments/moderation/phases/commentingDisabled.ts index 07ad21ecb..dc91f813b 100644 --- a/src/core/server/services/comments/moderation/phases/commentingDisabled.ts +++ b/src/core/server/services/comments/moderation/phases/commentingDisabled.ts @@ -8,13 +8,13 @@ const testDisabledCommenting = (settings: Partial) => settings.disableCommenting; export const commentingDisabled: IntermediateModerationPhase = ({ - asset, + story, tenant, }): IntermediatePhaseResult | void => { - // Check to see if the asset has closed commenting. + // Check to see if the story has closed commenting. if ( testDisabledCommenting(tenant) || - (asset.settings && testDisabledCommenting(asset.settings)) + (story.settings && testDisabledCommenting(story.settings)) ) { // TODO: (wyattjoh) return better error. throw new Error("commenting has been disabled tenant wide"); diff --git a/src/core/server/services/comments/moderation/phases/index.ts b/src/core/server/services/comments/moderation/phases/index.ts index a0a724cc6..7617f2736 100644 --- a/src/core/server/services/comments/moderation/phases/index.ts +++ b/src/core/server/services/comments/moderation/phases/index.ts @@ -2,13 +2,13 @@ import { IntermediateModerationPhase } from "talk-server/services/comments/moder import { premod } from "talk-server/services/comments/moderation/phases/premod"; import { toxic } from "talk-server/services/comments/moderation/phases/toxic"; -import { assetClosed } from "./assetClosed"; import { commentingDisabled } from "./commentingDisabled"; import { commentLength } from "./commentLength"; import { karma } from "./karma"; import { links } from "./links"; import { spam } from "./spam"; import { staff } from "./staff"; +import { storyClosed } from "./storyClosed"; import { wordlist } from "./wordlist"; /** @@ -16,7 +16,7 @@ import { wordlist } from "./wordlist"; */ export const moderationPhases: IntermediateModerationPhase[] = [ commentLength, - assetClosed, + storyClosed, commentingDisabled, wordlist, staff, diff --git a/src/core/server/services/comments/moderation/phases/links.ts b/src/core/server/services/comments/moderation/phases/links.ts index ae2c0e723..2388f2ea7 100755 --- a/src/core/server/services/comments/moderation/phases/links.ts +++ b/src/core/server/services/comments/moderation/phases/links.ts @@ -25,14 +25,14 @@ const testPremodLinksEnable = ( // This phase checks the comment if it has any links in it if the check is // enabled. export const links: IntermediateModerationPhase = ({ - asset, + story, tenant, comment, }): IntermediatePhaseResult | void => { if ( comment.body && (testPremodLinksEnable(tenant, comment.body) || - (asset.settings && testPremodLinksEnable(asset.settings, comment.body))) + (story.settings && testPremodLinksEnable(story.settings, comment.body))) ) { // Add the flag related to Trust to the comment. return { diff --git a/src/core/server/services/comments/moderation/phases/premod.ts b/src/core/server/services/comments/moderation/phases/premod.ts index 7ccdcfb73..504bd235b 100755 --- a/src/core/server/services/comments/moderation/phases/premod.ts +++ b/src/core/server/services/comments/moderation/phases/premod.ts @@ -14,16 +14,16 @@ const testModerationMode = (settings: Partial) => // This phase checks to see if the settings have premod enabled, if they do, // the comment is premod, otherwise, it's just none. export const premod: IntermediateModerationPhase = ({ - asset, + story, tenant, }): IntermediatePhaseResult | void => { // If the settings say that we're in premod mode, then the comment is in // premod status. - // TODO: (wyattjoh) pull from the asset settings. + // TODO: (wyattjoh) pull from the story settings. if ( testModerationMode(tenant) || - (asset.settings && testModerationMode(asset.settings)) + (story.settings && testModerationMode(story.settings)) ) { return { status: GQLCOMMENT_STATUS.PREMOD, diff --git a/src/core/server/services/comments/moderation/phases/spam.ts b/src/core/server/services/comments/moderation/phases/spam.ts index 5e3c495a7..d3ee2b008 100644 --- a/src/core/server/services/comments/moderation/phases/spam.ts +++ b/src/core/server/services/comments/moderation/phases/spam.ts @@ -12,7 +12,7 @@ import { } from "talk-server/services/comments/moderation"; export const spam: IntermediateModerationPhase = async ({ - asset, + story, tenant, comment, author, @@ -96,7 +96,7 @@ export const spam: IntermediateModerationPhase = async ({ referrer, // REQUIRED user_agent: userAgent, // REQUIRED comment_content: comment.body, - permalink: asset.url, + permalink: story.url, comment_author: author.displayName || author.username || "", comment_type: "comment", is_test: false, diff --git a/src/core/server/services/comments/moderation/phases/assetClosed.spec.ts b/src/core/server/services/comments/moderation/phases/storyClosed.spec.ts similarity index 57% rename from src/core/server/services/comments/moderation/phases/assetClosed.spec.ts rename to src/core/server/services/comments/moderation/phases/storyClosed.spec.ts index 31d5a1f2f..c562c0318 100644 --- a/src/core/server/services/comments/moderation/phases/assetClosed.spec.ts +++ b/src/core/server/services/comments/moderation/phases/storyClosed.spec.ts @@ -1,16 +1,16 @@ -import { Asset } from "talk-server/models/asset"; import { Comment } from "talk-server/models/comment"; +import { Story } from "talk-server/models/story"; import { Tenant } from "talk-server/models/tenant"; import { User } from "talk-server/models/user"; -import { assetClosed } from "talk-server/services/comments/moderation/phases/assetClosed"; +import { storyClosed } from "talk-server/services/comments/moderation/phases/storyClosed"; -describe("assetClosed", () => { - it("throws an error when the asset is closed", () => { - const asset = { closedAt: new Date() }; +describe("storyClosed", () => { + it("throws an error when the story is closed", () => { + const story = { closedAt: new Date() }; expect(() => - assetClosed({ - asset: asset as Asset, + storyClosed({ + story: story as Story, tenant: (null as any) as Tenant, comment: (null as any) as Comment, author: (null as any) as User, @@ -18,12 +18,12 @@ describe("assetClosed", () => { ).toThrow(); }); - it("does not throw an error when the asset is not closed", () => { + it("does not throw an error when the story is not closed", () => { const now = new Date(); expect( - assetClosed({ - asset: { closedAt: new Date(now.getTime() + 60000) } as Asset, + storyClosed({ + story: { closedAt: new Date(now.getTime() + 60000) } as Story, tenant: (null as any) as Tenant, comment: (null as any) as Comment, author: (null as any) as User, @@ -31,8 +31,8 @@ describe("assetClosed", () => { ).toBeUndefined(); expect( - assetClosed({ - asset: {} as Asset, + storyClosed({ + story: {} as Story, tenant: (null as any) as Tenant, comment: (null as any) as Comment, author: (null as any) as User, diff --git a/src/core/server/services/comments/moderation/phases/storyClosed.ts b/src/core/server/services/comments/moderation/phases/storyClosed.ts new file mode 100644 index 000000000..1b07c8413 --- /dev/null +++ b/src/core/server/services/comments/moderation/phases/storyClosed.ts @@ -0,0 +1,15 @@ +import { + IntermediateModerationPhase, + IntermediatePhaseResult, +} from "talk-server/services/comments/moderation"; + +// This phase checks to see if the story being processed is closed or not. +export const storyClosed: IntermediateModerationPhase = ({ + story, +}): IntermediatePhaseResult | void => { + // Check to see if the story has closed commenting... + if (story.closedAt && story.closedAt.valueOf() <= Date.now()) { + // TODO: (wyattjoh) return better error. + throw new Error("story is currently closed for commenting"); + } +}; diff --git a/src/core/server/services/comments/moderation/phases/wordlist.ts b/src/core/server/services/comments/moderation/phases/wordlist.ts index 05f6431b9..4df8b39e1 100755 --- a/src/core/server/services/comments/moderation/phases/wordlist.ts +++ b/src/core/server/services/comments/moderation/phases/wordlist.ts @@ -19,7 +19,7 @@ export const wordlist: IntermediateModerationPhase = ({ return; } - // Decide the status based on whether or not the current asset/settings + // Decide the status based on whether or not the current story/settings // has pre-mod enabled or not. If the comment was rejected based on the // wordlist, then reject it, otherwise if the moderation setting is // premod, set it to `premod`. diff --git a/src/core/server/services/queue/tasks/scraper/index.ts b/src/core/server/services/queue/tasks/scraper/index.ts index 17c71e3fb..2a12bb86a 100644 --- a/src/core/server/services/queue/tasks/scraper/index.ts +++ b/src/core/server/services/queue/tasks/scraper/index.ts @@ -8,7 +8,7 @@ import titleScraper from "metascraper-title"; import { Db } from "mongodb"; import logger from "talk-server/logger"; -import { updateAsset } from "talk-server/models/asset"; +import { updateStory } from "talk-server/models/story"; import Task from "talk-server/services/queue/Task"; import { modifiedScraper } from "./rules/modified"; import { sectionScraper } from "./rules/section"; @@ -20,8 +20,8 @@ export interface ScrapeProcessorOptions { } export interface ScraperData { - assetID: string; - assetURL: string; + storyID: string; + storyURL: string; tenantID: string; } @@ -30,17 +30,17 @@ const createJobProcessor = ( scraper: Scraper ) => async (job: Job) => { // Pull out the job data. - const { assetID: id, assetURL: url, tenantID } = job.data; + const { storyID: id, storyURL: url, tenantID } = job.data; logger.debug( { job_id: job.id, job_name: JOB_NAME, - asset_id: id, - asset_url: url, + story_id: id, + story_url: url, tenant_id: tenantID, }, - "starting to scrap the asset" + "starting to scrap the story" ); // Get the metadata from the scraped html. @@ -50,17 +50,17 @@ const createJobProcessor = ( { job_id: job.id, job_name: JOB_NAME, - asset_id: id, - asset_url: url, + story_id: id, + story_url: url, tenant_id: tenantID, }, - "asset at specified url not found, can not scrape" + "story at specified url not found, can not scrape" ); return; } - // Update the Asset with the scraped details. - const asset = await updateAsset(options.mongo, tenantID, id, { + // Update the Story with the scraped details. + const story = await updateStory(options.mongo, tenantID, id, { title: meta.title || undefined, description: meta.description || undefined, image: meta.image ? meta.image : undefined, @@ -70,16 +70,16 @@ const createJobProcessor = ( section: meta.section || undefined, scraped: new Date(), }); - if (!asset) { + if (!story) { logger.error( { job_id: job.id, job_name: JOB_NAME, - asset_id: id, - asset_url: url, + story_id: id, + story_url: url, tenant_id: tenantID, }, - "asset at specified id not found, can not update with metadata" + "story at specified id not found, can not update with metadata" ); return; } @@ -88,11 +88,11 @@ const createJobProcessor = ( { job_id: job.id, job_name: JOB_NAME, - asset_id: asset.id, - asset_url: url, + story_id: story.id, + story_url: url, tenant_id: tenantID, }, - "scraped the asset" + "scraped the story" ); }; diff --git a/src/core/server/services/assets/index.ts b/src/core/server/services/stories/index.ts similarity index 50% rename from src/core/server/services/assets/index.ts rename to src/core/server/services/stories/index.ts index 56a3e6119..beec64153 100644 --- a/src/core/server/services/assets/index.ts +++ b/src/core/server/services/stories/index.ts @@ -1,35 +1,35 @@ import { Db } from "mongodb"; import { - findOrCreateAsset, - FindOrCreateAssetInput, -} from "talk-server/models/asset"; + findOrCreateStory, + FindOrCreateStoryInput, +} from "talk-server/models/story"; import { Tenant } from "talk-server/models/tenant"; import Task from "talk-server/services/queue/Task"; import { ScraperData } from "talk-server/services/queue/tasks/scraper"; -export type FindOrCreateAsset = FindOrCreateAssetInput; +export type FindOrCreateStory = FindOrCreateStoryInput; export async function findOrCreate( db: Db, tenant: Tenant, - input: FindOrCreateAsset, + input: FindOrCreateStory, scraper: Task ) { - // TODO: check to see if the tenant has enabled lazy asset creation. + // TODO: check to see if the tenant has enabled lazy story creation. - const asset = await findOrCreateAsset(db, tenant.id, input); - if (!asset) { + const story = await findOrCreateStory(db, tenant.id, input); + if (!story) { return null; } - if (!asset.scraped) { + if (!story.scraped) { await scraper.add({ - assetID: asset.id, - assetURL: asset.url, + storyID: story.id, + storyURL: story.url, tenantID: tenant.id, }); } - return asset; + return story; } diff --git a/src/docs/workarounds.mdx b/src/docs/workarounds.mdx index e9a0b684c..6261034a0 100644 --- a/src/docs/workarounds.mdx +++ b/src/docs/workarounds.mdx @@ -85,7 +85,7 @@ const enhanced = withFragmentContainer<{ data: Data }>({ withLocalStateContainer( graphql` fragment PermalinkViewContainerLocal on Local { - assetURL + storyURL } ` )(PermalinkViewContainer) diff --git a/src/locales/en-US/stream.ftl b/src/locales/en-US/stream.ftl index e007ad0f8..2dd6c4ea3 100644 --- a/src/locales/en-US/stream.ftl +++ b/src/locales/en-US/stream.ftl @@ -21,7 +21,7 @@ general-app-myProfileTab = My Profile ## Comments Tab -comments-streamQuery-assetNotFound = Asset not found +comments-streamQuery-storyNotFound = Story not found comments-postCommentForm-submit = Submit comments-stream-loadMore = Load More @@ -56,7 +56,7 @@ comments-postCommentFormFake-rte = comments-replyButton-reply = Reply -comments-permalinkViewQuery-assetNotFound = { comments-streamQuery-assetNotFound } +comments-permalinkViewQuery-storyNotFound = { comments-streamQuery-storyNotFound } comments-replyCommentForm-submit = Submit comments-replyCommentForm-cancel = Cancel @@ -93,5 +93,5 @@ profile-historyComment-replies = Replies {$replyCount} profile-historyComment-commentHistory = Comment History profile-historyComment-story = Story: {$title} profile-profileQuery-errorLoadingProfile = Error loading profile -profile-profileQuery-assetNotFound = Asset not found +profile-profileQuery-storyNotFound = Story not found profile-commentHistory-loadMore = Load More