11import { acceptHMRUpdate , defineStore , storeToRefs } from "pinia" ;
2- import { computed , reactive , ref } from "vue" ;
2+ import { computed , reactive , Ref , ref } from "vue" ;
33import Header from "@/resources/Header" ;
44import type EndpointDetails from "@/resources/EndpointDetails" ;
55import { FailedMessage , ExceptionDetails , FailedMessageStatus } from "@/resources/FailedMessage" ;
@@ -11,6 +11,9 @@ import { parse, stringify } from "lossless-json";
1111import xmlFormat from "xml-formatter" ;
1212import { DataContainer } from "./DataContainer" ;
1313import { useServiceControlStore } from "./ServiceControlStore" ;
14+ import EditRetryResponse from "@/resources/EditRetryResponse" ;
15+ import { EditedMessage } from "@/resources/EditMessage" ;
16+ import useEnvironmentAndVersionsAutoRefresh from "@/composables/useEnvironmentAndVersionsAutoRefresh" ;
1417
1518interface Model {
1619 id ?: string ;
@@ -62,12 +65,15 @@ export const useMessageStore = defineStore("MessageStore", () => {
6265 const headers = ref < DataContainer < Header [ ] > > ( { data : [ ] } ) ;
6366 const body = ref < DataContainer < { value ?: string ; content_type ?: string ; no_content ?: boolean } > > ( { data : { } } ) ;
6467 const state = reactive < DataContainer < Model > > ( { data : { failure_metadata : { } , failure_status : { } , dialog_status : { } , invoked_saga : { } } } ) ;
68+ const editRetryResponse = ref < EditRetryResponse | null > ( null ) ;
6569 let bodyLoadedId = "" ;
6670 let conversationLoadedId = "" ;
6771 const conversationData = ref < DataContainer < Message [ ] > > ( { data : [ ] } ) ;
6872 const editRetryStore = useEditRetryStore ( ) ;
6973 const configStore = useConfigurationStore ( ) ;
7074 const serviceControlStore = useServiceControlStore ( ) ;
75+ const { store : environmentStore } = useEnvironmentAndVersionsAutoRefresh ( ) ;
76+ const areSimpleHeadersSupported = environmentStore . serviceControlIsGreaterThan ( "5.2.0" ) ;
7177
7278 const { config : edit_and_retry_config } = storeToRefs ( editRetryStore ) ;
7379 const { configuration } = storeToRefs ( configStore ) ;
@@ -83,6 +89,7 @@ export const useMessageStore = defineStore("MessageStore", () => {
8389 bodyLoadedId = "" ;
8490 conversationLoadedId = "" ;
8591 conversationData . value . data = [ ] ;
92+ editRetryResponse . value = null ;
8693 }
8794
8895 async function loadFailedMessage ( id : string ) {
@@ -261,6 +268,36 @@ export const useMessageStore = defineStore("MessageStore", () => {
261268 }
262269 }
263270
271+ async function retryEditedMessage ( id : string , editedMessage : Ref < EditedMessage > ) {
272+ const payload = {
273+ message_body : editedMessage . value . messageBody ,
274+ message_headers : areSimpleHeadersSupported . value
275+ ? editedMessage . value . headers . reduce (
276+ ( result , header ) => {
277+ const { key, value } = header as { key : string ; value : string } ;
278+ result [ key ] = value ;
279+ return result ;
280+ } ,
281+ { } as { [ key : string ] : string }
282+ )
283+ : editedMessage . value . headers ,
284+ } ;
285+ const response = await serviceControlStore . postToServiceControl ( `edit/${ id } ` , payload ) ;
286+ if ( ! response . ok ) {
287+ throw new Error ( response . statusText ) ;
288+ }
289+
290+ //older versions of SC return no payload about the edit result
291+ const bodyText = await response . text ( ) ;
292+ if ( bodyText === "" ) {
293+ editRetryResponse . value = {
294+ edit_ignored : false ,
295+ } ;
296+ } else {
297+ editRetryResponse . value = parse ( bodyText ) as EditRetryResponse ;
298+ }
299+ }
300+
264301 async function pollForNextUpdate ( status : FailedMessageStatus ) {
265302 if ( ! state . data . id ) {
266303 return ;
@@ -320,6 +357,7 @@ export const useMessageStore = defineStore("MessageStore", () => {
320357 body,
321358 state,
322359 edit_and_retry_config,
360+ editRetryResponse,
323361 reset,
324362 loadMessage,
325363 loadFailedMessage,
@@ -332,6 +370,7 @@ export const useMessageStore = defineStore("MessageStore", () => {
332370 retryMessages,
333371 conversationData,
334372 pollForNextUpdate,
373+ retryEditedMessage,
335374 } ;
336375} ) ;
337376
0 commit comments