diff --git a/src/controller/mastodon/handler.py b/src/controller/mastodon/handler.py index 553c424a..f9bfad74 100644 --- a/src/controller/mastodon/handler.py +++ b/src/controller/mastodon/handler.py @@ -296,16 +296,20 @@ class Handler(object): if not hasattr(buffer, 'get_item'): return # Tell user? item = buffer.get_item() + if not item: + return # empty buffer - if hasattr(item, 'username'): + holdUser = item.get('account') + if item.get('username'): # item is an account dict users = [(item.display_name, item.username, item.id)] - elif hasattr(item, 'mentions'): + elif item.get('mentions'): # statuse if item.reblog: item = item.reblog - users = [(user.display_name, user.username, user.id) for user in item.mentions] + users = [(user.acct, user.id) for user in item.mentions] users.insert(0, (item.account.display_name, item.account.username, item.account.id)) + holdUser = item.account elif hasattr(item, 'account'): # Notifications users = [(item.account.display_name, item.account.username, item.account.id)] @@ -313,10 +317,17 @@ class Handler(object): dialogs.no_user() return - users = list(set(users)) - selectedUser = showUserProfile.selectUserDialog(users) - log.debug(f"Selected user = {selectedUser}") - user = buffer.session.api.account(selectedUser[2]) + if len(users) == 1: + user = holdUser + else: + users = list(set(users)) + selectedUser = showUserProfile.selectUserDialog(users) + if not selectedUser: + return # Canceled selection + elif selectedUser[-1] == holdUser.id: + user = holdUser + else: + user = buffer.session.api.account(selectedUser[-1]) dlg = showUserProfile.ShowUserProfile( user.display_name, user.url, html_filter(user.note), user.header, user.avatar, [(field.name, html_filter(field.value)) for field in user.fields], False, False, False) diff --git a/src/wxUI/dialogs/mastodon/showUserProfile.py b/src/wxUI/dialogs/mastodon/showUserProfile.py index 71db5ebd..6fb5667b 100644 --- a/src/wxUI/dialogs/mastodon/showUserProfile.py +++ b/src/wxUI/dialogs/mastodon/showUserProfile.py @@ -1,13 +1,14 @@ # -*- coding: utf-8 -*- -def _(s): - return s """Wx dialogs for showing a user's profile.""" -import wx -import os -import requests from io import BytesIO +import os from typing import Tuple +import requests +import wx + +def _(s): + return s def selectUserDialog(users: list) -> tuple: @@ -16,7 +17,13 @@ def selectUserDialog(users: list) -> tuple: return users[0] dlg = wx.Dialog(None, title=_("Select user")) label = wx.StaticText(dlg, label="Select a user: ") - choice = wx.Choice(dlg, choices=[f"{name}: @{username}" for name, username, id in users]) + choiceList = [] + for user in users: + if len(user) == 3: # (display_name, username, id) + choiceList.append(f"{user[0]}: @{user[1]}") + else: # (acct, id) + choiceList.append(f"{user[0]}") + choice = wx.Choice(dlg, choices=choiceList) ok = wx.Button(dlg, wx.ID_OK, _("OK")) ok.SetDefault() cancel = wx.Button(dlg, wx.ID_CANCEL, _("Cancel")) @@ -30,7 +37,7 @@ def selectUserDialog(users: list) -> tuple: sizer.Add(cancel, wx.SizerFlags().Center()) if dlg.ShowModal() == wx.ID_CANCEL: - return + return () # return the selected user return users[choice.GetSelection()] @@ -56,7 +63,7 @@ class ShowUserProfile(wx.Dialog): """Initialize update profile dialog Parameters: - display_name: The user's display name to show in the display name field - - username: The user's username + - url: The user's url - note: The users bio to show in the bio field - header: the users header pic link - avatar: The users avatar pic link @@ -73,10 +80,10 @@ class ShowUserProfile(wx.Dialog): sizer.Add(nameLabel, wx.SizerFlags().Center()) sizer.Add(name, wx.SizerFlags().Center()) - usernameLabel = wx.StaticText(self.panel, label=_("Username: ")) - username = self.createTextCtrl(username, size=(200, 30)) - sizer.Add(usernameLabel, wx.SizerFlags().Center()) - sizer.Add(username, wx.SizerFlags().Center()) + urlLabel = wx.StaticText(self.panel, label=_("URL: ")) + url = self.createTextCtrl(url, size=(200, 30)) + sizer.Add(urlLabel, wx.SizerFlags().Center()) + sizer.Add(url, wx.SizerFlags().Center()) bioLabel = wx.StaticText(self.panel, label=_("Bio: ")) bio = self.createTextCtrl(note, (400, 60))