Send messages via mkdir
This commit is contained in:
parent
6c387338d3
commit
b9b58ffae0
2 changed files with 55 additions and 0 deletions
16
eufs/euph.py
16
eufs/euph.py
|
|
@ -48,6 +48,9 @@ class Room:
|
||||||
self.alive = False
|
self.alive = False
|
||||||
self.ws.close()
|
self.ws.close()
|
||||||
|
|
||||||
|
def send(self, content, parent=None):
|
||||||
|
self._send("send", content=content, parent=parent)
|
||||||
|
|
||||||
def find_msg_by_texts(self, texts):
|
def find_msg_by_texts(self, texts):
|
||||||
msg = None
|
msg = None
|
||||||
children = {mid: msg for mid, msg in self.msgs.items() if msg.parent == None}
|
children = {mid: msg for mid, msg in self.msgs.items() if msg.parent == None}
|
||||||
|
|
@ -103,6 +106,10 @@ class Room:
|
||||||
self._on_hello_event(data)
|
self._on_hello_event(data)
|
||||||
case "snapshot-event":
|
case "snapshot-event":
|
||||||
self._on_snapshot_event(data)
|
self._on_snapshot_event(data)
|
||||||
|
case "send-event":
|
||||||
|
self._on_send_event(data)
|
||||||
|
case "send-reply":
|
||||||
|
self._on_send_event(data)
|
||||||
|
|
||||||
print(packet["type"])
|
print(packet["type"])
|
||||||
|
|
||||||
|
|
@ -128,3 +135,12 @@ class Room:
|
||||||
parent.children[msg.id] = msg
|
parent.children[msg.id] = msg
|
||||||
|
|
||||||
self._send("nick", name="garmtest")
|
self._send("nick", name="garmtest")
|
||||||
|
|
||||||
|
def _on_send_event(self, data):
|
||||||
|
msg = Message(data)
|
||||||
|
self.msgs[msg.id] = msg
|
||||||
|
|
||||||
|
if msg.parent is not None:
|
||||||
|
parent = self.msgs.get(msg.parent)
|
||||||
|
if parent is not None:
|
||||||
|
parent.children[msg.id] = msg
|
||||||
|
|
|
||||||
39
eufs/main.py
39
eufs/main.py
|
|
@ -123,6 +123,45 @@ class EuFs(fuse.Fuse):
|
||||||
print(child.text)
|
print(child.text)
|
||||||
yield fuse.Direntry(child.text)
|
yield fuse.Direntry(child.text)
|
||||||
|
|
||||||
|
def mkdir(self, path, mode):
|
||||||
|
print(f"mkdir: {path!r} {mode!r}")
|
||||||
|
|
||||||
|
parts = Path(path).parts
|
||||||
|
if parts == ("/",):
|
||||||
|
print(f" is root")
|
||||||
|
return -errno.EEXIST
|
||||||
|
print(f" is not root")
|
||||||
|
|
||||||
|
roomname = parts[1]
|
||||||
|
texts = parts[2:]
|
||||||
|
|
||||||
|
room = self.rooms.get(roomname)
|
||||||
|
if not room:
|
||||||
|
print(f" is invalid room")
|
||||||
|
return -errno.ENOENT
|
||||||
|
print(f" is valid room")
|
||||||
|
|
||||||
|
if texts == ():
|
||||||
|
print(f" is no content")
|
||||||
|
return -errno.EEXIST
|
||||||
|
|
||||||
|
content = texts[-1]
|
||||||
|
texts = texts[:-1]
|
||||||
|
|
||||||
|
if texts == ():
|
||||||
|
print(" is root message")
|
||||||
|
room.send(content)
|
||||||
|
return
|
||||||
|
|
||||||
|
msg = room.find_msg_by_texts(texts)
|
||||||
|
if not msg:
|
||||||
|
print(f" is invalid msg")
|
||||||
|
return -errno.ENOENT
|
||||||
|
print(f" is valid msg")
|
||||||
|
|
||||||
|
print(" is child message")
|
||||||
|
room.send(content, parent=msg.id)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
server = EuFs(version="%prog " + fuse.__version__, dash_s_do="setsingle")
|
server = EuFs(version="%prog " + fuse.__version__, dash_s_do="setsingle")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue