Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tui: allow editing toots #451

Merged
merged 1 commit into from
Jan 2, 2024
Merged

tui: allow editing toots #451

merged 1 commit into from
Jan 2, 2024

Conversation

llfw
Copy link
Contributor

@llfw llfw commented Dec 31, 2023

Add new [E]dit command to the timeline: opens an existing toot to allow editing it. Since this is more or less the same operation as posting a new toot, extend the StatusComposer view to support this rather than implementing a new view.


this is a draft PR because of a significant unsolved issue: the Mastodon API returns toots as HTML, not plain text, so we would need to strip the HTML from the toot before displaying it in StatusComposer. this is particularly difficult for toots with links or embeds. i'm wondering if the API provides a better way to do this, but i couldn't find anything obvious in the docs.

aside from that, not all of the toot options are copied to the edited toot right now (i'll fix this), and it could also do with more testing.

also, the edited toot currently doesn't show up on the timeline without a refresh.

@ihabunek
Copy link
Owner

Thanks! This requires more brain cells than I'm willing to invest today. I'll leave the review for next year. :)

@danschwarz
Copy link
Collaborator

I suggest we don't strip the HTML when editing the toot. Rather, convert it to markdown, edit, then convert back to HTML.

#427 gives the required support libraries to reliably do HTML>markdown conversion (if you're willing to put up with the pandoc+pypandoc dependencies, it really does a better job than the alternatives.) I think those libraries will do markdown>HTML conversion as well, but will have to check.

@llfw
Copy link
Contributor Author

llfw commented Jan 1, 2024

i had a look at another library, Mastodon.py, and found it implements an endpoint called /api/v1/statuses/:id/source to fetch the plain-text source of a toot. it turns out this actually is documented in the Mastodon API docs, i just missed it the first time i looked.

according to a brief note, this only works for local toots, but only local toots can be edited, so this is fine.

hopefully, this means we don't need to do any conversion ourselves or use Pandoc, although i only use Mastodon so i don't know how this works on other implementations; presumably implementations that support Markdown will return the Markdown source.

@ihabunek
Copy link
Owner

ihabunek commented Jan 1, 2024

Good find! Was not aware of that. It's been a while since I read through the whole API docs to see what's new.

@llfw llfw force-pushed the edit-toot branch 2 times, most recently from d999639 to 8633ede Compare January 1, 2024 11:46
@llfw
Copy link
Contributor Author

llfw commented Jan 1, 2024

  • rebased against current master
  • now uses the /source API method to fetch the original text
  • original content warning is displayed in the edit box
  • polls currently aren't copied over, so will be removed on edit
  • fix an unrelated flake8 error in toot/cli/__init__.py

unless there are any other comments, the only thing left to land this is support for editing polls.

@danschwarz
Copy link
Collaborator

As a first implementation this would be fine; we can't author rich text statuses in toot yet anyway.

@llfw
Copy link
Contributor Author

llfw commented Jan 1, 2024

i noticed there's no support for composing polls to begin with, so now it just copies the poll from the original status (if there is one).

@llfw llfw marked this pull request as ready for review January 1, 2024 13:11
@llfw
Copy link
Contributor Author

llfw commented Jan 1, 2024

fixed an issue where editing a toot without a poll would fail (because the 'poll' key is still in the status dict, it's just set to null).

@llfw
Copy link
Contributor Author

llfw commented Jan 1, 2024

i've just noticed the issue where the updated status content isn't shown until refresh is still there. i'll add something to fix that, it looks fairly straightforward.

Add new [E]dit command to the timeline: opens an existing toot to allow
editing it.  Since this is more or less the same operation as posting a
new toot, extend the StatusComposer view to support this rather than
implementing a new view.

Add a new api method, fetch_status_source(), to implement the
/api/v1/statuses/{id}/source endpoint used to fetch the original post
text.
@llfw
Copy link
Contributor Author

llfw commented Jan 1, 2024

fixed.

Copy link
Owner

@ihabunek ihabunek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, tested it a bit and seems to work fine.

@ihabunek ihabunek merged commit 7f06928 into ihabunek:master Jan 2, 2024
6 checks passed
@danschwarz
Copy link
Collaborator

Interesting discovery- when editing toots containing rich text (html) on a glitch-doc server, the API call you're using automatically translates the html into markdown server-side. And reverses the translation when you submit the edit. At least this was my experience. I'll do some more testing. Unexpected and nice benefit.

@llfw llfw deleted the edit-toot branch January 3, 2024 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants