Mastodon: Added user aliases

This commit is contained in:
Manuel Cortez 2023-04-05 13:28:09 -06:00
parent 00a5ad9e59
commit 10e23b039b
No known key found for this signature in database
GPG Key ID: 9E0735CA15EFE790
6 changed files with 39 additions and 8 deletions

View File

@ -8,6 +8,7 @@ During the development of the current TWBlue version, Twitter has cut out access
* Mastodon:
* it is possible to add descriptions for all media available on Mastodon (audio, photos, video and Givs). ([#516](https://github.com/MCV-Software/TWBlue/issues/516))
* TWBlue can now perform OCR in attached images.
* It is possible to add aliases to mastodon users. Also, the "manage user aliases" setting, located on the application menu within the menu bar can be used to add, edit or remove aliases.
* Implemented "Hide emojis on usernames" in both GUI and invisible interface.
* Added an experimental feature to recover from connection errors. When making a post, if the post cannot be published due to any kind of error, TWBlue will bring up the dialog where the post was composed, so you can give the post a second chance or save the post's text. This feature should work for threads, posts with attachments, polls and replies. ([#527,](https://github.com/MCV-Software/TWBlue/issues/527) [#526,](https://github.com/MCV-Software/TWBlue/issues/526) [#377,](https://github.com/MCV-Software/TWBlue/issues/377) [#137,](https://github.com/MCV-Software/TWBlue/issues/137) [#108](https://github.com/MCV-Software/TWBlue/issues/108))
* When playing media items, TWBlue will prefer remote URL streams and fall back to instance cached stream URL'S.

View File

@ -157,9 +157,9 @@ class Controller(object):
widgetUtils.connect_event(self.view.nb, widgetUtils.NOTEBOOK_PAGE_CHANGED, self.buffer_changed)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.view_documentation, self.view.doc)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.view_changelog, self.view.changelog)
# widgetUtils.connect_event(self.view, widgetUtils.MENU, self.add_alias, self.view.addAlias)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.add_alias, self.view.addAlias)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.update_buffer, self.view.update_buffer)
# widgetUtils.connect_event(self.view, widgetUtils.MENU, self.manage_aliases, self.view.manageAliases)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.manage_aliases, self.view.manageAliases)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.report_error, self.view.reportError)
def set_systray_icon(self):

View File

@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-
import wx
import logging
import output
from pubsub import pub
from mysc import restart
from wxUI.dialogs.mastodon import search as search_dialogs
from wxUI.dialogs.mastodon import dialogs
from wxUI.dialogs import userAliasDialogs
from wxUI import commonMessageDialogs
from . import userActions, settings
@ -21,7 +23,7 @@ class Handler(object):
updateProfile=None,
menuitem_search=_("&Search"),
lists=None,
manageAliases=None,
manageAliases=_("Manage user aliases"),
# In item menu.
compose=_("&Post"),
reply=_("Re&ply"),
@ -36,7 +38,7 @@ class Handler(object):
follow=_("&Actions..."),
timeline=_("&View timeline..."),
dm=_("Direct me&ssage"),
addAlias=None,
addAlias=_("Add a&lias"),
addToList=None,
removeFromList=None,
details=None,
@ -223,3 +225,33 @@ class Handler(object):
buffer.session.settings.write()
buffer.session.save_persistent_data()
restart.restart_program()
def add_alias(self, buffer):
if not hasattr(buffer, "get_item"):
return
item = buffer.get_item()
if buffer.type == "user":
users = [item.acct]
elif buffer.type == "baseBuffer":
if item.reblog != None:
users = [user.acct for user in item.reblog.mentions if user.id != buffer.session.db["user_id"]]
if item.reblog.account.acct not in users and item.account.id != buffer.session.db["user_id"]:
users.insert(0, item.reblog.account.acct)
else:
users = [user.acct for user in item.mentions if user.id != buffer.session.db["user_id"]]
if item.account.acct not in users:
users.insert(0, item.account.acct)
dlg = userAliasDialogs.addAliasDialog(_("Add an user alias"), users)
if dlg.get_response() == wx.ID_OK:
user, alias = dlg.get_user()
if user == "" or alias == "":
return
try:
full_user = buffer.session.api.account_lookup(user)
except Exception as e:
log.exception("Error adding alias to user {}.".format(user))
return
buffer.session.settings["user-aliases"][str(full_user.id)] = alias
buffer.session.settings.write()
output.speak(_("Alias has been set correctly for {}.").format(user))
pub.sendMessage("alias-added")

View File

@ -53,5 +53,5 @@ actions = {
"audio": _(u"Try to play a media file"),
"update_buffer": _(u"Updates the buffer and retrieves possible lost items there."),
"ocr_image": _(u"Extracts the text from a picture and displays the result in a dialog."),
# "add_alias": _("Adds an alias to an user"),
"add_alias": _("Adds an alias to an user"),
}

View File

@ -79,7 +79,7 @@ def get_user_alias(user, settings):
aliases = settings.get("user-aliases")
if aliases == None:
return demoji_user(display_name, settings)
user_alias = aliases.get(user.id)
user_alias = aliases.get(str(user.id))
if user_alias != None:
return user_alias
return demoji_user(display_name, settings)

View File

@ -21,7 +21,6 @@ class mainFrame(wx.Frame):
self.lists = self.menubar_application.Append(wx.ID_ANY, _(u"&Lists manager"))
self.lists.Enable(False)
self.manageAliases = self.menubar_application.Append(wx.ID_ANY, _("Manage user aliases"))
self.manageAliases.Enable(False)
self.keystroke_editor = self.menubar_application.Append(wx.ID_ANY, _(u"&Edit keystrokes"))
self.account_settings = self.menubar_application.Append(wx.ID_ANY, _(u"Account se&ttings"))
self.prefs = self.menubar_application.Append(wx.ID_PREFERENCES, _(u"&Global settings"))
@ -46,7 +45,6 @@ class mainFrame(wx.Frame):
self.timeline = self.menubar_user.Append(wx.ID_ANY, _(u"&View timeline..."))
self.dm = self.menubar_user.Append(wx.ID_ANY, _(u"Direct me&ssage"))
self.addAlias = self.menubar_user.Append(wx.ID_ANY, _("Add a&lias"))
self.addAlias.Enable(False)
self.addToList = self.menubar_user.Append(wx.ID_ANY, _(u"&Add to list"))
self.removeFromList = self.menubar_user.Append(wx.ID_ANY, _(u"R&emove from list"))
self.details = self.menubar_user.Append(wx.ID_ANY, _(u"Show user &profile"))