Implemented get_more_items to dm's. Closes #235

This commit is contained in:
Manuel Cortez 2018-07-19 12:27:01 -05:00
parent d8da78e22d
commit b4020d0f95
2 changed files with 25 additions and 6 deletions

View File

@ -727,7 +727,27 @@ class baseBufferController(bufferController):
class directMessagesController(baseBufferController): class directMessagesController(baseBufferController):
def get_more_items(self): def get_more_items(self):
output.speak(_(u"This action is not supported for this buffer"), True) try:
items = self.session.get_more_items(self.function, dm=True, name=self.name, count=self.session.settings["general"]["max_tweets_per_call"], cursor=self.session.db[self.name]["cursor"], *self.args, **self.kwargs)
except TwythonError as e:
output.speak(e.message, True)
return
for i in items:
if self.session.settings["general"]["reverse_timelines"] == False:
self.session.db[self.name]["items"].insert(0, i)
else:
self.session.db[self.name]["items"].append(i)
selected = self.buffer.list.get_selected()
if self.session.settings["general"]["reverse_timelines"] == True:
for i in items:
tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"], self.session.settings["general"]["show_screen_names"], self.session)
self.buffer.list.insert_item(True, *tweet)
self.buffer.list.select_item(selected)
else:
for i in items:
tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"], self.session.settings["general"]["show_screen_names"], self.session)
self.buffer.list.insert_item(True, *tweet)
output.speak(_(u"%s items retrieved") % (len(items)), True)
def get_tweet(self): def get_tweet(self):
tweet = self.session.db[self.name]["items"][self.buffer.list.get_selected()] tweet = self.session.db[self.name]["items"][self.buffer.list.get_selected()]
@ -956,7 +976,6 @@ class peopleBufferController(baseBufferController):
else: else:
self.session.db[self.name]["items"].append(i) self.session.db[self.name]["items"].append(i)
selected = self.buffer.list.get_selected() selected = self.buffer.list.get_selected()
# self.put_items_on_list(len(items))
if self.session.settings["general"]["reverse_timelines"] == True: if self.session.settings["general"]["reverse_timelines"] == True:
for i in items: for i in items:
tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"], self.session) tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"], self.session)
@ -966,9 +985,6 @@ class peopleBufferController(baseBufferController):
for i in items: for i in items:
tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"], self.session) tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"], self.session)
self.buffer.list.insert_item(True, *tweet) self.buffer.list.insert_item(True, *tweet)
# self.buffer.list.select_item(selection)
# else:
# self.buffer.list.select_item(selection-elements)
output.speak(_(u"%s items retrieved") % (len(items)), True) output.speak(_(u"%s items retrieved") % (len(items)), True)
def put_items_on_list(self, number_of_items): def put_items_on_list(self, number_of_items):

View File

@ -187,7 +187,7 @@ class Session(object):
self.twitter.verify_authorisation(self.settings, pincode) self.twitter.verify_authorisation(self.settings, pincode)
self.authorisation_dialog.Destroy() self.authorisation_dialog.Destroy()
def get_more_items(self, update_function, users=False, name=None, *args, **kwargs): def get_more_items(self, update_function, users=False, dm=False, name=None, *args, **kwargs):
results = [] results = []
data = getattr(self.twitter.twitter, update_function)(*args, **kwargs) data = getattr(self.twitter.twitter, update_function)(*args, **kwargs)
if users == True: if users == True:
@ -196,6 +196,9 @@ class Session(object):
for i in data["users"]: results.append(i) for i in data["users"]: results.append(i)
elif type(data) == list: elif type(data) == list:
results.extend(data[1:]) results.extend(data[1:])
elif dm == True:
self.db[name]["cursor"] = data["next_cursor"]
for i in data["events"]: results.append(i)
else: else:
results.extend(data[1:]) results.extend(data[1:])
return results return results