@@ -41,6 +41,7 @@ public abstract class InteractionCallbackImpl<T> extends RestActionImpl<T> imple
41
41
{
42
42
protected final List <AttachedFile > files = new ArrayList <>();
43
43
protected final InteractionImpl interaction ;
44
+ protected boolean isFileUpdate = false ;
44
45
45
46
public InteractionCallbackImpl (InteractionImpl interaction )
46
47
{
@@ -54,30 +55,42 @@ public InteractionCallbackImpl(InteractionImpl interaction)
54
55
protected RequestBody finalizeData ()
55
56
{
56
57
DataObject json = toData ();
57
- if (files .isEmpty ())
58
- return getRequestBody (json );
59
58
60
- MultipartBody .Builder body = AttachedFile .createMultipartBody (files , null );
59
+ if (isFileUpdate || !files .isEmpty ())
60
+ {
61
+ // Add the attachments array to the payload, as required since v10
62
+ DataObject data ;
63
+ if (json .isNull ("data" ))
64
+ json .put ("data" , data = DataObject .empty ());
65
+ else
66
+ data = json .getObject ("data" );
61
67
62
- // Add the attachments array to the payload, as required since v10
63
- DataObject data ;
64
- if (json .isNull ("data" ))
65
- json .put ("data" , data = DataObject .empty ());
66
- else
67
- data = json .getObject ("data" );
68
+ DataArray attachments ;
69
+ if (data .isNull ("attachments" ))
70
+ data .put ("attachments" , attachments = DataArray .empty ());
71
+ else
72
+ attachments = data .getArray ("attachments" );
68
73
69
- DataArray attachments ;
70
- if (data .isNull ("attachments" ))
71
- data .put ("attachments" , attachments = DataArray .empty ());
72
- else
73
- attachments = data .getArray ("attachments" );
74
+ for (int i = 0 ; i < files .size (); i ++)
75
+ attachments .add (files .get (i ).toAttachmentData (i ));
76
+ }
74
77
75
- for (int i = 0 ; i < files .size (); i ++)
76
- attachments .add (files .get (i ).toAttachmentData (i ));
78
+ RequestBody body ;
79
+ // Upload files using multipart request if applicable
80
+ if (files .stream ().anyMatch (FileUpload .class ::isInstance ))
81
+ {
82
+ MultipartBody .Builder form = AttachedFile .createMultipartBody (files , null );
83
+ form .addFormDataPart ("payload_json" , json .toString ());
84
+ body = form .build ();
85
+ }
86
+ else
87
+ {
88
+ body = getRequestBody (json );
89
+ }
77
90
78
- body . addFormDataPart ( "payload_json" , json . toString ()) ;
91
+ isFileUpdate = false ;
79
92
files .clear ();
80
- return body . build () ;
93
+ return body ;
81
94
}
82
95
83
96
@ Nonnull
0 commit comments