From 983f1298d83257abadb25513916b914899061b8f Mon Sep 17 00:00:00 2001 From: pidgezero-one Date: Sat, 1 Jun 2024 12:45:31 -0400 Subject: [PATCH 01/10] wip --- openlibrary/core/models.py | 4 ++++ openlibrary/templates/type/user/view.html | 3 +++ 2 files changed, 7 insertions(+) diff --git a/openlibrary/core/models.py b/openlibrary/core/models.py index c0d40323818..ce6030d4eeb 100644 --- a/openlibrary/core/models.py +++ b/openlibrary/core/models.py @@ -874,6 +874,10 @@ def is_usergroup_member(self, usergroup): usergroup = '/usergroup/%s' % usergroup return usergroup in [g.key for g in self.usergroups] + def is_subscribed_user(self, username): + my_username = self.get_username() + return PubSub.is_subscribed(my_username, username) if not my_username == username else False + def has_cookie(self, name): return web.cookies().get(name, False) diff --git a/openlibrary/templates/type/user/view.html b/openlibrary/templates/type/user/view.html index 82296e134da..907e9a5286a 100644 --- a/openlibrary/templates/type/user/view.html +++ b/openlibrary/templates/type/user/view.html @@ -4,6 +4,7 @@ $ settings = page.get_users_settings() $ owners_page = ctx.user and ctx.user.key == page.key $ is_public = settings and settings.get('public_readlog', 'no') == "yes" +$ is_subscribed = ctx.user and ctx.user.is_subscribed_user(page.key) $if days_since(page.created) < 30: $ putctx('robots', 'noindex') @@ -29,6 +30,8 @@

$page.displayname

