diff options
author | Lorenz Diener <[email protected]> | 2019-04-28 14:28:05 +0200 |
---|---|---|
committer | Lorenz Diener <[email protected]> | 2019-04-28 14:28:05 +0200 |
commit | a29d278bf9cacf5f888561564f112312707e32fd (patch) | |
tree | a85fb9da87db5c99c4d19d062ce5eb702878840d /mastodon | |
parent | 65e2596d9bad2ac0a0c434ccc89700bd8e5d12ff (diff) | |
download | mastodon.py-a29d278bf9cacf5f888561564f112312707e32fd.tar.gz |
Add support for conversation streaming
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/Mastodon.py | 7 | ||||
-rw-r--r-- | mastodon/streaming.py | 11 |
2 files changed, 17 insertions, 1 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index edb67f8..b19c3de 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -2188,6 +2188,13 @@ class Mastodon: | |||
2188 | id = self.__unpack_id(id) | 2188 | id = self.__unpack_id(id) |
2189 | return self.__stream("/api/v1/streaming/list?list={}".format(id), listener, run_async=run_async, timeout=timeout, reconnect_async=reconnect_async, reconnect_async_wait_sec=reconnect_async_wait_sec) | 2189 | return self.__stream("/api/v1/streaming/list?list={}".format(id), listener, run_async=run_async, timeout=timeout, reconnect_async=reconnect_async, reconnect_async_wait_sec=reconnect_async_wait_sec) |
2190 | 2190 | ||
2191 | @api_version("2.6.0", "2.6.0", __DICT_VERSION_STATUS) | ||
2192 | def stream_direct(self, listener, run_async=False, timeout=__DEFAULT_STREAM_TIMEOUT, reconnect_async=False, reconnect_async_wait_sec=__DEFAULT_STREAM_RECONNECT_WAIT_SEC): | ||
2193 | """ | ||
2194 | Streams direct message events for the logged-in user, as conversation events. | ||
2195 | """ | ||
2196 | return self.__stream('/api/v1/streaming/direct', listener, run_async=run_async, timeout=timeout, reconnect_async=reconnect_async, reconnect_async_wait_sec=reconnect_async_wait_sec) | ||
2197 | |||
2191 | ### | 2198 | ### |
2192 | # Internal helpers, dragons probably | 2199 | # Internal helpers, dragons probably |
2193 | ### | 2200 | ### |
diff --git a/mastodon/streaming.py b/mastodon/streaming.py index 1e1eefd..098863f 100644 --- a/mastodon/streaming.py +++ b/mastodon/streaming.py | |||
@@ -40,6 +40,11 @@ class StreamListener(object): | |||
40 | """A status has been deleted. status_id is the status' integer ID.""" | 40 | """A status has been deleted. status_id is the status' integer ID.""" |
41 | pass | 41 | pass |
42 | 42 | ||
43 | def on_conversation(self, conversation): | ||
44 | """A direct message (in the direct stream) has been received. conversation | ||
45 | contains the resulting conversation dict.""" | ||
46 | pass | ||
47 | |||
43 | def handle_heartbeat(self): | 48 | def handle_heartbeat(self): |
44 | """The server has sent us a keep-alive message. This callback may be | 49 | """The server has sent us a keep-alive message. This callback may be |
45 | useful to carry out periodic housekeeping tasks, or just to confirm | 50 | useful to carry out periodic housekeeping tasks, or just to confirm |
@@ -151,7 +156,7 @@ class CallbackStreamListener(StreamListener): | |||
151 | Simple callback stream handler class. | 156 | Simple callback stream handler class. |
152 | Can optionally additionally send local update events to a separate handler. | 157 | Can optionally additionally send local update events to a separate handler. |
153 | """ | 158 | """ |
154 | def __init__(self, update_handler = None, local_update_handler = None, delete_handler = None, notification_handler = None): | 159 | def __init__(self, update_handler = None, local_update_handler = None, delete_handler = None, notification_handler = None, conversation_handler = None): |
155 | super(CallbackStreamListener, self).__init__() | 160 | super(CallbackStreamListener, self).__init__() |
156 | self.update_handler = update_handler | 161 | self.update_handler = update_handler |
157 | self.local_update_handler = local_update_handler | 162 | self.local_update_handler = local_update_handler |
@@ -178,3 +183,7 @@ class CallbackStreamListener(StreamListener): | |||
178 | def on_notification(self, notification): | 183 | def on_notification(self, notification): |
179 | if self.notification_handler != None: | 184 | if self.notification_handler != None: |
180 | self.notification_handler(notification) | 185 | self.notification_handler(notification) |
186 | |||
187 | def on_conversation(self, conversation): | ||
188 | if self.conversation_handler != None: | ||
189 | self.conversation_handler(conversation) | ||