Add new notification types, test for pathlib support

pull/278/head
halcy 2022-11-24 00:59:48 +02:00
rodzic 34280e604c
commit b7266db01b
6 zmienionych plików z 1045 dodań i 11 usunięć

Wyświetl plik

@ -13,6 +13,8 @@ v1.7.0
* Fixed search ignoring `exclude_unreviewed` (Thanks acidghost) * Fixed search ignoring `exclude_unreviewed` (Thanks acidghost)
* Add support for using pathlib paths when loading media files (Thanks reagle) * Add support for using pathlib paths when loading media files (Thanks reagle)
* Remove blocklist with long dead instances * Remove blocklist with long dead instances
* Add `types` parameter to notifications.
* Document additional notification types
* TECHNICALLY BREAKING CHANGE, but I would be quite surprised if this actually breaks anyone: Date parsing will now, when the date string is empty, return Jan. 1st, 1970 instead. This is to work around what I assume is a bug in Pleroma. * TECHNICALLY BREAKING CHANGE, but I would be quite surprised if this actually breaks anyone: Date parsing will now, when the date string is empty, return Jan. 1st, 1970 instead. This is to work around what I assume is a bug in Pleroma.
v1.6.3 v1.6.3

Wyświetl plik

@ -49,7 +49,7 @@ Refer to mastodon changelog and API docs for details when implementing, add or m
* [ ] Add POST /api/v1/accounts/:id/remove_from_followers to REST API * [ ] Add POST /api/v1/accounts/:id/remove_from_followers to REST API
* [ ] Add category and rule_ids params to POST /api/v1/reports IN REST API * [ ] Add category and rule_ids params to POST /api/v1/reports IN REST API
* [ ] Add global lang param to REST API * [ ] Add global lang param to REST API
* [ ] Add types param to GET /api/v1/notifications in REST API * [x] Add types param to GET /api/v1/notifications in REST API
* [ ] Add notifications for moderators about new sign-ups * [ ] Add notifications for moderators about new sign-ups
* [ ] v2 admin account api * [ ] v2 admin account api

Wyświetl plik

@ -938,6 +938,14 @@ Mastodon version (with regards to parameters as well as return values).
Version checking can also be disabled altogether. If a version check fails, Version checking can also be disabled altogether. If a version check fails,
Mastodon.py throws a `MastodonVersionError`. Mastodon.py throws a `MastodonVersionError`.
Some functions need to check what version of Mastodon they are talking to.
These will generally use a cached version to avoid sending a lot of pointless
requests.
Many non-mainline forks have various different formats for their versions and
they have different, incompatible ideas about how to report version. Mastodon.py
tries its best to figure out what is going on, but success is not guaranteed.
With the following functions, you can make Mastodon.py re-check the server With the following functions, you can make Mastodon.py re-check the server
version or explicitly determine if a specific minimum Version is available. version or explicitly determine if a specific minimum Version is available.
Long-running applications that aim to support multiple Mastodon versions Long-running applications that aim to support multiple Mastodon versions

Wyświetl plik