$if "lists" in ctx.features and lists: • $_("Lists") + $if is_public and not is_subscribed and not owners_page: + $:macros.Follow(mb.username, following=mb.is_subscribed) From 00d979d7e87f83def05d6b44735d60a76afba45c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 1 Jun 2024 16:49:04 +0000 Subject: [PATCH 02/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- openlibrary/core/models.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/openlibrary/core/models.py b/openlibrary/core/models.py index ce6030d4eeb..8944eeb5b8a 100644 --- a/openlibrary/core/models.py +++ b/openlibrary/core/models.py @@ -876,7 +876,11 @@ def is_usergroup_member(self, usergroup): def is_subscribed_user(self, username): my_username = self.get_username() - return PubSub.is_subscribed(my_username, username) if not my_username == username else False + return ( + PubSub.is_subscribed(my_username, username) + if not my_username == username + else False + ) def has_cookie(self, name): return web.cookies().get(name, False) From 31e688cdaab2778f99d5425789728ae54f0337a6 Mon Sep 17 00:00:00 2001 From: pidgezero-one Date: Sat, 1 Jun 2024 12:51:47 -0400 Subject: [PATCH 03/10] linting --- openlibrary/core/models.py | 2 +- openlibrary/templates/type/user/view.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/openlibrary/core/models.py b/openlibrary/core/models.py index ce6030d4eeb..f98a79e1ec3 100644 --- a/openlibrary/core/models.py +++ b/openlibrary/core/models.py @@ -876,7 +876,7 @@ def is_usergroup_member(self, usergroup): def is_subscribed_user(self, username): my_username = self.get_username() - return PubSub.is_subscribed(my_username, username) if not my_username == username else False + return PubSub.is_subscribed(my_username, username) if my_username != username else False def has_cookie(self, name): return web.cookies().get(name, False) diff --git a/openlibrary/templates/type/user/view.html b/openlibrary/templates/type/user/view.html index 907e9a5286a..33e3fcab613 100644 --- a/openlibrary/templates/type/user/view.html +++ b/openlibrary/templates/type/user/view.html @@ -30,7 +30,7 @@

$page.displayname

$if "lists" in ctx.features and lists: • $_("Lists") - $if is_public and not is_subscribed and not owners_page: + $if is_public and not owners_page and not is_subscribed: $:macros.Follow(mb.username, following=mb.is_subscribed) From 9afc1ebecd03bbabb26b65fc2a2950b727d97d4a Mon Sep 17 00:00:00 2001 From: pidgezero-one Date: Sat, 1 Jun 2024 13:06:20 -0400 Subject: [PATCH 04/10] move subscriber check to the user level' --- openlibrary/core/models.py | 2 +- openlibrary/plugins/upstream/mybooks.py | 5 ++--- openlibrary/templates/type/user/view.html | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/openlibrary/core/models.py b/openlibrary/core/models.py index 75eb8bd9289..beb6a3f5991 100644 --- a/openlibrary/core/models.py +++ b/openlibrary/core/models.py @@ -879,7 +879,7 @@ def is_subscribed_user(self, username): return ( PubSub.is_subscribed(my_username, username) if my_username != username - else False + else -1 ) def has_cookie(self, name): diff --git a/openlibrary/plugins/upstream/mybooks.py b/openlibrary/plugins/upstream/mybooks.py index db241f0dd1f..cb8005d273e 100644 --- a/openlibrary/plugins/upstream/mybooks.py +++ b/openlibrary/plugins/upstream/mybooks.py @@ -438,11 +438,10 @@ def __init__(self, username, key): self.user_itemname = self.user.get_account().get('internetarchive_itemname') self.me = accounts.get_current_user() - self.my_username = self.me and self.me.key.split('/')[-1] self.is_my_page = self.me and self.me.key.split('/')[-1] == self.username self.is_subscribed = ( - PubSub.is_subscribed(self.my_username, self.username) - if not self.is_my_page and self.is_public + self.me.is_subscribed_user(self.username) + if self.me and self.is_public else -1 ) self.key = key.lower() diff --git a/openlibrary/templates/type/user/view.html b/openlibrary/templates/type/user/view.html index 33e3fcab613..4068acbbfc1 100644 --- a/openlibrary/templates/type/user/view.html +++ b/openlibrary/templates/type/user/view.html @@ -30,7 +30,7 @@

$page.displayname

$if "lists" in ctx.features and lists: • $_("Lists") - $if is_public and not owners_page and not is_subscribed: + $if is_public and not owners_page and is_subscribed == False: $:macros.Follow(mb.username, following=mb.is_subscribed) From ef1042a052017947ff2855848896aee44db57c53 Mon Sep 17 00:00:00 2001 From: pidgezero-one Date: Sat, 1 Jun 2024 13:14:19 -0400 Subject: [PATCH 05/10] oops --- openlibrary/templates/type/user/view.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlibrary/templates/type/user/view.html b/openlibrary/templates/type/user/view.html index 4068acbbfc1..c3b6cde70f7 100644 --- a/openlibrary/templates/type/user/view.html +++ b/openlibrary/templates/type/user/view.html @@ -31,7 +31,7 @@

$page.displayname

$_("Lists") $if is_public and not owners_page and is_subscribed == False: - $:macros.Follow(mb.username, following=mb.is_subscribed) + $:macros.Follow(ctx.user.get_username(), following=is_subscribed) From f012d04eabae0e784b54a246c4d0517051ad6f33 Mon Sep 17 00:00:00 2001 From: pidgezero-one Date: Sat, 1 Jun 2024 13:21:28 -0400 Subject: [PATCH 06/10] add user check for incognito' --- openlibrary/templates/type/user/view.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlibrary/templates/type/user/view.html b/openlibrary/templates/type/user/view.html index c3b6cde70f7..5a760b6ebfd 100644 --- a/openlibrary/templates/type/user/view.html +++ b/openlibrary/templates/type/user/view.html @@ -30,7 +30,7 @@

$page.displayname

$if "lists" in ctx.features and lists: • $_("Lists") - $if is_public and not owners_page and is_subscribed == False: + $if ctx.user and is_public and not owners_page and is_subscribed == False: $:macros.Follow(ctx.user.get_username(), following=is_subscribed) From 96b358c1257f8d5248ace56352c629b191778534 Mon Sep 17 00:00:00 2001 From: pidgezero-one Date: Sat, 1 Jun 2024 13:44:47 -0400 Subject: [PATCH 07/10] moved the follow button --- openlibrary/templates/type/user/view.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openlibrary/templates/type/user/view.html b/openlibrary/templates/type/user/view.html index 5a760b6ebfd..bef24199e45 100644 --- a/openlibrary/templates/type/user/view.html +++ b/openlibrary/templates/type/user/view.html @@ -14,6 +14,8 @@ $ lists = []
+ $if ctx.user and is_public and not owners_page and is_subscribed == False: +
$:macros.Follow(ctx.user.get_username(), following=is_subscribed)
$:macros.databarView(page)

$page.displayname

@@ -30,8 +32,6 @@

$page.displayname

$if "lists" in ctx.features and lists: • $_("Lists") - $if ctx.user and is_public and not owners_page and is_subscribed == False: - $:macros.Follow(ctx.user.get_username(), following=is_subscribed)
From 3f5411dfa98cd03042a4bb15cf1b8ec6a1bda262 Mon Sep 17 00:00:00 2001 From: pidgezero-one Date: Sat, 1 Jun 2024 14:08:44 -0400 Subject: [PATCH 08/10] key' --- openlibrary/templates/type/user/view.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/openlibrary/templates/type/user/view.html b/openlibrary/templates/type/user/view.html index bef24199e45..3d551f0bc70 100644 --- a/openlibrary/templates/type/user/view.html +++ b/openlibrary/templates/type/user/view.html @@ -1,10 +1,12 @@ $def with (page) $var title: $page.displayname +$ username = page.key.split('/')[-1] $ settings = page.get_users_settings() $ owners_page = ctx.user and ctx.user.key == page.key $ is_public = settings and settings.get('public_readlog', 'no') == "yes" -$ is_subscribed = ctx.user and ctx.user.is_subscribed_user(page.key) + +$ is_subscribed = ctx.user and ctx.user.is_subscribed_user(username) $if days_since(page.created) < 30: $ putctx('robots', 'noindex') @@ -14,6 +16,7 @@ $ lists = []
+

$settings.get('username')

$if ctx.user and is_public and not owners_page and is_subscribed == False:
$:macros.Follow(ctx.user.get_username(), following=is_subscribed)
$:macros.databarView(page) From 8bddd3bbdd28470d890027f20dbc62cf133dff74 Mon Sep 17 00:00:00 2001 From: pidgezero-one Date: Sat, 1 Jun 2024 14:15:40 -0400 Subject: [PATCH 09/10] remove unnecessary space --- openlibrary/templates/type/user/view.html | 1 - 1 file changed, 1 deletion(-) diff --git a/openlibrary/templates/type/user/view.html b/openlibrary/templates/type/user/view.html index 3d551f0bc70..b1cb591925a 100644 --- a/openlibrary/templates/type/user/view.html +++ b/openlibrary/templates/type/user/view.html @@ -5,7 +5,6 @@ $ settings = page.get_users_settings() $ owners_page = ctx.user and ctx.user.key == page.key $ is_public = settings and settings.get('public_readlog', 'no') == "yes" - $ is_subscribed = ctx.user and ctx.user.is_subscribed_user(username) $if days_since(page.created) < 30: $ putctx('robots', 'noindex') From 1b996090c5689debf338281a451ce9184d82c6b1 Mon Sep 17 00:00:00 2001 From: pidgezero-one Date: Sun, 2 Jun 2024 15:26:25 -0400 Subject: [PATCH 10/10] fix follower button conditions --- openlibrary/templates/type/user/view.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openlibrary/templates/type/user/view.html b/openlibrary/templates/type/user/view.html index b1cb591925a..5c48f38e498 100644 --- a/openlibrary/templates/type/user/view.html +++ b/openlibrary/templates/type/user/view.html @@ -16,8 +16,8 @@

$settings.get('username')

- $if ctx.user and is_public and not owners_page and is_subscribed == False: -
$:macros.Follow(ctx.user.get_username(), following=is_subscribed)
+ $if is_public and not owners_page: +
$:macros.Follow(username, following=is_subscribed)
$:macros.databarView(page)

$page.displayname