@@ -10,8 +10,8 @@ import { MessageRenderer } from './message-renderer';
1010import { AttachmentPreviewList } from '../attachments' ;
1111import { ChatInput } from '../input' ;
1212import { useChatContext } from '../../context' ;
13- import { IInputModel , InputModel } from '../../input-model' ;
14- import { IMessageContent , IMessage } from '../../types' ;
13+ import { InputModel } from '../../input-model' ;
14+ import { IMessageContent , IMessage , INewMessage } from '../../types' ;
1515import { replaceSpanToMention } from '../../utils' ;
1616
1717export const MESSAGE_CONTAINER_CLASS = 'jp-chat-message-container' ;
@@ -96,8 +96,8 @@ export function ChatMessageBase(props: ChatMessageProps): JSX.Element {
9696 } ) ;
9797 const inputModel = new InputModel ( {
9898 chatContext : model . createChatContext ( ) ,
99- onSend : ( input : string , model ?: IInputModel ) =>
100- updateMessage ( message . id , input , model ) ,
99+ onSend : ( newMessage : INewMessage ) =>
100+ updateMessage ( message . id , newMessage ) ,
101101 onCancel : ( ) => cancelEdition ( ) ,
102102 value : body ,
103103 activeCellManager : model . activeCellManager ,
@@ -121,17 +121,27 @@ export function ChatMessageBase(props: ChatMessageProps): JSX.Element {
121121
122122 // Update the content of the message.
123123 const updateMessage = useCallback (
124- ( id : string , input : string , inputModel ?: IInputModel ) : void => {
125- if ( ! canEdit || ! inputModel ) {
124+ ( id : string , newMessage : INewMessage ) : void => {
125+ const inputModel = model . getEditionModel ( id ) ;
126+ if ( ! canEdit || ! inputModel || ! model . updateMessage ) {
127+ setEdit ( false ) ;
126128 return ;
127129 }
130+
128131 // Update the message
129132 const updatedMessage = { ...message } ;
130- updatedMessage . body = input ;
131- updatedMessage . attachments = inputModel . attachments ;
132- updatedMessage . mentions = inputModel . mentions ;
133- model . updateMessage ! ( id , updatedMessage ) ;
134- model . getEditionModel ( message . id ) ?. dispose ( ) ;
133+ if ( newMessage . body ) {
134+ updatedMessage . body = newMessage . body ;
135+ }
136+ if ( newMessage . attachments ) {
137+ updatedMessage . attachments = newMessage . attachments ;
138+ }
139+ if ( newMessage . mentions ) {
140+ updatedMessage . mentions = newMessage . mentions ;
141+ }
142+
143+ model . updateMessage ( id , updatedMessage ) ;
144+ inputModel . dispose ( ) ;
135145 setEdit ( false ) ;
136146 } ,
137147 [ model , message , canEdit ]
0 commit comments