@ -235,7 +235,7 @@ class Mastodon:
__DICT_VERSION_HASHTAG = "2.3.4" __DICT_VERSION_HASHTAG = "2.3.4"
__DICT_VERSION_EMOJI = "3.0.0" __DICT_VERSION_EMOJI = "3.0.0"
__DICT_VERSION_RELATIONSHIP = "3.3.0" __DICT_VERSION_RELATIONSHIP = "3.3.0"
__DICT_VERSION_NOTIFICATION = bigger_version(bigger_version("1.0.0", __DICT_VERSION_ACCOUNT), __DICT_VERSION_STATUS) __DICT_VERSION_NOTIFICATION = bigger_version(bigger_version("3.5.0", __DICT_VERSION_ACCOUNT), __DICT_VERSION_STATUS)
__DICT_VERSION_CONTEXT = bigger_version("1.0.0", __DICT_VERSION_STATUS) __DICT_VERSION_CONTEXT = bigger_version("1.0.0", __DICT_VERSION_STATUS)
__DICT_VERSION_LIST = "2.1.0" __DICT_VERSION_LIST = "2.1.0"
__DICT_VERSION_CARD = "3.2.0" __DICT_VERSION_CARD = "3.2.0"
@ -1080,15 +1080,25 @@ class Mastodon:
### ###
# Reading data: Notifications # Reading data: Notifications
### ###
@api_version("1.0.0", "2.9.0", __DICT_VERSION_NOTIFICATION) @api_version("1.0.0", "3.5.0", __DICT_VERSION_NOTIFICATION)
def notifications(self, id=None, account_id=None, max_id=None, min_id=None, since_id=None, limit=None, exclude_types=None, mentions_only=None): def notifications(self, id=None, account_id=None, max_id=None, min_id=None, since_id=None, limit=None, exclude_types=None, types=None, mentions_only=None):
""" """
Fetch notifications (mentions, favourites, reblogs, follows) for the logged-in Fetch notifications (mentions, favourites, reblogs, follows) for the logged-in
user. Pass `account_id` to get only notifications originating from the given account. user. Pass `account_id` to get only notifications originating from the given account.
Parameter `exclude_types` is an array of the following `follow`, `favourite`, `reblog`, There are different types of notifications:
`mention`, `poll`, `follow_request`. Specifying `mentions_only` is a deprecated way to * `follow` - A user followed the logged in user
set `exclude_types` to all but mentions. * `follow_request` - A user has requested to follow the logged in user (for locked accounts)
* `favourite` - A user favourited a post by the logged in user
* `reblog` - A user reblogged a post by the logged in user
* `mention` - A user mentioned the logged in user
* `poll` - A poll the logged in user created or voted in has ended
* `update` - A status the logged in user has reblogged (and only those, as of 4.0.0) has been edited
* `status` - A user that the logged in user has enabned notifications for has enabled `notify` (see `account_follow()`_)
* `admin.sign_up` - For accounts with appropriate permissions (TODO: document which those are when adding the permission API): A new user has signed up
* `admin.report ` - For accounts with appropriate permissions (TODO: document which those are when adding the permission API): A new report has been received
Parameters `exclude_types` or alternately `types` are array of these types, specifying them will in- or exclude the
types of notifications given. Specifying `mentions_only` is a deprecated way to set `exclude_types` to all but mentions.
Can be passed an `id` to fetch a single notification. Can be passed an `id` to fetch a single notification.
@ -1097,11 +1107,13 @@ class Mastodon:
if mentions_only is not None: if mentions_only is not None:
if exclude_types is not None: if exclude_types is not None:
if mentions_only: if mentions_only:
exclude_types = ["follow", "favourite", if self.verify_minimum_version("3.5.0", cached=True):
"reblog", "poll", "follow_request"] types = ["mention"]
else:
exclude_types = ["follow", "favourite",
"reblog", "poll", "follow_request"]
else: else:
raise MastodonIllegalArgumentError( raise MastodonIllegalArgumentError('Cannot specify exclude_types when mentions_only is present')
'Cannot specify exclude_types when mentions_only is present')
del mentions_only del mentions_only
if max_id is not None: if max_id is not None:

Wyświetl plik

@ -1,6 +1,7 @@
import pytest import pytest
import vcr import vcr
import time import time
import pathlib
@pytest.mark.vcr(match_on=['path']) @pytest.mark.vcr(match_on=['path'])
def test_media_post_v1(api): def test_media_post_v1(api):
@ -127,3 +128,10 @@ def test_media_post_file(api):
with open('tests/image.jpg', 'rb') as f: with open('tests/image.jpg', 'rb') as f:
media = api.media_post(f, mime_type='image/jpeg') media = api.media_post(f, mime_type='image/jpeg')
assert media assert media
@pytest.mark.vcr(match_on=['path'])
def test_media_post_pathlib(api):
path = pathlib.Path(".") / "tests" / "image.jpg"
media = api.media_post(path)
assert media