fix show user profile not working when a post have mentions

This commit is contained in:
Abdulqadir Ahmad 2023-08-10 19:15:34 +01:00
parent 1d8fefe7d3
commit 35ba915be6
2 changed files with 37 additions and 19 deletions

View File

@ -296,16 +296,20 @@ class Handler(object):
if not hasattr(buffer, 'get_item'): if not hasattr(buffer, 'get_item'):
return # Tell user? return # Tell user?
item = buffer.get_item() 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 # item is an account dict
users = [(item.display_name, item.username, item.id)] users = [(item.display_name, item.username, item.id)]
elif hasattr(item, 'mentions'): elif item.get('mentions'):
# statuse # statuse
if item.reblog: if item.reblog:
item = 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)) users.insert(0, (item.account.display_name, item.account.username, item.account.id))
holdUser = item.account
elif hasattr(item, 'account'): elif hasattr(item, 'account'):
# Notifications # Notifications
users = [(item.account.display_name, item.account.username, item.account.id)] users = [(item.account.display_name, item.account.username, item.account.id)]
@ -313,10 +317,17 @@ class Handler(object):
dialogs.no_user() dialogs.no_user()
return return
if len(users) == 1:
user = holdUser
else:
users = list(set(users)) users = list(set(users))
selectedUser = showUserProfile.selectUserDialog(users) selectedUser = showUserProfile.selectUserDialog(users)
log.debug(f"Selected user = {selectedUser}") if not selectedUser:
user = buffer.session.api.account(selectedUser[2]) return # Canceled selection
elif selectedUser[-1] == holdUser.id:
user = holdUser
else:
user = buffer.session.api.account(selectedUser[-1])
dlg = showUserProfile.ShowUserProfile( dlg = showUserProfile.ShowUserProfile(
user.display_name, user.url, html_filter(user.note), user.header, user.avatar, 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) [(field.name, html_filter(field.value)) for field in user.fields], False, False, False)

View File

@ -1,13 +1,14 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
def _(s):
return s
"""Wx dialogs for showing a user's profile.""" """Wx dialogs for showing a user's profile."""
import wx
import os
import requests
from io import BytesIO from io import BytesIO
import os
from typing import Tuple from typing import Tuple
import requests
import wx
def _(s):
return s
def selectUserDialog(users: list) -> tuple: def selectUserDialog(users: list) -> tuple:
@ -16,7 +17,13 @@ def selectUserDialog(users: list) -> tuple:
return users[0] return users[0]
dlg = wx.Dialog(None, title=_("Select user")) dlg = wx.Dialog(None, title=_("Select user"))
label = wx.StaticText(dlg, label="Select a 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 = wx.Button(dlg, wx.ID_OK, _("OK"))
ok.SetDefault() ok.SetDefault()
cancel = wx.Button(dlg, wx.ID_CANCEL, _("Cancel")) cancel = wx.Button(dlg, wx.ID_CANCEL, _("Cancel"))
@ -30,7 +37,7 @@ def selectUserDialog(users: list) -> tuple:
sizer.Add(cancel, wx.SizerFlags().Center()) sizer.Add(cancel, wx.SizerFlags().Center())
if dlg.ShowModal() == wx.ID_CANCEL: if dlg.ShowModal() == wx.ID_CANCEL:
return return ()
# return the selected user # return the selected user
return users[choice.GetSelection()] return users[choice.GetSelection()]
@ -56,7 +63,7 @@ class ShowUserProfile(wx.Dialog):
"""Initialize update profile dialog """Initialize update profile dialog
Parameters: Parameters:
- display_name: The user's display name to show in the display name field - 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 - note: The users bio to show in the bio field
- header: the users header pic link - header: the users header pic link
- avatar: The users avatar pic link - avatar: The users avatar pic link
@ -73,10 +80,10 @@ class ShowUserProfile(wx.Dialog):
sizer.Add(nameLabel, wx.SizerFlags().Center()) sizer.Add(nameLabel, wx.SizerFlags().Center())
sizer.Add(name, wx.SizerFlags().Center()) sizer.Add(name, wx.SizerFlags().Center())
usernameLabel = wx.StaticText(self.panel, label=_("Username: ")) urlLabel = wx.StaticText(self.panel, label=_("URL: "))
username = self.createTextCtrl(username, size=(200, 30)) url = self.createTextCtrl(url, size=(200, 30))
sizer.Add(usernameLabel, wx.SizerFlags().Center()) sizer.Add(urlLabel, wx.SizerFlags().Center())
sizer.Add(username, wx.SizerFlags().Center()) sizer.Add(url, wx.SizerFlags().Center())
bioLabel = wx.StaticText(self.panel, label=_("Bio: ")) bioLabel = wx.StaticText(self.panel, label=_("Bio: "))
bio = self.createTextCtrl(note, (400, 60)) bio = self.createTextCtrl(note, (400, 60))