Skip to content

Commit

Permalink
Set shared document file_id
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Dec 1, 2023
1 parent d8629b4 commit 97a857c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions plugins/yjs/fps_yjs/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ async def serve(self, websocket: YWebsocket, permissions) -> None:
file_path = await self.contents.file_id_manager.get_path(file_id)
logger.info(f"Opening collaboration room: {websocket.path} ({file_path})")
document = YDOCS.get(file_type, YFILE)(room.ydoc)
document.file_id = file_id
self.documents[websocket.path] = document
async with self.lock:
model = await self.contents.read_content(file_path, True, file_format)
Expand Down
8 changes: 8 additions & 0 deletions plugins/yjs/fps_yjs/ydocs/ybasedoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ def path(self) -> Optional[str]:
def path(self, value: str) -> None:
self._ystate["path"] = value

@property
def file_id(self) -> Optional[str]:
return self._ystate.get("file_id")

@file_id.setter
def file_id(self, value: str) -> None:
self._ystate["file_id"] = value

@abstractmethod
def get(self) -> Any:
...
Expand Down
2 changes: 1 addition & 1 deletion plugins/yjs/fps_yjs/ydocs/ynotebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def set(self, value: Dict) -> None:
# clear document
self._ymeta.clear()
self._ycells.clear()
for key in [k for k in self._ystate.keys() if k not in ("dirty", "path")]:
for key in [k for k in self._ystate.keys() if k not in ("dirty", "path", "file_id")]:
del self._ystate[key]

# initialize document
Expand Down

0 comments on commit 97a857c

Please sign in to comment.