Skip to content

Commit

Permalink
Fix: Amend command was broken due to refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
hoh committed Sep 20, 2022
1 parent bcc652a commit 5b514f8
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/aleph_client/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,24 +454,26 @@ def amend(
editor: str = os.getenv("EDITOR", default="nano")
with tempfile.NamedTemporaryFile(suffix="json") as fd:
# Fill in message template
fd.write(json.dumps(existing_message["content"], indent=4).encode())
fd.write(existing_message.content.json(indent=4).encode())
fd.seek(0)

# Launch editor
subprocess.run([editor, fd.name], check=True)

# Read new message
fd.seek(0)
new_message = fd.read()
new_content_json = fd.read()

new_content = json.loads(new_message)
new_content["ref"] = existing_message["item_hash"]
content_type = type(existing_message).__annotations__["content"]
new_content_dict = json.loads(new_content_json)
new_content = content_type(**new_content_dict)
new_content.ref = existing_message.item_hash
echo(new_content)
result = synchronous.submit(
account=account,
content=new_content,
message_type=existing_message["type"],
channel=existing_message["channel"],
content=new_content.dict(),
message_type=existing_message.type,
channel=existing_message.channel,
)
echo(f"{result.json(indent=4)}")

Expand Down

0 comments on commit 5b514f8

Please sign in to comment.