Skip to content

Commit

Permalink
mastodon: Language should be automatically suggested for posts during…
Browse files Browse the repository at this point in the history
… creation, replies or when recovering from an error
  • Loading branch information
manuelcortez committed Jan 1, 2025
1 parent 0322939 commit 6b97c51
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
17 changes: 10 additions & 7 deletions src/controller/buffers/mastodon/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def post_status(self, *args, **kwargs):
response = post.message.ShowModal()
if response == wx.ID_OK:
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"):
post.message.destroy()

Expand Down Expand Up @@ -335,16 +335,19 @@ def reply(self, event=None, item=None, *args, **kwargs):
visibility = "unlisted"
if item.reblog != None:
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:
users.append("@{} ".format(item.reblog.account.acct))
else:
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"]:
users.insert(0, "@{} ".format(item.account.acct))
users_str = "".join(users)
post = messages.post(session=self.session, title=title, caption=caption, text=users_str)
visibility_settings = dict(public=0, unlisted=1, private=2, direct=3)
post.message.visibility.SetSelection(visibility_settings.get(visibility))
post.set_language(language)
# Respect content warning settings.
if item.sensitive:
post.message.sensitive.SetValue(item.sensitive)
Expand All @@ -353,7 +356,7 @@ def reply(self, event=None, item=None, *args, **kwargs):
response = post.message.ShowModal()
if response == wx.ID_OK:
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"):
post.message.destroy()

Expand All @@ -380,7 +383,7 @@ def send_message(self, event=None, item=None, *args, **kwargs):
response = post.message.ShowModal()
if response == wx.ID_OK:
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"):
post.message.destroy()

Expand Down Expand Up @@ -551,7 +554,7 @@ def view_item(self, item=None):
except MastodonNotFoundError:
output.speak(_("No status found with that ID"))
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))

def ocr_image(self):
Expand Down Expand Up @@ -621,14 +624,14 @@ def vote(self, item=None):
return
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")
caption = _("Write your post here")
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()
if response == wx.ID_OK:
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"):
post.message.destroy()
2 changes: 1 addition & 1 deletion src/controller/buffers/mastodon/conversations.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def reply(self, *args):
response = post.message.ShowModal()
if response == wx.ID_OK:
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"):
post.message.destroy()

Expand Down
2 changes: 1 addition & 1 deletion src/controller/buffers/mastodon/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def send_message(self, *args, **kwargs):
response = post.message.ShowModal()
if response == wx.ID_OK:
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"):
post.message.destroy()

Expand Down
4 changes: 2 additions & 2 deletions src/controller/mainController.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,10 +1086,10 @@ def mastodon_new_conversation(self, conversation, session_name):
# if "direct_messages" not in buffer.session.settings["other_buffers"]["muted_buffers"]:
# 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)
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):
buffer_index = self.view.search(buffer, name)
Expand Down

0 comments on commit 6b97c51

Please sign in to comment.