Added toot writing and replies

This commit is contained in:
Manuel Cortez 2022-11-08 17:53:59 -06:00
parent 33647da6e8
commit 368e089639
No known key found for this signature in database
GPG Key ID: 9E0735CA15EFE790
4 changed files with 101 additions and 11 deletions

View File

@ -11,6 +11,7 @@ import languageHandler
import logging import logging
from audio_services import youtube_utils from audio_services import youtube_utils
from controller.buffers.base import base from controller.buffers.base import base
from controller.mastodon import messages
from sessions.mastodon import compose, utils, templates from sessions.mastodon import compose, utils, templates
from mysc.thread_utils import call_threaded from mysc.thread_utils import call_threaded
from pubsub import pub from pubsub import pub
@ -39,7 +40,7 @@ class BaseBuffer(base.Buffer):
def get_buffer_name(self): def get_buffer_name(self):
""" Get buffer name from a set of different techniques.""" """ Get buffer name from a set of different techniques."""
# firstly let's take the easier buffers. # 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()): if self.name in list(basic_buffers.keys()):
return basic_buffers[self.name] return basic_buffers[self.name]
# Check user timelines # Check user timelines
@ -57,8 +58,14 @@ class BaseBuffer(base.Buffer):
def post_status(self, *args, **kwargs): def post_status(self, *args, **kwargs):
title = _("Toot") title = _("Toot")
caption = _("Write your message here") caption = _("Write your toot here")
pass 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): 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] 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 return True
def reply(self, *args, **kwargs): def reply(self, *args, **kwargs):
toot = self.get_item() item = self.get_item()
pass 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): def send_message(self, *args, **kwargs):
toot = self.get_item() toot = self.get_item()
@ -341,6 +361,7 @@ class BaseBuffer(base.Buffer):
def view_item(self): def view_item(self):
toot = self.get_item() toot = self.get_item()
print(toot)
pass pass
def ocr_image(self): def ocr_image(self):

View 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

View File

@ -23,7 +23,7 @@ class basicTweet(object):
self.max = max self.max = max
self.title = title self.title = title
self.session = session 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.SetValue(text)
self.message.text.SetInsertionPoint(len(self.message.text.GetValue())) self.message.text.SetInsertionPoint(len(self.message.text.GetValue()))
widgetUtils.connect_event(self.message.spellcheck, widgetUtils.BUTTON_PRESSED, self.spellcheck) widgetUtils.connect_event(self.message.spellcheck, widgetUtils.BUTTON_PRESSED, self.spellcheck)
@ -185,6 +185,7 @@ class tweet(basicTweet):
def text_processor(self, *args, **kwargs): def text_processor(self, *args, **kwargs):
super(tweet, self).text_processor(*args, **kwargs) super(tweet, self).text_processor(*args, **kwargs)
if len(self.thread) > 0: if len(self.thread) > 0:
if hasattr(self.message, "tweets"):
self.message.tweets.Enable(True) self.message.tweets.Enable(True)
self.message.remove_tweet.Enable(True) self.message.remove_tweet.Enable(True)
else: else:

View File

@ -141,3 +141,22 @@ class Session(base.baseSession):
output.speak(_("%s succeeded.") % action) output.speak(_("%s succeeded.") % action)
if _sound != None: self.sound.play(_sound) if _sound != None: self.sound.play(_sound)
return val 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"]