mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-22 19:28:09 -06:00
Initial support for edited statuses in Streaming API. Only Works in invisible interface for now
This commit is contained in:
parent
b6dd539dc6
commit
d177ef5be2
@ -31,6 +31,7 @@ class Session(base.baseSession):
|
|||||||
self.db["pagination_info"] = dict()
|
self.db["pagination_info"] = dict()
|
||||||
self.char_limit = 500
|
self.char_limit = 500
|
||||||
pub.subscribe(self.on_status, "mastodon.status_received")
|
pub.subscribe(self.on_status, "mastodon.status_received")
|
||||||
|
pub.subscribe(self.on_status_updated, "mastodon.status_updated")
|
||||||
pub.subscribe(self.on_notification, "mastodon.notification_received")
|
pub.subscribe(self.on_notification, "mastodon.notification_received")
|
||||||
|
|
||||||
def login(self, verify_credentials=True):
|
def login(self, verify_credentials=True):
|
||||||
@ -149,6 +150,19 @@ class Session(base.baseSession):
|
|||||||
self.db[name] = objects
|
self.db[name] = objects
|
||||||
return num
|
return num
|
||||||
|
|
||||||
|
def update_item(self, name, item):
|
||||||
|
if name not in self.db:
|
||||||
|
return False
|
||||||
|
items = self.db[name]
|
||||||
|
if type(items) != list:
|
||||||
|
return False
|
||||||
|
# determine item position in buffer.
|
||||||
|
item_position = next((x for x in range(len(items)) if items[x].id == item.id), None)
|
||||||
|
if item_position != None:
|
||||||
|
self.db[name][item_position] = item
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def api_call(self, call_name, action="", _sound=None, report_success=False, report_failure=True, preexec_message="", *args, **kwargs):
|
def api_call(self, call_name, action="", _sound=None, report_success=False, report_failure=True, preexec_message="", *args, **kwargs):
|
||||||
finished = False
|
finished = False
|
||||||
tries = 0
|
tries = 0
|
||||||
@ -246,6 +260,17 @@ class Session(base.baseSession):
|
|||||||
buffers.remove(b)
|
buffers.remove(b)
|
||||||
pub.sendMessage("mastodon.new_item", session_name=self.get_name(), item=status, _buffers=buffers)
|
pub.sendMessage("mastodon.new_item", session_name=self.get_name(), item=status, _buffers=buffers)
|
||||||
|
|
||||||
|
def on_status_updated(self, status, session_name):
|
||||||
|
# Discard processing the status if the streaming sends a tweet for another account.
|
||||||
|
if self.get_name() != session_name:
|
||||||
|
return
|
||||||
|
buffers = []
|
||||||
|
for b in list(self.db.keys()):
|
||||||
|
updated = self.update_item(b, status)
|
||||||
|
if updated:
|
||||||
|
buffers.append(b)
|
||||||
|
pub.sendMessage("mastodon.updated_item", session_name=self.get_name(), item=status, _buffers=buffers)
|
||||||
|
|
||||||
def on_notification(self, notification, session_name):
|
def on_notification(self, notification, session_name):
|
||||||
# Discard processing the notification if the streaming sends a tweet for another account.
|
# Discard processing the notification if the streaming sends a tweet for another account.
|
||||||
if self.get_name() != session_name:
|
if self.get_name() != session_name:
|
||||||
|
@ -12,6 +12,9 @@ class StreamListener(mastodon.StreamListener):
|
|||||||
def on_update(self, status):
|
def on_update(self, status):
|
||||||
pub.sendMessage("mastodon.status_received", status=status, session_name=self.session_name)
|
pub.sendMessage("mastodon.status_received", status=status, session_name=self.session_name)
|
||||||
|
|
||||||
|
def on_status_update(self, status):
|
||||||
|
pub.sendMessage("mastodon.status_updated", status=status, session_name=self.session_name)
|
||||||
|
|
||||||
def on_conversation(self, conversation):
|
def on_conversation(self, conversation):
|
||||||
pub.sendMessage("mastodon.conversation_received", conversation=conversation, session_name=self.session_name)
|
pub.sendMessage("mastodon.conversation_received", conversation=conversation, session_name=self.session_name)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user