Skip to content

Commit df24975

Browse files
authored
Fix the attachments on message edition and on python Message model (#200)
* Add the attachments field in the python Message interface * Fix the extra attachments property after editing a message
1 parent 748c20f commit df24975

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

packages/jupyterlab-chat/src/model.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ export class LabChatModel extends ChatModel implements DocumentRegistry.IModel {
162162
}
163163

164164
// Add the attachments to the message.
165-
if (this.input.attachments.length) {
166-
const attachmentIds = this.input.attachments.map(attachment =>
167-
this.sharedModel.setAttachment(attachment)
168-
);
165+
const attachmentIds = this.input.attachments?.map(attachment =>
166+
this.sharedModel.setAttachment(attachment)
167+
);
168+
if (attachmentIds?.length) {
169169
msg.attachments = attachmentIds;
170-
this.input.clearAttachments();
171170
}
171+
this.input.clearAttachments();
172172

173173
this.sharedModel.addMessage(msg);
174174
}
@@ -204,9 +204,12 @@ export class LabChatModel extends ChatModel implements DocumentRegistry.IModel {
204204
const attachmentIds = updatedMessage.attachments?.map(attachment =>
205205
this.sharedModel.setAttachment(attachment)
206206
);
207-
if (attachmentIds) {
207+
if (attachmentIds?.length) {
208208
message.attachments = attachmentIds;
209+
} else {
210+
delete message.attachments;
209211
}
212+
210213
this.sharedModel.updateMessage(index, message as IYmessage);
211214
}
212215

python/jupyterlab-chat/jupyterlab_chat/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class Message:
3535
# 3.9 reaches EOL.
3636
type: Literal["msg"] = "msg"
3737

38+
attachments: Optional[list[str]] = None
39+
""" The message attachments, a list of attachment ID """
40+
3841
raw_time: Optional[bool] = None
3942
"""
4043
Whether the timestamp is raw (from client) or not (from server, unified)

0 commit comments

Comments
 (0)