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

Support newer event type #234

Closed
tribela opened this issue Jun 20, 2022 · 4 comments · Fixed by #235
Closed

Support newer event type #234

tribela opened this issue Jun 20, 2022 · 4 comments · Fixed by #235

Comments

@tribela
Copy link
Contributor

tribela commented Jun 20, 2022

Mastodon 3.5 introduces status.update event.
Currently mastodon.py doesn't support it, And keep crashing on that event.

@arittner
Copy link
Collaborator

Hi!

I guess you mean this from the changelog:

Add support for incoming edited posts (mastodon/mastodon#16697, mastodon/mastodon#17727, mastodon/mastodon#17728, mastodon/mastodon#17320, mastodon/mastodon#17404, mastodon/mastodon#17390, mastodon/mastodon#17335, mastodon/mastodon#17696, mastodon/mastodon#17745, mastodon/mastodon#17740, mastodon/mastodon#17697, mastodon/mastodon#17648, mastodon/mastodon#17531, mastodon/mastodon#17499, mastodon/mastodon#17498, mastodon/mastodon#17380, mastodon/mastodon#17373, mastodon/mastodon#17334, mastodon/mastodon#17333, mastodon/mastodon#17699, mastodon/mastodon#17748)

Previous versions remain available for perusal and comparison
People who reblogged a post are notified when it's edited
New REST APIs:
PUT /api/v1/statuses/:id
GET /api/v1/statuses/:id/history
GET /api/v1/statuses/:id/source
New streaming API event:
status.update

And the crash is in the streaming API on receiving the update event?

@arittner
Copy link
Collaborator

Hello @tribela

I guess the "crash" is a MastodonMalformedEventError from this function (in streaming.py):

    def _dispatch(self, event):
...
        handler_name = 'on_' + name
        try:
            handler = getattr(self, handler_name)
        except AttributeError as err:
            exception = MastodonMalformedEventError('Bad event type', name)
            self.on_abort(exception)
            six.raise_from(
               exception,
               err
            )
        else:
            handler(payload)

The name of the event-type is not supported. The Mastodon.py supports only update (which means a new status), delete, notification and conversation.

I'll try to support @halcy to implement it.

It may also be useful to configure Mastodon.py to ignore unknown events to avoid future problems with new events. With this option, a developer has the choice to use Mastodon.py with newer API events.

@arittner
Copy link
Collaborator

arittner commented Jun 20, 2022

I checked the code, and it's typically possible to write listener-functions to manage well-known new events. Unfortunately, Mastodon API use now a dot inside the event name. And this is not supported with the callback-function lookup.

So, we have two cases:

  1. Unknown new events breaks existing listeners. We have no handler to manage complete unknown messages. So every time the API comes with new events, a developer must enhance the listener. Otherwise, the app will break on fetching these unknown events.
  2. Events with reserved characters (e.g. a . dot) cannot be handled, because this is not allowed:
        def on_status.update(self, data):
            pass

For point 2 the solution is simple. The event-name can be patched to replace dots with underscores (we hope, we'll not get other special characters). The solution for the first point is just a little more complicated, but worth it if you want to prevent such current cases that Mastodon.py is not usable for a while when the API has changed.

I implemented both solutions and check it, if it's working. I'll drop a PR.

The PR will not include a handling of status.update and status edits and not the history API. But the PR supports handling event names with dots and the possibility to catch and handle new unknown events.

Supporting the new "status edit" should be part of an additional implementation.

/cc @halcy

@arittner
Copy link
Collaborator

See also: #218

arittner pushed a commit to arittner/Mastodon.py that referenced this issue Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants