mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-26 12:53:12 -06:00
Added toot writing and replies
This commit is contained in:
parent
33647da6e8
commit
368e089639
@ -11,6 +11,7 @@ import languageHandler
|
||||
import logging
|
||||
from audio_services import youtube_utils
|
||||
from controller.buffers.base import base
|
||||
from controller.mastodon import messages
|
||||
from sessions.mastodon import compose, utils, templates
|
||||
from mysc.thread_utils import call_threaded
|
||||
from pubsub import pub
|
||||
@ -39,7 +40,7 @@ class BaseBuffer(base.Buffer):
|
||||
def get_buffer_name(self):
|
||||
""" Get buffer name from a set of different techniques."""
|
||||
# firstly let's take the easier buffers.
|
||||
basic_buffers = dict(home_timeline=_("Home"), local_timeline=_("Local"), federated_timeline=_("Federated"), mentions=_(u"Mentions"), direct_messages=_(u"Direct messages"), sent_direct_messages=_(u"Sent direct messages"), sent_tweets=_(u"Sent tweets"), favourites=_(u"Likes"), followers=_(u"Followers"), friends=_(u"Friends"), blocked=_(u"Blocked users"), muted=_(u"Muted users"))
|
||||
basic_buffers = dict(home_timeline=_("Home"), local_timeline=_("Local"), federated_timeline=_("Federated"), mentions=_("Mentions"), direct_messages=_("Direct messages"), sent_direct_messages=_(u"Sent direct messages"), sent_toots=_("Sent toots"), favourites=_("Favorites"), followers=_("Followers"), following=_("Following"), blocked=_(u"Blocked users"), muted=_(u"Muted users"))
|
||||
if self.name in list(basic_buffers.keys()):
|
||||
return basic_buffers[self.name]
|
||||
# Check user timelines
|
||||
@ -57,8 +58,14 @@ class BaseBuffer(base.Buffer):
|
||||
|
||||
def post_status(self, *args, **kwargs):
|
||||
title = _("Toot")
|
||||
caption = _("Write your message here")
|
||||
pass
|
||||
caption = _("Write your toot here")
|
||||
toot = messages.toot(session=self.session, title=title, caption=caption)
|
||||
response = toot.message.ShowModal()
|
||||
if response == wx.ID_OK:
|
||||
toot_data = toot.get_tweet_data()
|
||||
call_threaded(self.session.send_toot, *toot_data)
|
||||
if hasattr(toot.message, "destroy"):
|
||||
toot.message.destroy()
|
||||
|
||||
def get_formatted_message(self):
|
||||
return self.compose_function(self.get_item(), self.session.db, self.session.settings["general"]["relative_times"], self.session.settings["general"]["show_screen_names"])[1]
|
||||
@ -255,8 +262,21 @@ class BaseBuffer(base.Buffer):
|
||||
return True
|
||||
|
||||
def reply(self, *args, **kwargs):
|
||||
toot = self.get_item()
|
||||
pass
|
||||
item = self.get_item()
|
||||
title = _("Reply to {}").format(item.account.username)
|
||||
caption = _("Write your reply here")
|
||||
users = [user.acct for user in item.mentions if user.id != self.session.db["user_id"]]
|
||||
toot = messages.reply(session=self.session, title=title, caption=caption, users=users)
|
||||
response = toot.message.ShowModal()
|
||||
if response == wx.ID_OK:
|
||||
toot_data = toot.get_tweet_data()
|
||||
users = toot.get_people()
|
||||
if users == "" and item.account.id != self.session.db["user_id"]:
|
||||
users = users +"@{}".format(item.account.acct)
|
||||
call_threaded(self.session.send_toot, item.id, users, *toot_data)
|
||||
if hasattr(toot.message, "destroy"):
|
||||
toot.message.destroy()
|
||||
|
||||
|
||||
def send_message(self, *args, **kwargs):
|
||||
toot = self.get_item()
|
||||
@ -341,6 +361,7 @@ class BaseBuffer(base.Buffer):
|
||||
|
||||
def view_item(self):
|
||||
toot = self.get_item()
|
||||
print(toot)
|
||||
pass
|
||||
|
||||
def ocr_image(self):
|
||||
|
49
src/controller/mastodon/messages.py
Normal file
49
src/controller/mastodon/messages.py
Normal file
@ -0,0 +1,49 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import widgetUtils
|
||||
import config
|
||||
from controller.twitter import messages
|
||||
|
||||
class toot(messages.tweet):
|
||||
def __init__(self, max=500, *args, **kwargs):
|
||||
super(toot, self).__init__(*args, **kwargs)
|
||||
if hasattr(self.message, "add_tweet"):
|
||||
self.message.add_tweet.SetLabel(_("Add toot"))
|
||||
|
||||
class reply(toot):
|
||||
def __init__(self, users=[], *a, **b):
|
||||
super(reply, self).__init__(messageType="reply", users=users, *a, **b)
|
||||
self.users = users
|
||||
if len(users) > 0:
|
||||
widgetUtils.connect_event(self.message.mention_all, widgetUtils.CHECKBOX, self.mention_all)
|
||||
self.message.mention_all.Enable(True)
|
||||
if config.app["app-settings"]["remember_mention_and_longtweet"]:
|
||||
self.message.mention_all.SetValue(config.app["app-settings"]["mention_all"])
|
||||
self.mention_all()
|
||||
self.message.text.SetInsertionPoint(len(self.message.text.GetValue()))
|
||||
self.text_processor()
|
||||
|
||||
def text_processor(self, *args, **kwargs):
|
||||
super(toot, self).text_processor(*args, **kwargs)
|
||||
if len(self.attachments) > 0:
|
||||
self.message.attachments.Enable(True)
|
||||
self.message.remove_attachment.Enable(True)
|
||||
else:
|
||||
self.message.attachments.Enable(False)
|
||||
self.message.remove_attachment.Enable(False)
|
||||
|
||||
def mention_all(self, *args, **kwargs):
|
||||
if self.message.mention_all.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_people(self):
|
||||
people = ""
|
||||
for i in range(0, len(self.message.checkboxes)):
|
||||
if self.message.checkboxes[i].GetValue() == True:
|
||||
people = people + "{0} ".format(self.message.checkboxes[i].GetLabel(),)
|
||||
return people
|
@ -23,7 +23,7 @@ class basicTweet(object):
|
||||
self.max = max
|
||||
self.title = title
|
||||
self.session = session
|
||||
self.message = getattr(twitterDialogs, messageType)(title=title, caption=caption, message=text, *args, **kwargs)
|
||||
self.message = getattr(twitterDialogs, messageType)(title=title, caption=caption, message=text, max_length=max, *args, **kwargs)
|
||||
self.message.text.SetValue(text)
|
||||
self.message.text.SetInsertionPoint(len(self.message.text.GetValue()))
|
||||
widgetUtils.connect_event(self.message.spellcheck, widgetUtils.BUTTON_PRESSED, self.spellcheck)
|
||||
@ -185,6 +185,7 @@ class tweet(basicTweet):
|
||||
def text_processor(self, *args, **kwargs):
|
||||
super(tweet, self).text_processor(*args, **kwargs)
|
||||
if len(self.thread) > 0:
|
||||
if hasattr(self.message, "tweets"):
|
||||
self.message.tweets.Enable(True)
|
||||
self.message.remove_tweet.Enable(True)
|
||||
else:
|
||||
|
@ -141,3 +141,22 @@ class Session(base.baseSession):
|
||||
output.speak(_("%s succeeded.") % action)
|
||||
if _sound != None: self.sound.play(_sound)
|
||||
return val
|
||||
|
||||
def send_toot(self, reply_to=None, users=None, *toots):
|
||||
""" Convenience function to send a thread. """
|
||||
in_reply_to_id = reply_to
|
||||
for obj in toots:
|
||||
if users != None:
|
||||
text = "{} {}".format(users, obj.get("text"))
|
||||
else:
|
||||
text = obj.get("text")
|
||||
if len(obj["attachments"]) == 0:
|
||||
item = self.api_call(call_name="status_post", status=text, _sound="tweet_send.ogg", in_reply_to_id=in_reply_to_id)
|
||||
in_reply_to_id = item["id"]
|
||||
else:
|
||||
media_ids = []
|
||||
for i in obj["attachments"]:
|
||||
img = self.api_call("media_post", media_file=i["file"], description=i["description"])
|
||||
media_ids.append(img.id)
|
||||
item = self.api_call(call_name="status_post", status=text, _sound="tweet_send.ogg", in_reply_to_id=in_reply_to_id, media_ids=media_ids)
|
||||
in_reply_to_id = item["id"]
|
||||
|
Loading…
Reference in New Issue
Block a user