mastodon: Language should be automatically suggested for posts during creation, replies or when recovering from an error

This commit is contained in:
Manuel Cortez 2024-12-31 18:51:00 -06:00
parent 0322939cba
commit 6b97c5123f
4 changed files with 14 additions and 11 deletions

View File

@ -70,7 +70,7 @@ class BaseBuffer(base.Buffer):
response = post.message.ShowModal() response = post.message.ShowModal()
if response == wx.ID_OK: if response == wx.ID_OK:
post_data = post.get_data() post_data = post.get_data()
call_threaded(self.session.send_post, posts=post_data, visibility=post.get_visibility(), **kwargs) call_threaded(self.session.send_post, posts=post_data, visibility=post.get_visibility(), language=post.get_language(), **kwargs)
if hasattr(post.message, "destroy"): if hasattr(post.message, "destroy"):
post.message.destroy() post.message.destroy()
@ -335,16 +335,19 @@ class BaseBuffer(base.Buffer):
visibility = "unlisted" visibility = "unlisted"
if item.reblog != None: if item.reblog != None:
users = ["@{} ".format(user.acct) for user in item.reblog.mentions if user.id != self.session.db["user_id"]] users = ["@{} ".format(user.acct) for user in item.reblog.mentions if user.id != self.session.db["user_id"]]
language = item.reblog.language
if item.reblog.account.acct != item.account.acct and "@{} ".format(item.reblog.account.acct) not in users: if item.reblog.account.acct != item.account.acct and "@{} ".format(item.reblog.account.acct) not in users:
users.append("@{} ".format(item.reblog.account.acct)) users.append("@{} ".format(item.reblog.account.acct))
else: else:
users = ["@{} ".format(user.acct) for user in item.mentions if user.id != self.session.db["user_id"]] users = ["@{} ".format(user.acct) for user in item.mentions if user.id != self.session.db["user_id"]]
language = item.language
if "@{} ".format(item.account.acct) not in users and item.account.id != self.session.db["user_id"]: if "@{} ".format(item.account.acct) not in users and item.account.id != self.session.db["user_id"]:
users.insert(0, "@{} ".format(item.account.acct)) users.insert(0, "@{} ".format(item.account.acct))
users_str = "".join(users) users_str = "".join(users)
post = messages.post(session=self.session, title=title, caption=caption, text=users_str) post = messages.post(session=self.session, title=title, caption=caption, text=users_str)
visibility_settings = dict(public=0, unlisted=1, private=2, direct=3) visibility_settings = dict(public=0, unlisted=1, private=2, direct=3)
post.message.visibility.SetSelection(visibility_settings.get(visibility)) post.message.visibility.SetSelection(visibility_settings.get(visibility))
post.set_language(language)
# Respect content warning settings. # Respect content warning settings.
if item.sensitive: if item.sensitive:
post.message.sensitive.SetValue(item.sensitive) post.message.sensitive.SetValue(item.sensitive)
@ -353,7 +356,7 @@ class BaseBuffer(base.Buffer):
response = post.message.ShowModal() response = post.message.ShowModal()
if response == wx.ID_OK: if response == wx.ID_OK:
post_data = post.get_data() post_data = post.get_data()
call_threaded(self.session.send_post, reply_to=item.id, posts=post_data, visibility=post.get_visibility()) call_threaded(self.session.send_post, reply_to=item.id, posts=post_data, visibility=post.get_visibility(), language=post.get_language())
if hasattr(post.message, "destroy"): if hasattr(post.message, "destroy"):
post.message.destroy() post.message.destroy()
@ -380,7 +383,7 @@ class BaseBuffer(base.Buffer):
response = post.message.ShowModal() response = post.message.ShowModal()
if response == wx.ID_OK: if response == wx.ID_OK:
post_data = post.get_data() post_data = post.get_data()
call_threaded(self.session.send_post, posts=post_data, visibility="direct", reply_to=item.id) call_threaded(self.session.send_post, posts=post_data, visibility="direct", reply_to=item.id, language=post.get_language())
if hasattr(post.message, "destroy"): if hasattr(post.message, "destroy"):
post.message.destroy() post.message.destroy()
@ -551,7 +554,7 @@ class BaseBuffer(base.Buffer):
except MastodonNotFoundError: except MastodonNotFoundError:
output.speak(_("No status found with that ID")) output.speak(_("No status found with that ID"))
return return
# print(post) # print(item)
msg = messages.viewPost(self.session, item, offset_hours=self.session.db["utc_offset"], item_url=self.get_item_url(item=item)) msg = messages.viewPost(self.session, item, offset_hours=self.session.db["utc_offset"], item_url=self.get_item_url(item=item))
def ocr_image(self): def ocr_image(self):
@ -621,14 +624,14 @@ class BaseBuffer(base.Buffer):
return return
poll = self.session.api_call(call_name="poll_vote", id=poll.id, choices=options, preexec_message=_("Sending vote...")) poll = self.session.api_call(call_name="poll_vote", id=poll.id, choices=options, preexec_message=_("Sending vote..."))
def post_from_error(self, visibility, reply_to, data): def post_from_error(self, visibility, reply_to, data, lang):
title = _("Post") title = _("Post")
caption = _("Write your post here") caption = _("Write your post here")
post = messages.post(session=self.session, title=title, caption=caption) post = messages.post(session=self.session, title=title, caption=caption)
post.set_post_data(visibility=visibility, data=data) post.set_post_data(visibility=visibility, data=data, language=language)
response = post.message.ShowModal() response = post.message.ShowModal()
if response == wx.ID_OK: if response == wx.ID_OK:
post_data = post.get_data() post_data = post.get_data()
call_threaded(self.session.send_post, posts=post_data, reply_to=reply_to, visibility=post.get_visibility()) call_threaded(self.session.send_post, posts=post_data, reply_to=reply_to, visibility=post.get_visibility(), language=post.get_language())
if hasattr(post.message, "destroy"): if hasattr(post.message, "destroy"):
post.message.destroy() post.message.destroy()

