Add pubsub events by using twitter's namespace to separate services

This commit is contained in:
Manuel Cortez 2022-11-18 13:41:12 -06:00
parent 39fb5b4830
commit 2fe9c35c0b
No known key found for this signature in database
GPG Key ID: 9E0735CA15EFE790
5 changed files with 28 additions and 26 deletions

View File

@ -69,7 +69,7 @@ class DirectMessagesBuffer(base.BaseBuffer):
self.session.db["sent_direct_messages"] = sent_dms
user_ids = [item.message_create["sender_id"] for item in items]
self.session.save_users(user_ids)
pub.sendMessage("more-sent-dms", data=sent, account=self.session.db["user_name"])
pub.sendMessage("twitter.more_sent_dms", data=sent, account=self.session.db["user_name"])
selected = self.buffer.list.get_selected()
if self.session.settings["general"]["reverse_timelines"] == True:
for i in received:

View File

@ -101,25 +101,25 @@ class Controller(object):
""" Binds the local application events with their functions."""
log.debug("Binding other application events...")
pub.subscribe(self.buffer_title_changed, "buffer-title-changed")
pub.subscribe(self.manage_sent_dm, "sent-dm")
pub.subscribe(self.manage_sent_dm, "twitter.sent_dm")
widgetUtils.connect_event(self.view, widgetUtils.CLOSE_EVENT, self.exit_)
pub.subscribe(self.logout_account, "logout")
pub.subscribe(self.login_account, "login")
pub.subscribe(self.execute_action, "execute-action")
pub.subscribe(self.search_topic, "search")
pub.subscribe(self.update_sent_dms, "sent-dms-updated")
pub.subscribe(self.more_dms, "more-sent-dms")
pub.subscribe(self.manage_sent_tweets, "sent-tweet")
pub.subscribe(self.manage_new_tweet, "newTweet")
pub.subscribe(self.manage_friend, "friend")
pub.subscribe(self.manage_unfollowing, "unfollowing")
pub.subscribe(self.manage_favourite, "favourite")
pub.subscribe(self.manage_unfavourite, "unfavourite")
pub.subscribe(self.manage_blocked_user, "blocked-user")
pub.subscribe(self.manage_unblocked_user, "unblocked-user")
pub.subscribe(self.update_sent_dms, "twitter.sent_dms_updated")
pub.subscribe(self.more_dms, "twitter.more_sent_dms")
pub.subscribe(self.manage_sent_tweets, "twitter.sent_tweet")
pub.subscribe(self.manage_new_tweet, "twitter.new_tweet")
pub.subscribe(self.manage_friend, "twitter.friend")
pub.subscribe(self.manage_unfollowing, "twitter.unfollowing")
pub.subscribe(self.manage_favourite, "twitter.favourite")
pub.subscribe(self.manage_unfavourite, "twitter.unfavourite")
pub.subscribe(self.manage_blocked_user, "twitter.blocked_user")
pub.subscribe(self.manage_unblocked_user, "twitter.unblocked_user")
pub.subscribe(self.create_buffer, "createBuffer")
pub.subscribe(self.toggle_share_settings, "toggleShare")
pub.subscribe(self.restart_streaming, "restartStreaming")
pub.subscribe(self.restart_streaming, "twitter.restart_streaming")
pub.subscribe(self.invisible_shorcuts_changed, "invisible-shorcuts-changed")
pub.subscribe(self.create_account_buffer, "core.create_account")
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.show_hide, menuitem=self.view.show_hide)
@ -285,6 +285,8 @@ class Controller(object):
if handler != None and hasattr(handler, "create_buffers"):
handler.create_buffers(session=session, controller=self, createAccounts=False)
self.start_buffers(session)
if hasattr(session, "start_streaming"):
session.start_streaming()
def create_account_buffer(self, name, session_id, logged=False):
self.accounts.append(name)

View File

