mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-26 12:53:12 -06:00
Reimplemented direct messages with support for media
This commit is contained in:
parent
1e2464c4fa
commit
a43101e694
@ -425,21 +425,17 @@ class BaseBuffer(base.Buffer):
|
|||||||
else:
|
else:
|
||||||
screen_name = self.session.get_user(tweet.user).screen_name
|
screen_name = self.session.get_user(tweet.user).screen_name
|
||||||
users = utils.get_all_users(tweet, self.session)
|
users = utils.get_all_users(tweet, self.session)
|
||||||
dm = messages.dm(self.session, _(u"Direct message to %s") % (screen_name,), _(u"New direct message"), users)
|
dm = messages.dm(self.session, _("Direct message to %s") % (screen_name,), _("New direct message"), users)
|
||||||
if dm.message.ShowModal() == widgetUtils.OK:
|
if dm.message.ShowModal() == widgetUtils.OK:
|
||||||
screen_name = dm.message.cb.GetValue()
|
screen_name = dm.message.cb.GetValue()
|
||||||
user = self.session.get_user_by_screen_name(screen_name)
|
user = self.session.get_user_by_screen_name(screen_name)
|
||||||
recipient_id = user
|
recipient_id = user
|
||||||
text = dm.message.text.GetValue()
|
text = dm.message.text.GetValue()
|
||||||
val = self.session.api_call(call_name="send_direct_message", recipient_id=recipient_id, text=text)
|
if len(dm.attachments) > 0:
|
||||||
if val != None:
|
attachment = dm.attachments[0]
|
||||||
sent_dms = self.session.db["sent_direct_messages"]
|
else:
|
||||||
if self.session.settings["general"]["reverse_timelines"] == False:
|
attachment = None
|
||||||
sent_dms.append(val)
|
call_threaded(self.session.direct_message, text=text, recipient=recipient_id, attachment=attachment)
|
||||||
else:
|
|
||||||
sent_dms.insert(0, val)
|
|
||||||
self.session.db["sent_direct_messages"] = sent_dms
|
|
||||||
pub.sendMessage("sent-dm", data=val, user=self.session.db["user_name"])
|
|
||||||
if hasattr(dm.message, "destroy"): dm.message.destroy()
|
if hasattr(dm.message, "destroy"): dm.message.destroy()
|
||||||
|
|
||||||
@_tweets_exist
|
@_tweets_exist
|
||||||
|
@ -269,6 +269,11 @@ class dm(basicTweet):
|
|||||||
def get_data(self):
|
def get_data(self):
|
||||||
return dict(text=self.message.text.GetValue(), attachments=self.attachments)
|
return dict(text=self.message.text.GetValue(), attachments=self.attachments)
|
||||||
|
|
||||||
|
def can_attach(self):
|
||||||
|
if len(self.attachments) == 0:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
class viewTweet(basicTweet):
|
class viewTweet(basicTweet):
|
||||||
def __init__(self, tweet, tweetList, is_tweet=True, utc_offset=0, date="", item_url=""):
|
def __init__(self, tweet, tweetList, is_tweet=True, utc_offset=0, date="", item_url=""):
|
||||||
""" This represents a tweet displayer. However it could be used for showing something wich is not a tweet, like a direct message or an event.
|
""" This represents a tweet displayer. However it could be used for showing something wich is not a tweet, like a direct message or an event.
|
||||||
|
@ -620,3 +620,24 @@ class Session(base.baseSession):
|
|||||||
self.api_call(call_name="create_media_metadata", media_id=img.media_id, alt_text=i["description"])
|
self.api_call(call_name="create_media_metadata", media_id=img.media_id, alt_text=i["description"])
|
||||||
media_ids.append(img.media_id)
|
media_ids.append(img.media_id)
|
||||||
item = self.api_call(call_name="update_status", status=text, _sound="reply_send.ogg", tweet_mode="extended", in_reply_to_status_id=in_reply_to_status_id, media_ids=media_ids, *args, **kwargs)
|
item = self.api_call(call_name="update_status", status=text, _sound="reply_send.ogg", tweet_mode="extended", in_reply_to_status_id=in_reply_to_status_id, media_ids=media_ids, *args, **kwargs)
|
||||||
|
|
||||||
|
def direct_message(self, text, recipient, attachment=None, *args, **kwargs):
|
||||||
|
if attachment == None:
|
||||||
|
item = self.api_call(call_name="send_direct_message", recipient_id=recipient, text=text)
|
||||||
|
else:
|
||||||
|
if attachment["type"] == "photo":
|
||||||
|
media_category = "DmImage"
|
||||||
|
elif attachment["type"] == "gif":
|
||||||
|
media_category = "DmGif"
|
||||||
|
elif attachment["type"] == "video":
|
||||||
|
media_category = "DmVideo"
|
||||||
|
media = self.api_call("media_upload", filename=attachment["file"], media_category=media_category)
|
||||||
|
item = self.api_call(call_name="send_direct_message", recipient_id=recipient, text=text, attachment_type="media", attachment_media_id=media.media_id)
|
||||||
|
if item != None:
|
||||||
|
sent_dms = self.db["sent_direct_messages"]
|
||||||
|
if self.settings["general"]["reverse_timelines"] == False:
|
||||||
|
sent_dms.append(item)
|
||||||
|
else:
|
||||||
|
sent_dms.insert(0, item)
|
||||||
|
self.db["sent_direct_messages"] = sent_dms
|
||||||
|
pub.sendMessage("sent-dm", data=item, user=self.db["user_name"])
|
||||||
|
@ -283,6 +283,20 @@ class dm(tweet):
|
|||||||
self.SetEscapeId(self.cancel.GetId())
|
self.SetEscapeId(self.cancel.GetId())
|
||||||
self.Layout()
|
self.Layout()
|
||||||
|
|
||||||
|
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, None)
|
||||||
|
return (openFileDialog.GetPath(), "")
|
||||||
|
|
||||||
|
def attach_menu(self, event=None, enabled=True, *args, **kwargs):
|
||||||
|
menu = wx.Menu()
|
||||||
|
self.add_image = menu.Append(wx.ID_ANY, _("Image"))
|
||||||
|
self.add_image.Enable(enabled)
|
||||||
|
self.add_video = menu.Append(wx.ID_ANY, _("Video"))
|
||||||
|
self.add_video.Enable(enabled)
|
||||||
|
return menu
|
||||||
|
|
||||||
class viewTweet(wx.Dialog):
|
class viewTweet(wx.Dialog):
|
||||||
def set_title(self, lenght):
|
def set_title(self, lenght):
|
||||||
self.SetTitle(_(u"Tweet - %i characters ") % (lenght,))
|
self.SetTitle(_(u"Tweet - %i characters ") % (lenght,))
|
||||||
|
Loading…
Reference in New Issue
Block a user