View File

@ -191,7 +191,7 @@ class ConversationListBuffer(BaseBuffer):
response = post.message.ShowModal() response = post.message.ShowModal()
if response == wx.ID_OK: if response == wx.ID_OK:
post_data = post.get_data() post_data = post.get_data()
call_threaded(self.session.send_post, reply_to=item.id, posts=post_data, visibility=visibility) call_threaded(self.session.send_post, reply_to=item.id, posts=post_data, visibility=visibility, language=post.get_language())
if hasattr(post.message, "destroy"): if hasattr(post.message, "destroy"):
post.message.destroy() post.message.destroy()

View File

@ -126,7 +126,7 @@ class NotificationsBuffer(BaseBuffer):
response = post.message.ShowModal() response = post.message.ShowModal()
if response == wx.ID_OK: if response == wx.ID_OK:
post_data = post.get_data() post_data = post.get_data()
call_threaded(self.session.send_post, posts=post_data, visibility="direct") call_threaded(self.session.send_post, posts=post_data, visibility="direct", language=post.get_language())
if hasattr(post.message, "destroy"): if hasattr(post.message, "destroy"):
post.message.destroy() post.message.destroy()

View File

@ -1086,10 +1086,10 @@ class Controller(object):
# if "direct_messages" not in buffer.session.settings["other_buffers"]["muted_buffers"]: # if "direct_messages" not in buffer.session.settings["other_buffers"]["muted_buffers"]:
# self.notify(buffer.session, sound_to_play) # self.notify(buffer.session, sound_to_play)
def mastodon_error_post(self, name, reply_to, visibility, posts): def mastodon_error_post(self, name, reply_to, visibility, posts, language):
home = self.search_buffer("home_timeline", name) home = self.search_buffer("home_timeline", name)
if home != None: if home != None:
wx.CallAfter(home.post_from_error, visibility=visibility, reply_to=reply_to, data=posts) wx.CallAfter(home.post_from_error, visibility=visibility, reply_to=reply_to, data=posts, lang=language)
def change_buffer_title(self, name, buffer, title): def change_buffer_title(self, name, buffer, title):
buffer_index = self.view.search(buffer, name) buffer_index = self.view.search(buffer, name)