11import PropTypes from 'prop-types' ;
22
3- import ActivityGroupingContext from './ActivityGroupingContext' ;
43import createDirectLineWithTranscript from '../createDirectLineWithTranscript' ;
4+ import ActivityGroupingContext from './ActivityGroupingContext' ;
55
66// Use React from window (UMD) instead of import.
77const { React : { useEffect, useMemo, useState } = { } } = window ;
@@ -23,22 +23,6 @@ const URL_QUERY_MAPPING = {
2323 wd : 'hide'
2424} ;
2525
26- function createCustomActivityMiddleware ( attachmentLayout ) {
27- return ( ) =>
28- next =>
29- ( arg0 , ...args ) =>
30- next (
31- {
32- ...arg0 ,
33- activity : {
34- ...arg0 . activity ,
35- ...( attachmentLayout && arg0 . activity . from . role === 'bot' ? { attachmentLayout } : { } )
36- }
37- } ,
38- ...args
39- ) ;
40- }
41-
4226function generateURL ( state ) {
4327 const params = { } ;
4428
@@ -143,7 +127,15 @@ const ActivityGroupingSurface = ({ children }) => {
143127 let directLine ;
144128
145129 ( async function ( ) {
146- directLine = await createDirectLineWithTranscript ( transcriptName ) ;
130+ directLine = await createDirectLineWithTranscript ( transcriptName , {
131+ patchActivity : activity => {
132+ if ( ( attachmentLayout === 'carousel' || attachmentLayout === 'stacked' ) && activity . from ?. role === 'bot' ) {
133+ return Object . freeze ( { ...activity , attachmentLayout } ) ;
134+ }
135+
136+ return activity ;
137+ }
138+ } ) ;
147139
148140 aborted || setDirectLine ( directLine ) ;
149141 } ) ( ) ;
@@ -152,15 +144,7 @@ const ActivityGroupingSurface = ({ children }) => {
152144 aborted = true ;
153145 directLine && directLine . end ( ) ;
154146 } ;
155- } , [ setDirectLine , transcriptName ] ) ;
156-
157- const activityMiddleware = useMemo (
158- ( ) =>
159- attachmentLayout === 'carousel' || attachmentLayout === 'stacked'
160- ? createCustomActivityMiddleware ( attachmentLayout )
161- : undefined ,
162- [ attachmentLayout ]
163- ) ;
147+ } , [ attachmentLayout , setDirectLine , transcriptName ] ) ;
164148
165149 const styleOptions = useMemo (
166150 ( ) => ( {
@@ -223,7 +207,6 @@ const ActivityGroupingSurface = ({ children }) => {
223207 const context = useMemo (
224208 ( ) => ( {
225209 ...contextState ,
226- activityMiddleware,
227210 directLine,
228211 setAttachmentLayout,
229212 setBotAvatarInitials,
@@ -242,7 +225,6 @@ const ActivityGroupingSurface = ({ children }) => {
242225 url
243226 } ) ,
244227 [
245- activityMiddleware ,
246228 contextState ,
247229 directLine ,
248230 setAttachmentLayout ,
0 commit comments