@ -29,42 +29,42 @@ class userActionsController(object):
def follow(self, user):
try:
self.session.twitter.create_friendship(screen_name=user )
pub.sendMessage("restartStreaming", session=self.session.session_id)
pub.sendMessage("twitter.restart_streaming", session=self.session.session_id)
except TweepyException as err:
output.speak("Error %s" % (str(err)), True)
def unfollow(self, user):
try:
id = self.session.twitter.destroy_friendship(screen_name=user )
pub.sendMessage("restartStreaming", session=self.session.session_id)
pub.sendMessage("twitter.restart_streaming", session=self.session.session_id)
except TweepyException as err:
output.speak("Error %s" % (str(err)), True)
def mute(self, user):
try:
id = self.session.twitter.create_mute(screen_name=user )
pub.sendMessage("restartStreaming", session=self.session.session_id)
pub.sendMessage("twitter.restart_streaming", session=self.session.session_id)
except TweepyException as err:
output.speak("Error %s" % (str(err)), True)
def unmute(self, user):
try:
id = self.session.twitter.destroy_mute(screen_name=user )
pub.sendMessage("restartStreaming", session=self.session.session_id)
pub.sendMessage("twitter.restart_streaming", session=self.session.session_id)
except TweepyException as err:
output.speak("Error %s" % (str(err)), True)
def report(self, user):
try:
id = self.session.twitter.report_spam(screen_name=user )
pub.sendMessage("restartStreaming", session=self.session.session_id)
pub.sendMessage("twitter.restart_streaming", session=self.session.session_id)
except TweepyException as err:
output.speak("Error %s" % (str(err)), True)
def block(self, user):
try:
id = self.session.twitter.create_block(screen_name=user )
pub.sendMessage("restartStreaming", session=self.session.session_id)
pub.sendMessage("twitter.restart_streaming", session=self.session.session_id)
except TweepyException as err:
output.speak("Error %s" % (str(err)), True)

View File

@ -107,7 +107,7 @@ class Session(base.baseSession):
incoming = incoming+1
self.db["direct_messages"] = objects
self.db["sent_direct_messages"] = sent_objects
pub.sendMessage("sent-dms-updated", total=sent, session_name=self.get_name())
pub.sendMessage("twitter.sent_dms_updated", total=sent, session_name=self.get_name())
return incoming
def __init__(self, *args, **kwargs):
@ -125,8 +125,8 @@ class Session(base.baseSession):
# If we wouldn't implement this approach, TWBlue would save permanently the "deleted user" object.
self.deleted_users = {}
self.type = "twitter"
pub.subscribe(self.handle_new_status, "newStatus")
pub.subscribe(self.handle_connected, "streamConnected")
pub.subscribe(self.handle_new_status, "twitter.new_status")
pub.subscribe(self.handle_connected, "twitter.stream_connected")
# @_require_configuration
def login(self, verify_credentials=True):
@ -600,7 +600,7 @@ class Session(base.baseSession):
status = self.check_quoted_status(status)
status = self.check_long_tweet(status)
# Send it to the main controller object.
pub.sendMessage("newTweet", data=status, session_name=self.get_name(), _buffers=buffers_to_send)
pub.sendMessage("twitter.new_tweet", data=status, session_name=self.get_name(), _buffers=buffers_to_send)
def check_streams(self):
if config.app["app-settings"]["no_streaming"]:
@ -666,7 +666,7 @@ class Session(base.baseSession):
else:
sent_dms.insert(0, item)
self.db["sent_direct_messages"] = sent_dms
pub.sendMessage("sent-dm", data=item, session_name=self.get_name())
pub.sendMessage("twitter.sent_dm", data=item, session_name=self.get_name())
def get_name(self):
if self.logged:

View File

@ -33,7 +33,7 @@ class Stream(tweepy.Stream):
log.debug("Streaming listener started with {} users to follow.".format(len(self.users)))
def on_connect(self):
pub.sendMessage("streamConnected", session_name=self.session_name)
pub.sendMessage("twitter.stream_connected", session_name=self.session_name)
def on_exception(self, ex):
log.exception("Exception received on streaming endpoint for session {}".format(self.session_name))
@ -44,4 +44,4 @@ class Stream(tweepy.Stream):
if status.in_reply_to_user_id_str != None and status.in_reply_to_user_id_str not in self.users and status.user.id != self.user_id:
return
if status.user.id_str in self.users:
pub.sendMessage("newStatus", status=status, session_name=self.session_name)
pub.sendMessage("twitter.new_status", status=status, session_name=self.session_name)