mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-22 11:18:08 -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.char_limit = 500
|
||||
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")
|
||||
|
||||
def login(self, verify_credentials=True):
|
||||
@ -149,6 +150,19 @@ class Session(base.baseSession):
|
||||
self.db[name] = objects
|
||||
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):
|
||||
finished = False
|
||||
tries = 0
|
||||
@ -246,6 +260,17 @@ class Session(base.baseSession):
|
||||
buffers.remove(b)
|
||||
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):
|
||||
# Discard processing the notification if the streaming sends a tweet for another account.
|
||||
if self.get_name() != session_name:
|
||||
|
@ -12,6 +12,9 @@ class StreamListener(mastodon.StreamListener):
|
||||
def on_update(self, status):
|
||||
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):
|
||||
pub.sendMessage("mastodon.conversation_received", conversation=conversation, session_name=self.session_name)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user