From 6b0cefe190da3c9643b06c841880f22f02c9adad Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Fri, 23 Feb 2024 17:14:52 +0800 Subject: [PATCH] add representation column to the highlight table and gql schema which is either CONTENT or FEED_CONTENT --- packages/api/src/entity/highlight.ts | 11 +++++++++++ packages/api/src/generated/graphql.ts | 10 ++++++++++ packages/api/src/generated/schema.graphql | 8 ++++++++ packages/api/src/resolvers/highlight/index.ts | 4 +++- packages/api/src/schema.ts | 8 ++++++++ ...0165.do.rename_preview_content_in_library_item.sql | 3 ++- ...65.undo.rename_preview_content_in_library_item.sql | 4 +++- 7 files changed, 45 insertions(+), 3 deletions(-) diff --git a/packages/api/src/entity/highlight.ts b/packages/api/src/entity/highlight.ts index f34ba69e8..602c9f959 100644 --- a/packages/api/src/entity/highlight.ts +++ b/packages/api/src/entity/highlight.ts @@ -19,6 +19,11 @@ export enum HighlightType { Note = 'NOTE', // to be deleted in favor of note on library item } +export enum RepresentationType { + Content = 'CONTENT', + FeedContent = 'FEED_CONTENT', +} + @Entity({ name: 'highlight' }) export class Highlight { @PrimaryGeneratedColumn('uuid') @@ -87,4 +92,10 @@ export class Highlight { inverseJoinColumn: { name: 'label_id' }, }) labels?: Label[] + + @Column('enum', { + enum: RepresentationType, + default: RepresentationType.Content, + }) + representation!: RepresentationType } diff --git a/packages/api/src/generated/graphql.ts b/packages/api/src/generated/graphql.ts index de12eefd7..028155767 100644 --- a/packages/api/src/generated/graphql.ts +++ b/packages/api/src/generated/graphql.ts @@ -368,6 +368,7 @@ export type CreateHighlightInput = { patch?: InputMaybe; prefix?: InputMaybe; quote?: InputMaybe; + representation?: InputMaybe; sharedAt?: InputMaybe; shortId: Scalars['String']; suffix?: InputMaybe; @@ -1024,6 +1025,7 @@ export type Highlight = { quote?: Maybe; reactions: Array; replies: Array; + representation: RepresentationType; sharedAt?: Maybe; shortId: Scalars['String']; suffix?: Maybe; @@ -1281,6 +1283,7 @@ export type MergeHighlightInput = { patch: Scalars['String']; prefix?: InputMaybe; quote: Scalars['String']; + representation?: InputMaybe; shortId: Scalars['ID']; suffix?: InputMaybe; }; @@ -2178,6 +2181,11 @@ export enum ReportType { Spam = 'SPAM' } +export enum RepresentationType { + Content = 'CONTENT', + FeedContent = 'FEED_CONTENT' +} + export type RevokeApiKeyError = { __typename?: 'RevokeApiKeyError'; errorCodes: Array; @@ -3870,6 +3878,7 @@ export type ResolversTypes = { ReportItemInput: ReportItemInput; ReportItemResult: ResolverTypeWrapper; ReportType: ReportType; + RepresentationType: RepresentationType; RevokeApiKeyError: ResolverTypeWrapper; RevokeApiKeyErrorCode: RevokeApiKeyErrorCode; RevokeApiKeyResult: ResolversTypes['RevokeApiKeyError'] | ResolversTypes['RevokeApiKeySuccess']; @@ -5256,6 +5265,7 @@ export type HighlightResolvers, ParentType, ContextType>; reactions?: Resolver, ParentType, ContextType>; replies?: Resolver, ParentType, ContextType>; + representation?: Resolver; sharedAt?: Resolver, ParentType, ContextType>; shortId?: Resolver; suffix?: Resolver, ParentType, ContextType>; diff --git a/packages/api/src/generated/schema.graphql b/packages/api/src/generated/schema.graphql index e7f5e748a..776a19d59 100644 --- a/packages/api/src/generated/schema.graphql +++ b/packages/api/src/generated/schema.graphql @@ -319,6 +319,7 @@ input CreateHighlightInput { patch: String prefix: String quote: String + representation: RepresentationType sharedAt: Date shortId: String! suffix: String @@ -912,6 +913,7 @@ type Highlight { quote: String reactions: [Reaction!]! replies: [HighlightReply!]! + representation: RepresentationType! sharedAt: Date shortId: String! suffix: String @@ -1148,6 +1150,7 @@ input MergeHighlightInput { patch: String! prefix: String quote: String! + representation: RepresentationType shortId: ID! suffix: String } @@ -1622,6 +1625,11 @@ enum ReportType { SPAM } +enum RepresentationType { + CONTENT + FEED_CONTENT +} + type RevokeApiKeyError { errorCodes: [RevokeApiKeyErrorCode!]! } diff --git a/packages/api/src/resolvers/highlight/index.ts b/packages/api/src/resolvers/highlight/index.ts index 9853ef7e4..e68ac948b 100644 --- a/packages/api/src/resolvers/highlight/index.ts +++ b/packages/api/src/resolvers/highlight/index.ts @@ -5,6 +5,7 @@ import { DeepPartial } from 'typeorm' import { Highlight as HighlightData, HighlightType, + RepresentationType, } from '../../entity/highlight' import { Label } from '../../entity/label' import { env } from '../../env' @@ -34,8 +35,8 @@ import { updateHighlight, } from '../../services/highlights' import { analytics } from '../../utils/analytics' -import { highlightDataToHighlight } from '../../utils/helpers' import { authorized } from '../../utils/gql-utils' +import { highlightDataToHighlight } from '../../utils/helpers' export const createHighlightResolver = authorized< CreateHighlightSuccess, @@ -51,6 +52,7 @@ export const createHighlightResolver = authorized< highlightType: input.type || HighlightType.Highlight, highlightPositionAnchorIndex: input.highlightPositionAnchorIndex || 0, highlightPositionPercent: input.highlightPositionPercent || 0, + representation: input.representation || RepresentationType.Content, }, input.articleId, uid, diff --git a/packages/api/src/schema.ts b/packages/api/src/schema.ts index e3421f20a..5566c9a02 100755 --- a/packages/api/src/schema.ts +++ b/packages/api/src/schema.ts @@ -704,6 +704,11 @@ const schema = gql` NOTE } + enum RepresentationType { + CONTENT + FEED_CONTENT + } + # Highlight type Highlight { id: ID! @@ -729,6 +734,7 @@ const schema = gql` type: HighlightType! html: String color: String + representation: RepresentationType! } input CreateHighlightInput { @@ -746,6 +752,7 @@ const schema = gql` type: HighlightType html: String color: String + representation: RepresentationType } type CreateHighlightSuccess { @@ -780,6 +787,7 @@ const schema = gql` highlightPositionAnchorIndex: Int html: String color: String + representation: RepresentationType } type MergeHighlightSuccess { diff --git a/packages/db/migrations/0165.do.rename_preview_content_in_library_item.sql b/packages/db/migrations/0165.do.rename_preview_content_in_library_item.sql index 098e76e49..69fe27eb1 100755 --- a/packages/db/migrations/0165.do.rename_preview_content_in_library_item.sql +++ b/packages/db/migrations/0165.do.rename_preview_content_in_library_item.sql @@ -7,7 +7,8 @@ BEGIN; ALTER TABLE omnivore.library_item RENAME COLUMN preview_content TO feed_content; CREATE TYPE fetch_content_enum AS ENUM ('ALWAYS', 'NEVER', 'WHEN_EMPTY'); - ALTER TABLE omnivore.subscriptions ADD COLUMN fetch_content_type fetch_content_enum NOT NULL DEFAULT 'ALWAYS'::fetch_content_enum; +CREATE TYPE representation_type AS ENUM ('CONTENT', 'FEED_CONTENT'); +ALTER TABLE omnivore.highlight ADD COLUMN representation representation_type NOT NULL DEFAULT 'CONTENT'::representation_type; COMMIT; diff --git a/packages/db/migrations/0165.undo.rename_preview_content_in_library_item.sql b/packages/db/migrations/0165.undo.rename_preview_content_in_library_item.sql index b2aa4a628..29da95a98 100755 --- a/packages/db/migrations/0165.undo.rename_preview_content_in_library_item.sql +++ b/packages/db/migrations/0165.undo.rename_preview_content_in_library_item.sql @@ -4,8 +4,10 @@ BEGIN; -ALTER TABLE omnivore.subscriptions DROP COLUMN fetch_content_type; +ALTER TABLE omnivore.highlight DROP COLUMN representation; +DROP TYPE representation_type; +ALTER TABLE omnivore.subscriptions DROP COLUMN fetch_content_type; DROP TYPE fetch_content_enum; ALTER TABLE omnivore.library_item RENAME COLUMN feed_content TO preview_content;