@@ -11,44 +11,51 @@ import {
1111 MAX_LENGTH_TITLE ,
1212 toUnionUndefined ,
1313} from "@/shared/shared.js" ;
14- import {
15- conversationTable ,
16- conversationUpdateQueueTable ,
17- } from "@/shared-backend/schema.js" ;
14+ import { conversationUpdateQueueTable } from "@/shared-backend/schema.js" ;
1815import { nowZeroMs } from "@/shared/util.js" ;
19- import { eq } from "drizzle-orm" ;
2016import type { VoteBuffer } from "./voteBuffer.js" ;
2117
18+ // URL import configuration
19+ export interface UrlImportConfig {
20+ method : "url" ;
21+ polisUrl : string ;
22+ polisUrlType : "report" | "conversation" ;
23+ }
24+
25+ // CSV import configuration
26+ export interface CsvImportConfig {
27+ method : "csv" ;
28+ }
29+
30+ // Discriminated union for import configuration
31+ export type ImportConfig = UrlImportConfig | CsvImportConfig ;
32+
2233interface LoadImportedPolisConversationProps {
2334 db : PostgresDatabase ;
2435 voteBuffer : VoteBuffer ;
25- polisUrl : string ;
26- polisUrlType : "report" | "conversation" ;
2736 importedPolisConversation : ImportPolisResults ;
37+ importConfig : ImportConfig ;
2838 proof : string ;
2939 didWrite : string ;
3040 authorId : string ;
3141 postAsOrganization : string | undefined ;
3242 indexConversationAt ?: string ;
3343 isLoginRequired : boolean ;
3444 isIndexed : boolean ;
35- importMethod : "url" | "csv" ;
3645}
3746
3847export async function loadImportedPolisConversation ( {
3948 db,
4049 voteBuffer,
4150 importedPolisConversation,
42- polisUrl,
43- polisUrlType,
51+ importConfig,
4452 proof,
4553 didWrite,
4654 authorId,
4755 postAsOrganization,
4856 indexConversationAt,
4957 isLoginRequired,
5058 isIndexed,
51- importMethod,
5259} : LoadImportedPolisConversationProps ) : Promise < ConversationIds > {
5360 const now = nowZeroMs ( ) ;
5461 // create conversation
@@ -74,7 +81,7 @@ export async function loadImportedPolisConversation({
7481 let conversationBody = `${ trimmedBody } <br /><br />--------------` ;
7582
7683 // Handle messaging based on import method
77- if ( importMethod === "csv" ) {
84+ if ( importConfig . method === "csv" ) {
7885 // CSV imports
7986 conversationBody = `${ conversationBody } <br />This conversation was imported from Polis CSV files.` ;
8087 // For CSV imports, link_url might be available from summary.csv
@@ -85,8 +92,8 @@ export async function loadImportedPolisConversation({
8592 }
8693 } else {
8794 // URL imports (existing behavior)
88- if ( polisUrlType === "conversation" ) {
89- conversationUrl = polisUrl ;
95+ if ( importConfig . polisUrlType === "conversation" ) {
96+ conversationUrl = importConfig . polisUrl ;
9097 conversationBody = `${ conversationBody } <br />This conversation was initially imported from ${ conversationUrl } .` ;
9198 reportUrl =
9299 importedPolisConversation . report_id !== null
@@ -102,7 +109,7 @@ export async function loadImportedPolisConversation({
102109 null
103110 ? `https://pol.is/${ String ( importedPolisConversation . conversation_data . conversation_id ) } `
104111 : undefined ) ; // should never be undefined, but as we rely on external systems we don't control, better safe than sorry
105- reportUrl = polisUrl ;
112+ reportUrl = importConfig . polisUrl ;
106113 conversationBody = `${ conversationBody } <br />This conversation was initially imported from ${ reportUrl } .` ;
107114 if ( conversationUrl !== undefined ) {
108115 conversationBody = `${ conversationBody } <br />The original conversation url is ${ conversationUrl } .` ;
@@ -144,12 +151,15 @@ export async function loadImportedPolisConversation({
144151 isIndexed : isIndexed ,
145152 isLoginRequired : isLoginRequired ,
146153 seedOpinionList : [ ] ,
147- importUrl : importMethod === "csv" ? undefined : polisUrl ,
154+ importUrl :
155+ importConfig . method === "csv"
156+ ? undefined
157+ : importConfig . polisUrl ,
148158 importConversationUrl : conversationUrl ,
149159 importExportUrl : reportUrl ,
150160 importCreatedAt : importCreatedAt ,
151161 importAuthor : toUnionUndefined ( ownername ) ,
152- importMethod : importMethod ,
162+ importMethod : importConfig . method ,
153163 } ) ;
154164 try {
155165 const {
0 commit comments