Changed how replies works in TWBlue

This commit is contained in:
Manuel Cortez 2016-12-09 10:15:39 -06:00
parent ca0f00e27d
commit 1351712db4
5 changed files with 117 additions and 49 deletions

View File

@ -479,23 +479,23 @@ class baseBufferController(bufferController):
tweet = self.get_right_tweet()
screen_name = tweet["user"]["screen_name"]
id = tweet["id"]
users = utils.get_all_mentioned(tweet, self.session.db)
message = messages.reply(self.session, _(u"Reply"), _(u"Reply to %s") % (screen_name,), "", twishort_enabled=self.session.settings["mysc"]["twishort_enabled"], users=users)
users = utils.get_all_mentioned(tweet, self.session.db, field="screen_name")
ids = utils.get_all_mentioned(tweet, self.session.db, field="id_str")
message = messages.reply(self.session, _(u"Reply"), _(u"Reply to %s") % (screen_name,), "", twishort_enabled=self.session.settings["mysc"]["twishort_enabled"], users=users, ids=ids)
if message.message.get_response() == widgetUtils.OK:
self.session.settings["mysc"]["twishort_enabled"] = message.message.long_tweet.GetValue()
self.session.settings["mysc"]["mention_all"] = message.message.mentionAll.GetValue()
excluded_ids = message.get_ids()
text = message.message.get_text()
if message.message.mentionAll.GetValue() == False:
text = u"@{0} {1}".format(screen_name, text)
if len(text) > 140 and message.message.get("long_tweet") == True:
if message.image == None:
text = twishort.create_tweet(self.session.settings["twitter"]["user_key"], self.session.settings["twitter"]["user_secret"], text)
else:
text = twishort.create_tweet(self.session.settings["twitter"]["user_key"], self.session.settings["twitter"]["user_secret"], text, 1)
if message.image == None:
call_threaded(self.session.api_call, call_name="update_status", _sound="reply_send.ogg", in_reply_to_status_id=id, status=text, auto_populate_reply_metadata=message.message.mentionAll.GetValue())
call_threaded(self.session.api_call, call_name="update_status", _sound="reply_send.ogg", in_reply_to_status_id=id, status=text, auto_populate_reply_metadata=True, exclude_reply_user_ids=excluded_ids)
else:
call_threaded(self.session.api_call, call_name="update_status_with_media", _sound="reply_send.ogg", in_reply_to_status_id=id, status=text, media=message.file, auto_populate_reply_metadata=message.message.mentionAll.GetValue())
call_threaded(self.session.api_call, call_name="update_status_with_media", _sound="reply_send.ogg", in_reply_to_status_id=id, status=text, media=message.file, auto_populate_reply_metadata=True, exclude_reply_user_ids=excluded_ids)
if hasattr(message.message, "destroy"): message.message.destroy()
@_tweets_exist

View File

@ -1324,6 +1324,7 @@ class Controller(object):
def manage_stream_errors(self, session):
log.error(" Restarting %s session streams. It will be destroyed" % (session,))
s = session_.sessions[session]
try:
if hasattr(s, "main_stream"):
s.main_stream.disconnect()
log.error("main stream disconnected")
@ -1331,11 +1332,9 @@ class Controller(object):
if hasattr(s, "timelinesStream"):
s.timelinesStream.disconnect()
del s.timelinesStream
except AttributeError:
pass
s.counter = 0
# s.reconnection_function_active = False
# for i in self.buffers:
# if i.invisible == True and i.session.session_id == s.session_id and i.type != "people":
# i.start_stream()
# s.listen_stream_error()
def check_connection(self):

View File

