Added sent dm buffer working. Closes #233. Needs testing

This commit is contained in:
Manuel Cortez 2018-08-13 11:26:55 -05:00
parent 2f0b20558e
commit 04ac629b51
3 changed files with 62 additions and 6 deletions

View File

@ -398,7 +398,7 @@ class baseBufferController(bufferController):
def put_items_on_list(self, number_of_items):
# Define the list we're going to use as cursored stuff are a bit different.
if self.name != "direct_messages":
if self.name != "direct_messages" and self.name != "sent_direct_messages":
list_to_use = self.session.db[self.name]
else:
list_to_use = self.session.db[self.name]["items"]
@ -746,19 +746,32 @@ class directMessagesController(baseBufferController):
except TwythonError as e:
output.speak(e.message, True)
return
sent = []
for i in items:
if self.session.settings["general"]["reverse_timelines"] == False:
self.session.db[self.name]["items"].insert(0, i)
if i["message_create"]["sender_id"] == self.session.db["user_id"]:
if self.session.settings["general"]["reverse_timelines"] == False:
self.session.db["sent_direct_messages"]["items"].insert(0, i)
else:
self.session.db["sent_direct_messages"]["items"].append(i)
sent.append(i)
else:
self.session.db[self.name]["items"].append(i)
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)
pub.sendMessage("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 items:
if i["message_create"]["sender_id"] == self.session.db["user_id"]:
continue
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:
if i["message_create"]["sender_id"] == self.session.db["user_id"]:
continue
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)
@ -812,9 +825,19 @@ class sentDirectMessagesController(directMessagesController):
def get_more_items(self):
output.speak(_(u"Getting more items cannot be done in this buffer. Use the direct messages buffer instead."))
def start_stream(self):
def start_stream(self, *args, **kwargs):
pass
def put_more_items(self, items):
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)
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)
class listBufferController(baseBufferController):
def __init__(self, parent, function, name, sessionObject, account, sound=None, bufferType=None, list_id=None, *args, **kwargs):
super(listBufferController, self).__init__(parent, function, name, sessionObject, account, sound=None, bufferType=None, *args, **kwargs)

View File

@ -140,6 +140,8 @@ class Controller(object):
pub.subscribe(self.create_new_buffer, "create-new-buffer")
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")
if system == "Windows":
pub.subscribe(self.invisible_shorcuts_changed, "invisible-shorcuts-changed")
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.show_hide, menuitem=self.view.show_hide)
@ -1685,6 +1687,16 @@ class Controller(object):
return
msg = messages.viewTweet(text["ParsedText"], [], False)
def update_sent_dms(self, total, account):
sent_dms = self.search_buffer("sent_direct_messages", account)
if sent_dms != None:
sent_dms.put_items_on_list(total)
def more_dms(self, data, account):
sent_dms = self.search_buffer("sent_direct_messages", account)
if sent_dms != None:
sent_dms.put_more_items(data)
def save_data_in_db(self):
for i in session_.sessions:
session_.sessions[i].shelve()

View File

@ -94,7 +94,8 @@ class Session(object):
name str: The name for the buffer stored in the dictionary.
data list: A list with items and some information about cursors.
returns the number of items that have been added in this execution"""
if name == "direct_messages":
return self.order_direct_messages(data)
num = 0
if self.db.has_key(name) == False:
self.db[name] = {}
@ -107,6 +108,26 @@ class Session(object):
num = num+1
return num
def order_direct_messages(self, data):
incoming = 0
sent = 0
if self.db.has_key("direct_messages") == False:
self.db["direct_messages"] = {}
self.db["direct_messages"]["items"] = []
for i in data:
if i["message_create"]["sender_id"] == self.db["user_id"]:
if utils.find_item(i["id"], self.db["sent_direct_messages"]["items"]) == None:
if self.settings["general"]["reverse_timelines"] == False: self.db["sent_direct_messages"]["items"].append(i)
else: self.db["sent_direct_messages"]["items"].insert(0, i)
sent = sent+1
else:
if utils.find_item(i["id"], self.db["direct_messages"]["items"]) == None:
if self.settings["general"]["reverse_timelines"] == False: self.db["direct_messages"]["items"].append(i)
else: self.db["direct_messages"]["items"].insert(0, i)
incoming = incoming+1
pub.sendMessage("sent-dms-updated", total=sent, account=self.db["user_name"])
return incoming
def __init__(self, session_id):
""" session_id (str): The name of the folder inside the config directory where the session is located."""