From 0b418f985d326d9b885ffc9e1683e158c69d21e9 Mon Sep 17 00:00:00 2001 From: Cy Date: Mon, 1 Jun 2020 07:41:34 +0000 Subject: [PATCH 1/5] Trying to figure out why it's not finding accounts Refactoring the code to be a little more readable... --- brutaldon/views.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/brutaldon/views.py b/brutaldon/views.py index 5249078..9ff30da 100644 --- a/brutaldon/views.py +++ b/brutaldon/views.py @@ -704,6 +704,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 def user(request, username, prev=None, next=None): @@ -711,20 +717,24 @@ def user(request, username, prev=None, next=None): account, mastodon = get_usercontext(request) except NotLoggedInException: return redirect(about) + user_dict = [] + for dict in mastodon.account_search(username): + if same_username(account, dict.acct ,username): continue + try: user_dict = [ dict - for dict in mastodon.account_search(username) + if ( (dict.acct == username) or ( dict.acct == username.split("@")[0] - and username.split("@")[1] == account.username.split("@")[1] + and ) ) ][0] - except (IndexError, AttributeError): - raise Http404(_("The user %s could not be found.") % username) + except (IndexError, AttributeError) as e: + raise Http404(_("The user %s could not be found. %s") % (username, e)) data = mastodon.account_statuses(user_dict.id, max_id=next, min_id=prev) relationship = mastodon.account_relationships(user_dict.id)[0] notifications = _notes_count(account, mastodon) From 9dd5e44e6f9228010f1b4b2138d09e4d91ddd4d3 Mon Sep 17 00:00:00 2001 From: Cy Date: Mon, 1 Jun 2020 07:48:46 +0000 Subject: [PATCH 2/5] More debugging Trying to understand what's coming over the wire again --- brutaldon/views.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/brutaldon/views.py b/brutaldon/views.py index 9ff30da..0b01c31 100644 --- a/brutaldon/views.py +++ b/brutaldon/views.py @@ -710,31 +710,23 @@ def same_username(account, acct, username): myhost = account.username.split("@",1)[1] if acct == user and host == myhost: return True return False - +from pprint import pprint @br_login_required def user(request, username, prev=None, next=None): try: account, mastodon = get_usercontext(request) except NotLoggedInException: return redirect(about) - user_dict = [] + user_dict = None + print("username",username) for dict in mastodon.account_search(username): - if same_username(account, dict.acct ,username): continue - - try: - user_dict = [ - dict - - if ( - (dict.acct == username) - or ( - dict.acct == username.split("@")[0] - and - ) - ) - ][0] - except (IndexError, AttributeError) as e: - raise Http404(_("The user %s could not be found. %s") % (username, e)) + pprint(("check", dict)) + raise SystemExit(23) + if not same_username(account, dict.acct, username): continue + 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) relationship = mastodon.account_relationships(user_dict.id)[0] notifications = _notes_count(account, mastodon) From 6d22b6fc668efb75ef62c68a43258a07f8ff3fdb Mon Sep 17 00:00:00 2001 From: Cy Date: Mon, 1 Jun 2020 08:13:03 +0000 Subject: [PATCH 3/5] Pleroma bug requires /search before /account_search works Bluh... falling back to /search if /account_search fails. --- brutaldon/views.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/brutaldon/views.py b/brutaldon/views.py index 0b01c31..bb73eba 100644 --- a/brutaldon/views.py +++ b/brutaldon/views.py @@ -710,7 +710,7 @@ def same_username(account, acct, username): myhost = account.username.split("@",1)[1] if acct == user and host == myhost: return True return False -from pprint import pprint + @br_login_required def user(request, username, prev=None, next=None): try: @@ -718,15 +718,24 @@ def user(request, username, prev=None, next=None): except NotLoggedInException: return redirect(about) user_dict = None - print("username",username) + # pleroma currently flops if the user's not already locally known + # this is a BUG that they MUST FIX + # but until then, we might have to "prime the engine" + # by doing a regular search, if the account search fails + # to return results. for dict in mastodon.account_search(username): - pprint(("check", dict)) - raise SystemExit(23) + print("check", dict.acct) if not same_username(account, dict.acct, username): continue user_dict = dict break else: - raise Http404(_("The user %s could not be found.") % username) + for dict in mastodon.search(username, + result_type="accounts", + account_id=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) relationship = mastodon.account_relationships(user_dict.id)[0] notifications = _notes_count(account, mastodon) @@ -1459,6 +1468,7 @@ def search_results(request): else: query = "" account, mastodon = get_usercontext(request) + results = mastodon.search(query) notifications = _notes_count(account, mastodon) return render( From f471cf656f286ec5738ce9526bd698e6fe9ae9d3 Mon Sep 17 00:00:00 2001 From: Cy Date: Mon, 1 Jun 2020 08:22:36 +0000 Subject: [PATCH 4/5] Missed a same_username Making sure to check the username in the fallback too. Otherwise, seems to be working! --- brutaldon/views.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/brutaldon/views.py b/brutaldon/views.py index bb73eba..4ba4b70 100644 --- a/brutaldon/views.py +++ b/brutaldon/views.py @@ -84,6 +84,7 @@ def get_usercontext(request): ): raise NotLoggedInException() mastodon = Mastodon( + debug_requests=True, client_id=client.client_id, client_secret=client.client_secret, access_token=user.access_token, @@ -720,18 +721,16 @@ def user(request, username, prev=None, next=None): user_dict = None # pleroma currently flops if the user's not already locally known # this is a BUG that they MUST FIX - # but until then, we might have to "prime the engine" - # by doing a regular search, if the account search fails - # to return results. + # but until then, we might have to fallback to a regular search, + # if the account search fails to return results. for dict in mastodon.account_search(username): - print("check", dict.acct) if not same_username(account, dict.acct, username): continue user_dict = dict break else: for dict in mastodon.search(username, - result_type="accounts", - account_id=username): + result_type="accounts").accounts: + if not same_username(account, dict.acct, username): continue user_dict = dict break else: From 9b062437af9f4cd22429778d26bf07aa1d8a78f0 Mon Sep 17 00:00:00 2001 From: Cy Date: Mon, 1 Jun 2020 08:39:16 +0000 Subject: [PATCH 5/5] Oops, left some debugging in there --- brutaldon/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/brutaldon/views.py b/brutaldon/views.py index 4ba4b70..b77570a 100644 --- a/brutaldon/views.py +++ b/brutaldon/views.py @@ -84,7 +84,6 @@ def get_usercontext(request): ): raise NotLoggedInException() mastodon = Mastodon( - debug_requests=True, client_id=client.client_id, client_secret=client.client_secret, access_token=user.access_token,