kopia lustrzana https://github.com/halcy/Mastodon.py
Add new notification types, test for pathlib support
rodzic
34280e604c
commit
b7266db01b
|
@ -13,6 +13,8 @@ v1.7.0
|
|||
* Fixed search ignoring `exclude_unreviewed` (Thanks acidghost)
|
||||
* Add support for using pathlib paths when loading media files (Thanks reagle)
|
||||
* 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.
|
||||
|
||||
v1.6.3
|
||||
|
|
2
TODO.md
2
TODO.md
|
@ -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 category and rule_ids params to POST /api/v1/reports IN 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
|
||||
* [ ] v2 admin account api
|
||||
|
||||
|
|
|
@ -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,
|
||||
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
|
||||
version or explicitly determine if a specific minimum Version is available.
|
||||
Long-running applications that aim to support multiple Mastodon versions
|
||||
|
|
|
@ -235,7 +235,7 @@ class Mastodon:
|
|||
__DICT_VERSION_HASHTAG = "2.3.4"
|
||||
__DICT_VERSION_EMOJI = "3.0.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_LIST = "2.1.0"
|
||||
__DICT_VERSION_CARD = "3.2.0"
|
||||
|
@ -1080,15 +1080,25 @@ class Mastodon:
|
|||
###
|
||||
# Reading data: Notifications
|
||||
###
|
||||
@api_version("1.0.0", "2.9.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):
|
||||
@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, types=None, mentions_only=None):
|
||||
"""
|
||||
Fetch notifications (mentions, favourites, reblogs, follows) for the logged-in
|
||||
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`,
|
||||
`mention`, `poll`, `follow_request`. Specifying `mentions_only` is a deprecated way to
|
||||
set `exclude_types` to all but mentions.
|
||||
There are different types of notifications:
|
||||
* `follow` - A user followed the logged in user
|
||||
* `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.
|
||||
|
||||
|
@ -1097,11 +1107,13 @@ class Mastodon:
|
|||
if mentions_only is not None:
|
||||
if exclude_types is not None:
|
||||
if mentions_only:
|
||||
exclude_types = ["follow", "favourite",
|
||||
"reblog", "poll", "follow_request"]
|
||||
if self.verify_minimum_version("3.5.0", cached=True):
|
||||
types = ["mention"]
|
||||
else:
|
||||
exclude_types = ["follow", "favourite",
|
||||
"reblog", "poll", "follow_request"]
|
||||
else:
|
||||
raise MastodonIllegalArgumentError(
|
||||
'Cannot specify exclude_types when mentions_only is present')
|
||||
raise MastodonIllegalArgumentError('Cannot specify exclude_types when mentions_only is present')
|
||||
del mentions_only
|
||||
|
||||
if max_id is not None:
|
||||
|
|
Plik diff jest za duży
Load Diff
|
@ -1,6 +1,7 @@
|
|||
import pytest
|
||||
import vcr
|
||||
import time
|
||||
import pathlib
|
||||
|
||||
@pytest.mark.vcr(match_on=['path'])
|
||||
def test_media_post_v1(api):
|
||||
|
@ -127,3 +128,10 @@ def test_media_post_file(api):
|
|||
with open('tests/image.jpg', 'rb') as f:
|
||||
media = api.media_post(f, mime_type='image/jpeg')
|
||||
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
|
||||
|
Ładowanie…
Reference in New Issue