mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-23 03:38:08 -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()
|
url = self.get_item_url()
|
||||||
output.speak(_(u"Opening item in web browser..."))
|
output.speak(_(u"Opening item in web browser..."))
|
||||||
webbrowser.open(url)
|
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()
|
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"])
|
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
|
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()
|
tweet = self.get_tweet()
|
||||||
url = "https://twitter.com/{screen_name}".format(screen_name=tweet.screen_name)
|
url = "https://twitter.com/{screen_name}".format(screen_name=tweet.screen_name)
|
||||||
return url
|
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):
|
def post_tweet(self, event=None):
|
||||||
buffer = self.get_best_buffer()
|
buffer = self.get_best_buffer()
|
||||||
buffer.post_status()
|
if hasattr(buffer, "post_status"):
|
||||||
|
buffer.post_status()
|
||||||
|
|
||||||
def post_reply(self, *args, **kwargs):
|
def post_reply(self, *args, **kwargs):
|
||||||
buffer = self.get_current_buffer()
|
buffer = self.get_current_buffer()
|
||||||
if buffer.name == "direct_messages":
|
if hasattr(buffer, "reply"):
|
||||||
buffer.send_message()
|
return buffer.reply()
|
||||||
else:
|
|
||||||
buffer.reply()
|
|
||||||
|
|
||||||
def send_dm(self, *args, **kwargs):
|
def send_dm(self, *args, **kwargs):
|
||||||
buffer = self.get_current_buffer()
|
buffer = self.get_current_buffer()
|
||||||
buffer.send_message()
|
if hasattr(buffer, "send_message"):
|
||||||
|
buffer.send_message()
|
||||||
|
|
||||||
def post_retweet(self, *args, **kwargs):
|
def post_retweet(self, *args, **kwargs):
|
||||||
buffer = self.get_current_buffer()
|
buffer = self.get_current_buffer()
|
||||||
if buffer.type == "dm" or buffer.type == "people" or buffer.type == "events":
|
if hasattr(buffer, "share_item"):
|
||||||
return
|
return buffer.share_item()
|
||||||
else:
|
|
||||||
buffer.share_item()
|
|
||||||
|
|
||||||
def add_to_favourites(self, *args, **kwargs):
|
def add_to_favourites(self, *args, **kwargs):
|
||||||
buffer = self.get_current_buffer()
|
buffer = self.get_current_buffer()
|
||||||
if buffer.type == "dm" or buffer.type == "people" or buffer.type == "events":
|
if hasattr(buffer, "add_to_favorites"):
|
||||||
return
|
return buffer.add_to_favorites()
|
||||||
else:
|
|
||||||
id = buffer.get_tweet().id
|
|
||||||
call_threaded(buffer.session.api_call, call_name="create_favorite", _sound="favourite.ogg", id=id)
|
|
||||||
|
|
||||||
def remove_from_favourites(self, *args, **kwargs):
|
def remove_from_favourites(self, *args, **kwargs):
|
||||||
buffer = self.get_current_buffer()
|
buffer = self.get_current_buffer()
|
||||||
if buffer.type == "dm" or buffer.type == "people" or buffer.type == "events":
|
if hasattr(buffer, "remove_from_favorites"):
|
||||||
return
|
return buffer.remove_from_favorites()
|
||||||
else:
|
|
||||||
id = buffer.get_tweet().id
|
|
||||||
call_threaded(buffer.session.api_call, call_name="destroy_favorite", id=id)
|
|
||||||
|
|
||||||
def toggle_like(self, *args, **kwargs):
|
def toggle_like(self, *args, **kwargs):
|
||||||
buffer = self.get_current_buffer()
|
buffer = self.get_current_buffer()
|
||||||
if buffer.type == "dm" or buffer.type == "people" or buffer.type == "events":
|
if hasattr(buffer, "toggle_favorite"):
|
||||||
return
|
return buffer.toggle_favorite()
|
||||||
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)
|
|
||||||
|
|
||||||
def view_item(self, *args, **kwargs):
|
def view_item(self, *args, **kwargs):
|
||||||
buffer = self.get_current_buffer()
|
buffer = self.get_current_buffer()
|
||||||
if buffer.type == "account" or buffer.type == "empty":
|
if hasattr(buffer, "view_item"):
|
||||||
return
|
return buffer.view_item()
|
||||||
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)
|
|
||||||
|
|
||||||
def open_in_browser(self, *args, **kwargs):
|
def open_in_browser(self, *args, **kwargs):
|
||||||
buffer = self.get_current_buffer()
|
buffer = self.get_current_buffer()
|
||||||
|
Loading…
Reference in New Issue
Block a user