Skip to content

Commit 3bde20f

Browse files
committed
Better handling of message update from the backend
1 parent db44b60 commit 3bde20f

File tree

1 file changed

+10
-9
lines changed
  • python/jupyterlab-chat/jupyterlab_chat

1 file changed

+10
-9
lines changed

python/jupyterlab-chat/jupyterlab_chat/ychat.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,16 @@ def update_message(self, update: Message, append: bool = False):
161161
If append is True, the content will be append to the previous content.
162162
"""
163163
with self._ydoc.transaction():
164-
index = self._indexes_by_id[update.id]
165-
message = self._ymessages[index]
166-
message.update({
167-
"attachments": update.attachments,
168-
"mentions": update.mentions,
169-
"deleted": update.deleted,
170-
"edited": update.edited,
171-
"body": (message.get("body") if append else "") + update.body
172-
})
164+
try:
165+
index = self._indexes_by_id[update.id]
166+
message = self._ymessages[index]
167+
except (KeyError, IndexError) as e:
168+
print(e)
169+
return
170+
update_dict = asdict(update)
171+
if (update.body and append):
172+
update_dict["body"] = message.get("body") + update.body
173+
message.update(update_dict)
173174

174175
def get_attachments(self) -> dict[str, Union[FileAttachment, NotebookAttachment]]:
175176
"""

0 commit comments

Comments
 (0)