@ -18,12 +18,12 @@ from twitter import utils
class basicTweet(object):
""" This class handles the tweet main features. Other classes should derive from this class."""
def __init__(self, session, title, caption, text, messageType="tweet", max=140):
def __init__(self, session, title, caption, text, messageType="tweet", max=140, *args, **kwargs):
super(basicTweet, self).__init__()
self.max = max
self.title = title
self.session = session
self.message = getattr(message, messageType)(title, caption, text)
self.message = getattr(message, messageType)(title, caption, text, *args, **kwargs)
widgetUtils.connect_event(self.message.spellcheck, widgetUtils.BUTTON_PRESSED, self.spellcheck)
widgetUtils.connect_event(self.message.attach, widgetUtils.BUTTON_PRESSED, self.attach)
# if system == "Windows":
@ -125,8 +125,8 @@ class basicTweet(object):
self.message.text_focus()
class tweet(basicTweet):
def __init__(self, session, title, caption, text, twishort_enabled, messageType="tweet", max=140):
super(tweet, self).__init__(session, title, caption, text, messageType, max)
def __init__(self, session, title, caption, text, twishort_enabled, messageType="tweet", max=140, *args, **kwargs):
super(tweet, self).__init__(session, title, caption, text, messageType, max, *args, **kwargs)
self.image = None
widgetUtils.connect_event(self.message.upload_image, widgetUtils.BUTTON_PRESSED, self.upload_image)
widgetUtils.connect_event(self.message.autocompletionButton, widgetUtils.BUTTON_PRESSED, self.autocomplete_users)
@ -145,21 +145,35 @@ class tweet(basicTweet):
c.show_menu()
class reply(tweet):
def __init__(self, session, title, caption, text, twishort_enabled, users=None):
super(reply, self).__init__(session, title, caption, text, twishort_enabled, messageType="reply")
self.message.mentionAll.SetValue(True)
if len(users) > 1:
# widgetUtils.connect_event(self.message.mentionAll, widgetUtils.CHECKBOX, self.mention_all)
def __init__(self, session, title, caption, text, twishort_enabled, users=[], ids=[]):
super(reply, self).__init__(session, title, caption, text, twishort_enabled, messageType="reply", users=users)
self.ids = ids
if len(users) > 0:
widgetUtils.connect_event(self.message.mentionAll, widgetUtils.CHECKBOX, self.mention_all)
self.message.enable_button("mentionAll")
self.message.mentionAll.SetValue(self.session.settings["mysc"]["mention_all"])
if self.message.mentionAll.GetValue() == True:
self.mention_all()
self.message.set_cursor_at_end()
self.text_processor()
def mention_all(self, *args, **kwargs):
self.message.set_text(self.message.get_text()+self.users)
self.message.set_cursor_at_end()
self.message.text_focus()
self.text_processor()
if self.message.mentionAll.GetValue() == True:
for i in self.message.checkboxes:
i.SetValue(True)
i.Hide()
else:
for i in self.message.checkboxes:
i.SetValue(False)
i.Show()
def get_ids(self):
excluded_ids = ""
for i in xrange(0, len(self.message.checkboxes)):
if self.message.checkboxes[i].GetValue() == False:
excluded_ids = excluded_ids + "{0},".format(self.ids[i],)
return excluded_ids
class dm(basicTweet):
def __init__(self, session, title, caption, text):

View File

@ -66,14 +66,14 @@ def is_geocoded(tweet):
if tweet.has_key("coordinates") and tweet["coordinates"] != None:
return True
def get_all_mentioned(tweet, conf):
def get_all_mentioned(tweet, conf, field="screen_name"):
""" Gets all users that has been mentioned."""
string = []
results = []
for i in tweet["entities"]["user_mentions"]:
if i["screen_name"] != conf["user_name"] and i["screen_name"] != tweet["user"]["screen_name"]:
if i["id"] not in string:
string.append(i["id_str"])
return " ".join(string)+" "
if i[field] not in results:
results.append(i[field])
return results
def get_all_users(tweet, conf):
string = []

View File

