Merge pull request #79 from cyisfor/pleroma_account_search_workaround

Pleroma account search workaround
This commit is contained in:
GCU Prosthetic Conscience 2020-07-08 12:16:27 -04:00 committed by GitHub
commit 8c5c48fd19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -714,6 +714,12 @@ def thread(request, id):
}, },
) )
def same_username(account, acct, username):
if acct == username: return True
user, host = username.split("@", 1)
myhost = account.username.split("@",1)[1]
if acct == user and host == myhost: return True
return False
@br_login_required @br_login_required
def user(request, username, prev=None, next=None): def user(request, username, prev=None, next=None):
@ -721,20 +727,23 @@ def user(request, username, prev=None, next=None):
account, mastodon = get_usercontext(request) account, mastodon = get_usercontext(request)
except NotLoggedInException: except NotLoggedInException:
return redirect(about) return redirect(about)
try: user_dict = None
user_dict = [ # pleroma currently flops if the user's not already locally known
dict # this is a BUG that they MUST FIX
for dict in mastodon.account_search(username) # but until then, we might have to fallback to a regular search,
if ( # if the account search fails to return results.
(dict.acct == username) for dict in mastodon.account_search(username):
or ( if not same_username(account, dict.acct, username): continue
dict.acct == username.split("@")[0] user_dict = dict
and username.split("@")[1] == account.username.split("@")[1] break
) else:
) for dict in mastodon.search(username,
][0] result_type="accounts").accounts:
except (IndexError, AttributeError): if not same_username(account, dict.acct, username): continue
raise Http404(_("The user %s could not be found.") % username) user_dict = dict
break
else:
raise Http404(_("The user %s could not be found.") % username)
data = mastodon.account_statuses(user_dict.id, max_id=next, min_id=prev) data = mastodon.account_statuses(user_dict.id, max_id=next, min_id=prev)
relationship = mastodon.account_relationships(user_dict.id)[0] relationship = mastodon.account_relationships(user_dict.id)[0]
notifications = _notes_count(account, mastodon) notifications = _notes_count(account, mastodon)
@ -1459,6 +1468,7 @@ def search_results(request):
else: else:
query = "" query = ""
account, mastodon = get_usercontext(request) account, mastodon = get_usercontext(request)
results = mastodon.search(query) results = mastodon.search(query)
notifications = _notes_count(account, mastodon) notifications = _notes_count(account, mastodon)
return render( return render(