diff options
Diffstat (limited to 'mastodon/notifications.py')
-rw-r--r-- | mastodon/notifications.py | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/mastodon/notifications.py b/mastodon/notifications.py new file mode 100644 index 0000000..f65b3fb --- /dev/null +++ b/mastodon/notifications.py | |||
@@ -0,0 +1,92 @@ | |||
1 | # notifications.py - notification endpoints | ||
2 | |||
3 | from .versions import _DICT_VERSION_NOTIFICATION | ||
4 | from .errors import MastodonIllegalArgumentError | ||
5 | from .utility import api_version | ||
6 | |||
7 | from .internals import Mastodon as Internals | ||
8 | |||
9 | class Mastodon(Internals): | ||
10 | ### | ||
11 | # Reading data: Notifications | ||
12 | ### | ||
13 | @api_version("1.0.0", "3.5.0", _DICT_VERSION_NOTIFICATION) | ||
14 | 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): | ||
15 | """ | ||
16 | Fetch notifications (mentions, favourites, reblogs, follows) for the logged-in | ||
17 | user. Pass `account_id` to get only notifications originating from the given account. | ||
18 | |||
19 | There are different types of notifications: | ||
20 | * `follow` - A user followed the logged in user | ||
21 | * `follow_request` - A user has requested to follow the logged in user (for locked accounts) | ||
22 | * `favourite` - A user favourited a post by the logged in user | ||
23 | * `reblog` - A user reblogged a post by the logged in user | ||
24 | * `mention` - A user mentioned the logged in user | ||
25 | * `poll` - A poll the logged in user created or voted in has ended | ||
26 | * `update` - A status the logged in user has reblogged (and only those, as of 4.0.0) has been edited | ||
27 | * `status` - A user that the logged in user has enabned notifications for has enabled `notify` (see :ref:`account_follow() <account_follow()>`) | ||
28 | * `admin.sign_up` - For accounts with appropriate permissions (TODO: document which those are when adding the permission API): A new user has signed up | ||
29 | * `admin.report` - For accounts with appropriate permissions (TODO: document which those are when adding the permission API): A new report has been received | ||
30 | Parameters `exclude_types` and `types` are array of these types, specifying them will in- or exclude the | ||
31 | types of notifications given. It is legal to give both parameters at the same tine, the result will then | ||
32 | be the intersection of the results of both filters. Specifying `mentions_only` is a deprecated way to set | ||
33 | `exclude_types` to all but mentions. | ||
34 | |||
35 | Can be passed an `id` to fetch a single notification. | ||
36 | |||
37 | Returns a list of :ref:`notification dicts <notification dicts>`. | ||
38 | """ | ||
39 | if mentions_only is not None: | ||
40 | if exclude_types is None and types is None: | ||
41 | if mentions_only: | ||
42 | if self.verify_minimum_version("3.5.0", cached=True): | ||
43 | types = ["mention"] | ||
44 | else: | ||
45 | exclude_types = ["follow", "favourite", "reblog", "poll", "follow_request"] | ||
46 | else: | ||
47 | raise MastodonIllegalArgumentError('Cannot specify exclude_types/types when mentions_only is present') | ||
48 | del mentions_only | ||
49 | |||
50 | if max_id is not None: | ||
51 | max_id = self.__unpack_id(max_id, dateconv=True) | ||
52 | |||
53 | if min_id is not None: | ||
54 | min_id = self.__unpack_id(min_id, dateconv=True) | ||
55 | |||
56 | if since_id is not None: | ||
57 | since_id = self.__unpack_id(since_id, dateconv=True) | ||
58 | |||
59 | if account_id is not None: | ||
60 | account_id = self.__unpack_id(account_id) | ||
61 | |||
62 | if id is None: | ||
63 | params = self.__generate_params(locals(), ['id']) | ||
64 | return self.__api_request('GET', '/api/v1/notifications', params) | ||
65 | else: | ||
66 | id = self.__unpack_id(id) | ||
67 | url = '/api/v1/notifications/{0}'.format(str(id)) | ||
68 | return self.__api_request('GET', url) | ||
69 | |||
70 | ### | ||
71 | # Writing data: Notifications | ||
72 | ### | ||
73 | @api_version("1.0.0", "1.0.0", "1.0.0") | ||
74 | def notifications_clear(self): | ||
75 | """ | ||
76 | Clear out a user's notifications | ||
77 | """ | ||
78 | self.__api_request('POST', '/api/v1/notifications/clear') | ||
79 | |||
80 | @api_version("1.3.0", "2.9.2", "2.9.2") | ||
81 | def notifications_dismiss(self, id): | ||
82 | """ | ||
83 | Deletes a single notification | ||
84 | """ | ||
85 | id = self.__unpack_id(id) | ||
86 | |||
87 | if self.verify_minimum_version("2.9.2", cached=True): | ||
88 | url = '/api/v1/notifications/{0}/dismiss'.format(str(id)) | ||
89 | self.__api_request('POST', url) | ||
90 | else: | ||
91 | params = self.__generate_params(locals()) | ||
92 | self.__api_request('POST', '/api/v1/notifications/dismiss', params) | ||