@ -5,6 +5,7 @@ import widgetUtils
class textLimited(widgetUtils.BaseDialog):
def __init__(self, *args, **kwargs):
super(textLimited, self).__init__(parent=None, *args, **kwargs)
def createTextArea(self, message="", text=""):
if not hasattr(self, "panel"):
self.panel = wx.Panel(self)
@ -106,11 +107,10 @@ class tweet(textLimited):
self.SetAcceleratorTable(self.accel_tbl)
self.panel.SetSizer(self.mainBox)
def __init__(self, title, message, text):
def __init__(self, title, message, text, *args, **kwargs):
super(tweet, self).__init__()
self.shift=False
self.createControls(message, title, text)
# self.onTimer(wx.EVT_CHAR_HOOK)
self.SetClientSize(self.mainBox.CalcMin())
def get_image(self):
@ -166,7 +166,7 @@ class retweet(tweet):
self.SetAcceleratorTable(self.accel_tbl)
self.panel.SetSizer(self.mainBox)
def __init__(self, title, message, text):
def __init__(self, title, message, text, *args, **kwargs):
super(tweet, self).__init__()
self.createControls(message, title, text)
# self.onTimer(wx.EVT_CHAR_HOOK)
@ -218,7 +218,7 @@ class dm(textLimited):
self.panel.SetSizer(self.mainBox)
self.SetClientSize(self.mainBox.CalcMin())
def __init__(self, title, message, users):
def __init__(self, title, message, users, *args, **kwargs):
super(dm, self).__init__()
self.createControls(message, title, users)
# self.onTimer(wx.EVT_CHAR_HOOK)
@ -230,22 +230,77 @@ class dm(textLimited):
def set_user(self, user):
return self.cb.SetValue(user)
class reply(tweet):
def __init__(self, title, message, text):
super(reply, self).__init__(message, title, text)
self.text.SetInsertionPoint(len(self.text.GetValue()))
self.mentionAll = wx.CheckBox(self, -1, _(u"&Mention to all"), size=wx.DefaultSize)
class reply(textLimited):
def get_image(self):
openFileDialog = wx.FileDialog(self, _(u"Select the picture to be uploaded"), "", "", _("Image files (*.png, *.jpg, *.gif)|*.png; *.jpg; *.gif"), wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
if openFileDialog.ShowModal() == wx.ID_CANCEL:
return None
return open(openFileDialog.GetPath(), "rb")
def createControls(self, title, message, text):
self.mainBox = wx.BoxSizer(wx.VERTICAL)
self.createTextArea(message, text)
self.mainBox.Add(self.textBox, 0, wx.ALL, 5)
self.usersbox = wx.BoxSizer(wx.VERTICAL)
self.mentionAll = wx.CheckBox(self.panel, -1, _(u"&Mention to all"), size=wx.DefaultSize)
self.mentionAll.Disable()
self.buttonsBox1.Add(self.mentionAll, 0, wx.ALL, 5)
self.buttonsBox1.Layout()
self.mainBox.Layout()
self.usersbox.Add(self.mentionAll, 0, wx.ALL, 5)
self.checkboxes = []
for i in self.users:
user_checkbox = wx.CheckBox(self.panel, -1, "@"+i, size=wx.DefaultSize)
self.checkboxes.append(user_checkbox)
self.usersbox.Add(self.checkboxes[-1], 0, wx.ALL, 5)
self.mainBox.Add(self.usersbox, 0, wx.ALL, 10)
self.long_tweet = wx.CheckBox(self.panel, -1, _(u"&Long tweet"))
self.long_tweet.SetValue(True)
self.upload_image = wx.Button(self.panel, -1, _(u"&Upload image..."), size=wx.DefaultSize)
self.spellcheck = wx.Button(self.panel, -1, _("Check &spelling..."), size=wx.DefaultSize)
self.attach = wx.Button(self.panel, -1, _(u"&Attach audio..."), size=wx.DefaultSize)
self.shortenButton = wx.Button(self.panel, -1, _(u"Sh&orten URL"), size=wx.DefaultSize)
self.unshortenButton = wx.Button(self.panel, -1, _(u"&Expand URL"), size=wx.DefaultSize)
self.shortenButton.Disable()
self.unshortenButton.Disable()
self.translateButton = wx.Button(self.panel, -1, _(u"&Translate..."), size=wx.DefaultSize)
self.autocompletionButton = wx.Button(self.panel, -1, _(u"Auto&complete users"))
self.okButton = wx.Button(self.panel, wx.ID_OK, _(u"Sen&d"), size=wx.DefaultSize)
self.okButton.SetDefault()
cancelButton = wx.Button(self.panel, wx.ID_CANCEL, _(u"C&lose"), size=wx.DefaultSize)
self.buttonsBox1 = wx.BoxSizer(wx.HORIZONTAL)
self.buttonsBox1.Add(self.upload_image, 0, wx.ALL, 10)
self.buttonsBox1.Add(self.spellcheck, 0, wx.ALL, 10)
self.buttonsBox1.Add(self.attach, 0, wx.ALL, 10)
self.mainBox.Add(self.buttonsBox1, 0, wx.ALL, 10)
self.buttonsBox2 = wx.BoxSizer(wx.HORIZONTAL)
self.buttonsBox2.Add(self.shortenButton, 0, wx.ALL, 10)
self.buttonsBox2.Add(self.unshortenButton, 0, wx.ALL, 10)
self.buttonsBox2.Add(self.translateButton, 0, wx.ALL, 10)
self.mainBox.Add(self.buttonsBox2, 0, wx.ALL, 10)
self.ok_cancelSizer = wx.BoxSizer(wx.HORIZONTAL)
self.ok_cancelSizer.Add(self.autocompletionButton, 0, wx.ALL, 10)
self.ok_cancelSizer.Add(self.okButton, 0, wx.ALL, 10)
self.ok_cancelSizer.Add(cancelButton, 0, wx.ALL, 10)
self.mainBox.Add(self.ok_cancelSizer, 0, wx.ALL, 10)
selectId = wx.NewId()
self.Bind(wx.EVT_MENU, self.onSelect, id=selectId)
self.accel_tbl = wx.AcceleratorTable([
(wx.ACCEL_CTRL, ord('A'), selectId),
])
self.SetAcceleratorTable(self.accel_tbl)
self.panel.SetSizer(self.mainBox)
def __init__(self, title, message, text, users=[], *args, **kwargs):
self.users = users
super(reply, self).__init__()
self.shift=False
self.createControls(message, title, text)
self.SetClientSize(self.mainBox.CalcMin())
class viewTweet(widgetUtils.BaseDialog):
def set_title(self, lenght):
self.SetTitle(_(u"Tweet - %i characters ") % (lenght,))
def __init__(self, text, rt_count, favs_count,source):
def __init__(self, text, rt_count, favs_count,source, *args, **kwargs):
super(viewTweet, self).__init__(None, size=(850,850))
panel = wx.Panel(self)
label = wx.StaticText(panel, -1, _(u"Tweet"))
@ -337,7 +392,7 @@ class viewTweet(widgetUtils.BaseDialog):
class viewNonTweet(widgetUtils.BaseDialog):
def __init__(self, text):
def __init__(self, text, *args, **kwargs):
super(viewNonTweet, self).__init__(None, size=(850,850))
self.SetTitle(_(u"View"))
panel = wx.Panel(self)