mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-26 12:53:12 -06:00
Moved some interactions with buffers from main controller to the buffer classes themselves
This commit is contained in:
parent
cf9add1fc9
commit
23af944fba
@ -580,3 +580,30 @@ class BaseBuffer(base.Buffer):
|
||||
url = self.get_item_url()
|
||||
output.speak(_(u"Opening item in web browser..."))
|
||||
webbrowser.open(url)
|
||||
|
||||
def add_to_favorites(self):
|
||||
id = self.get_tweet().id
|
||||
call_threaded(self.session.api_call, call_name="create_favorite", _sound="favourite.ogg", id=id)
|
||||
|
||||
def remove_from_favorites(self):
|
||||
id = self.get_tweet().id
|
||||
call_threaded(self.session.api_call, call_name="destroy_favorite", id=id)
|
||||
|
||||
def toggle_favorite(self):
|
||||
id = self.get_tweet().id
|
||||
tweet = self.session.twitter.get_status(id=id, include_ext_alt_text=True, tweet_mode="extended")
|
||||
if tweet.favorited == False:
|
||||
call_threaded(self.session.api_call, call_name="create_favorite", _sound="favourite.ogg", id=id)
|
||||
else:
|
||||
call_threaded(self.session.api_call, call_name="destroy_favorite", id=id)
|
||||
|
||||
def view_item(self):
|
||||
if self.type == "dm" or self.name == "direct_messages":
|
||||
non_tweet = self.get_formatted_message()
|
||||
item = self.get_right_tweet()
|
||||
original_date = arrow.get(int(item.created_timestamp))
|
||||
date = original_date.shift(seconds=self.session.db["utc_offset"]).format(_(u"MMM D, YYYY. H:m"), locale=languageHandler.getLanguage())
|
||||
msg = messages.viewTweet(non_tweet, [], False, date=date)
|
||||
else:
|
||||
tweet, tweetsList = self.get_full_tweet()
|
||||
msg = messages.viewTweet(tweet, tweetsList, utc_offset=self.session.db["utc_offset"], item_url=self.get_item_url())
|
@ -162,3 +162,10 @@ class SentDirectMessagesBuffer(DirectMessagesBuffer):
|
||||
dm = self.get_right_tweet()
|
||||
t = templates.render_dm(dm, template, self.session, relative_times=self.session.settings["general"]["relative_times"], offset_seconds=self.session.db["utc_offset"])
|
||||
return t
|
||||
|
||||
def view_item(self):
|
||||
non_tweet = self.get_formatted_message()
|
||||
item = self.get_right_tweet()
|
||||
original_date = arrow.get(int(item.created_timestamp))
|
||||
date = original_date.shift(seconds=self.session.db["utc_offset"]).format(_(u"MMM D, YYYY. H:m"), locale=languageHandler.getLanguage())
|
||||
msg = messages.viewTweet(non_tweet, [], False, date=date)
|
||||
|
@ -247,3 +247,8 @@ class PeopleBuffer(base.BaseBuffer):
|
||||
tweet = self.get_tweet()
|
||||
url = "https://twitter.com/{screen_name}".format(screen_name=tweet.screen_name)
|
||||
return url
|
||||
|
||||
def view_item(self):
|
||||
item_url = self.get_item_url()
|
||||
non_tweet = self.get_formatted_message()
|
||||
msg = messages.viewTweet(non_tweet, [], False, item_url=item_url)
|
@ -573,73 +573,43 @@ class Controller(object):
|
||||
|
||||
def post_tweet(self, event=None):
|
||||
buffer = self.get_best_buffer()
|
||||
if hasattr(buffer, "post_status"):
|
||||
buffer.post_status()
|
||||
|
||||
def post_reply(self, *args, **kwargs):
|
||||
buffer = self.get_current_buffer()
|
||||
if buffer.name == "direct_messages":
|
||||
buffer.send_message()
|
||||
else:
|
||||
buffer.reply()
|
||||
if hasattr(buffer, "reply"):
|
||||
return buffer.reply()
|
||||
|
||||
def send_dm(self, *args, **kwargs):
|
||||
buffer = self.get_current_buffer()
|
||||
if hasattr(buffer, "send_message"):
|
||||
buffer.send_message()
|
||||
|
||||
def post_retweet(self, *args, **kwargs):
|
||||
buffer = self.get_current_buffer()
|
||||
if buffer.type == "dm" or buffer.type == "people" or buffer.type == "events":
|
||||
return
|
||||
else:
|
||||
buffer.share_item()
|
||||
if hasattr(buffer, "share_item"):
|
||||
return buffer.share_item()
|
||||
|
||||
def add_to_favourites(self, *args, **kwargs):
|
||||
buffer = self.get_current_buffer()
|
||||
if buffer.type == "dm" or buffer.type == "people" or buffer.type == "events":
|
||||
return
|
||||
else:
|
||||
id = buffer.get_tweet().id
|
||||
call_threaded(buffer.session.api_call, call_name="create_favorite", _sound="favourite.ogg", id=id)
|
||||
if hasattr(buffer, "add_to_favorites"):
|
||||
return buffer.add_to_favorites()
|
||||
|
||||
def remove_from_favourites(self, *args, **kwargs):
|
||||
buffer = self.get_current_buffer()
|
||||
if buffer.type == "dm" or buffer.type == "people" or buffer.type == "events":
|
||||
return
|
||||
else:
|
||||
id = buffer.get_tweet().id
|
||||
call_threaded(buffer.session.api_call, call_name="destroy_favorite", id=id)
|
||||
if hasattr(buffer, "remove_from_favorites"):
|
||||
return buffer.remove_from_favorites()
|
||||
|
||||
def toggle_like(self, *args, **kwargs):
|
||||
buffer = self.get_current_buffer()
|
||||
if buffer.type == "dm" or buffer.type == "people" or buffer.type == "events":
|
||||
return
|
||||
else:
|
||||
id = buffer.get_tweet().id
|
||||
tweet = buffer.session.twitter.get_status(id=id, include_ext_alt_text=True, tweet_mode="extended")
|
||||
if tweet.favorited == False:
|
||||
call_threaded(buffer.session.api_call, call_name="create_favorite", _sound="favourite.ogg", id=id)
|
||||
else:
|
||||
call_threaded(buffer.session.api_call, call_name="destroy_favorite", id=id)
|
||||
if hasattr(buffer, "toggle_favorite"):
|
||||
return buffer.toggle_favorite()
|
||||
|
||||
def view_item(self, *args, **kwargs):
|
||||
buffer = self.get_current_buffer()
|
||||
if buffer.type == "account" or buffer.type == "empty":
|
||||
return
|
||||
elif buffer.type == "baseBuffer" or buffer.type == "favourites_timeline" or buffer.type == "list" or buffer.type == "search":
|
||||
tweet, tweetsList = buffer.get_full_tweet()
|
||||
msg = messages.viewTweet(tweet, tweetsList, utc_offset=buffer.session.db["utc_offset"], item_url=buffer.get_item_url())
|
||||
elif buffer.type == "dm":
|
||||
non_tweet = buffer.get_formatted_message()
|
||||
item = buffer.get_right_tweet()
|
||||
original_date = arrow.get(int(item.created_timestamp))
|
||||
date = original_date.shift(seconds=buffer.session.db["utc_offset"]).format(_(u"MMM D, YYYY. H:m"), locale=languageHandler.getLanguage())
|
||||
msg = messages.viewTweet(non_tweet, [], False, date=date)
|
||||
else:
|
||||
item_url = ""
|
||||
if hasattr(buffer, "get_item_url"):
|
||||
item_url = buffer.get_item_url()
|
||||
non_tweet = buffer.get_formatted_message()
|
||||
msg = messages.viewTweet(non_tweet, [], False, item_url=item_url)
|
||||
if hasattr(buffer, "view_item"):
|
||||
return buffer.view_item()
|
||||
|
||||
def open_in_browser(self, *args, **kwargs):
|
||||
buffer = self.get_current_buffer()
|
||||
|
Loading…
Reference in New Issue
Block a user