auto bookmark

This commit is contained in:
Your Name 2024-06-15 23:38:33 -04:00 committed by Henri Dickson
parent 791688b002
commit b182845f0a
9 changed files with 146 additions and 46 deletions

View file

@ -292,20 +292,24 @@ class Mark:
) )
self.rating_grade = rating_grade self.rating_grade = rating_grade
# publish a new or updated ActivityPub post # publish a new or updated ActivityPub post
user = self.owner.user
post_as_new = shelf_type != last_shelf_type or visibility != last_visibility post_as_new = shelf_type != last_shelf_type or visibility != last_visibility
classic_repost = self.owner.user.preference.mastodon_repost_mode == 1 classic_repost = user.preference.mastodon_repost_mode == 1
append = ( append = (
f"@{self.owner.user.mastodon_acct}\n" f"@{user.mastodon_acct}\n"
if visibility > 0 and share_to_mastodon and not classic_repost if visibility > 0 and share_to_mastodon and not classic_repost
else "" else ""
) )
post = Takahe.post_mark(self, post_as_new, append) post = Takahe.post_mark(self, post_as_new, append)
if post and self.item.category in (user.preference.auto_bookmark_cats or []):
if shelf_type == ShelfType.PROGRESS:
Takahe.bookmark(post.pk, self.owner.pk)
# async boost to mastodon # async boost to mastodon
if post and share_to_mastodon: if post and share_to_mastodon:
if classic_repost: if classic_repost:
share_mark(self, post_as_new) share_mark(self, post_as_new)
else: else:
boost_toot_later(self.owner.user, post.url) boost_toot_later(user, post.url)
return True return True
def delete(self, keep_tags=False): def delete(self, keep_tags=False):

View file

@ -6,7 +6,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-15 22:23-0400\n" "POT-Creation-Date: 2024-06-15 23:28-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -1032,8 +1032,8 @@ msgstr "创建"
#: journal/templates/mark.html:147 journal/templates/note.html:39 #: journal/templates/mark.html:147 journal/templates/note.html:39
#: journal/templates/review_edit.html:39 journal/templates/tag_edit.html:51 #: journal/templates/review_edit.html:39 journal/templates/tag_edit.html:51
#: users/templates/users/account.html:43 users/templates/users/account.html:102 #: users/templates/users/account.html:43 users/templates/users/account.html:102
#: users/templates/users/preferences.html:168 #: users/templates/users/preferences.html:187
#: users/templates/users/preferences.html:193 #: users/templates/users/preferences.html:212
msgid "Save" msgid "Save"
msgstr "保存" msgstr "保存"
@ -3653,70 +3653,78 @@ msgid "Language"
msgstr "语言" msgstr "语言"
#: users/templates/users/preferences.html:140 #: users/templates/users/preferences.html:140
msgid "Automatic bookmark for these categories"
msgstr "以下类型自动加入书签"
#: users/templates/users/preferences.html:153
msgid "When start to read/watch/play/... an item in these categories, a bookmark will be created automatically. Bookmarks can be viewed and managed in most <a href=\"https://joinmastodon.org/apps\" target=\"_blank\">Mastodon compatible apps</a>; your replies to these posts will automatically become notes for the item."
msgstr "将以下类型的条目设置为在读/在看/在玩/...时,自动把相应帖文添加为书签。这些书签帖文可在登录<a href=\"https://joinmastodon.org/apps\" target=\"_blank\">应用程序</a>(如<a href=\"https://phanpy.social/#/login?instance=neodb.social&submit=1\" target=\"_blank\">Phanpy</a>等)后查看和管理,你对这些帖子的回复会自动成为该条目的笔记。"
#: users/templates/users/preferences.html:157
msgid "Hide these categories in search results" msgid "Hide these categories in search results"
msgstr "搜索时不显示以下类型" msgstr "搜索时不显示以下类型"
#: users/templates/users/preferences.html:156 #: users/templates/users/preferences.html:175
msgid "Profile visible to anonymous web visitors and search engines" msgid "Profile visible to anonymous web visitors and search engines"
msgstr "匿名访客和搜索引擎可以查看你的个人主页" msgstr "匿名访客和搜索引擎可以查看你的个人主页"
#: users/templates/users/preferences.html:157 #: users/templates/users/preferences.html:176
msgid "this option limits web visits only; to limit fediverse visibility, choose followers only or mentioned only when posting" msgid "this option limits web visits only; to limit fediverse visibility, choose followers only or mentioned only when posting"
msgstr "此选项仅针对网页访客,如果不希望被联邦网络用户看到请在发表时选择仅关注者或本人" msgstr "此选项仅针对网页访客,如果不希望被联邦网络用户看到请在发表时选择仅关注者或本人"
#: users/templates/users/preferences.html:165 #: users/templates/users/preferences.html:184
msgid "Show your name on item page if you recently edited it" msgid "Show your name on item page if you recently edited it"
msgstr "显示你是某条目的最近编辑者" msgstr "显示你是某条目的最近编辑者"
#: users/templates/users/preferences.html:174 #: users/templates/users/preferences.html:193
msgid "Settings for current device" msgid "Settings for current device"
msgstr "当前设备设置" msgstr "当前设备设置"
#: users/templates/users/preferences.html:176 #: users/templates/users/preferences.html:195
msgid "theme" msgid "theme"
msgstr "主题" msgstr "主题"
#: users/templates/users/preferences.html:179 #: users/templates/users/preferences.html:198
msgid "system" msgid "system"
msgstr "系统" msgstr "系统"
#: users/templates/users/preferences.html:181 #: users/templates/users/preferences.html:200
msgid "light" msgid "light"
msgstr "明亮" msgstr "明亮"
#: users/templates/users/preferences.html:183 #: users/templates/users/preferences.html:202
msgid "dark" msgid "dark"
msgstr "暗色" msgstr "暗色"
#: users/templates/users/preferences.html:185 #: users/templates/users/preferences.html:204
msgid "Focus mode" msgid "Focus mode"
msgstr "专注模式" msgstr "专注模式"
#: users/templates/users/preferences.html:188 #: users/templates/users/preferences.html:207
msgid "hide reviews and ratings from other users" msgid "hide reviews and ratings from other users"
msgstr "启用专注模式后搜索和条目页面将不再显示来自他人的评价和打分" msgstr "启用专注模式后搜索和条目页面将不再显示来自他人的评价和打分"
#: users/templates/users/preferences.html:190 #: users/templates/users/preferences.html:209
msgid "Custom styles" msgid "Custom styles"
msgstr "自定义样式代码" msgstr "自定义样式代码"
#: users/templates/users/preferences.html:209 #: users/templates/users/preferences.html:228
msgid "Settings for current device saved" msgid "Settings for current device saved"
msgstr "当前设备设置已保存" msgstr "当前设备设置已保存"
#: users/templates/users/preferences.html:215 #: users/templates/users/preferences.html:234
msgid "Additional Settings" msgid "Additional Settings"
msgstr "更多设置" msgstr "更多设置"
#: users/templates/users/preferences.html:217 #: users/templates/users/preferences.html:236
msgid "View authorized applications" msgid "View authorized applications"
msgstr "查看已授权的应用程序" msgstr "查看已授权的应用程序"
#: users/templates/users/preferences.html:221 #: users/templates/users/preferences.html:240
msgid "Migrate account" msgid "Migrate account"
msgstr "迁移账号" msgstr "迁移账号"
#: users/templates/users/preferences.html:223 #: users/templates/users/preferences.html:242
msgid "Link an email so that you can migrate followers from other Fediverse instances." msgid "Link an email so that you can migrate followers from other Fediverse instances."
msgstr "关联电子邮件后方可从其他实例迁入。" msgstr "关联电子邮件后方可从其他实例迁入。"

View file

@ -6,7 +6,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-15 22:23-0400\n" "POT-Creation-Date: 2024-06-15 23:28-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -1032,8 +1032,8 @@ msgstr "創建"
#: journal/templates/mark.html:147 journal/templates/note.html:39 #: journal/templates/mark.html:147 journal/templates/note.html:39
#: journal/templates/review_edit.html:39 journal/templates/tag_edit.html:51 #: journal/templates/review_edit.html:39 journal/templates/tag_edit.html:51
#: users/templates/users/account.html:43 users/templates/users/account.html:102 #: users/templates/users/account.html:43 users/templates/users/account.html:102
#: users/templates/users/preferences.html:168 #: users/templates/users/preferences.html:187
#: users/templates/users/preferences.html:193 #: users/templates/users/preferences.html:212
msgid "Save" msgid "Save"
msgstr "保存" msgstr "保存"
@ -3653,70 +3653,78 @@ msgid "Language"
msgstr "語言" msgstr "語言"
#: users/templates/users/preferences.html:140 #: users/templates/users/preferences.html:140
msgid "Automatic bookmark for these categories"
msgstr "以下類型自動加入書籤"
#: users/templates/users/preferences.html:153
msgid "When start to read/watch/play/... an item in these categories, a bookmark will be created automatically. Bookmarks can be viewed and managed in most <a href=\"https://joinmastodon.org/apps\" target=\"_blank\">Mastodon compatible apps</a>; your replies to these posts will automatically become notes for the item."
msgstr "將以下類型的條目設置爲在讀/在看/在玩/...時,自動把相應帖文添加爲書籤。這些書籤帖文可在登錄<a href=\"https://joinmastodon.org/apps\" target=\"_blank\">應用程序</a>(如<a href=\"https://phanpy.social/#/login?instance=neodb.social&submit=1\" target=\"_blank\">Phanpy</a>等)後查看和管理,你對這些帖子的回覆會自動成爲該條目的筆記。"
#: users/templates/users/preferences.html:157
msgid "Hide these categories in search results" msgid "Hide these categories in search results"
msgstr "搜索時不顯示以下類型" msgstr "搜索時不顯示以下類型"
#: users/templates/users/preferences.html:156 #: users/templates/users/preferences.html:175
msgid "Profile visible to anonymous web visitors and search engines" msgid "Profile visible to anonymous web visitors and search engines"
msgstr "匿名訪客和搜索引擎可以查看你的個人主頁" msgstr "匿名訪客和搜索引擎可以查看你的個人主頁"
#: users/templates/users/preferences.html:157 #: users/templates/users/preferences.html:176
msgid "this option limits web visits only; to limit fediverse visibility, choose followers only or mentioned only when posting" msgid "this option limits web visits only; to limit fediverse visibility, choose followers only or mentioned only when posting"
msgstr "此選項僅針對網頁訪客,如果不希望被聯邦網絡用戶看到請在發表時選擇僅關注者或本人" msgstr "此選項僅針對網頁訪客,如果不希望被聯邦網絡用戶看到請在發表時選擇僅關注者或本人"
#: users/templates/users/preferences.html:165 #: users/templates/users/preferences.html:184
msgid "Show your name on item page if you recently edited it" msgid "Show your name on item page if you recently edited it"
msgstr "顯示你是某條目的最近編輯者" msgstr "顯示你是某條目的最近編輯者"
#: users/templates/users/preferences.html:174 #: users/templates/users/preferences.html:193
msgid "Settings for current device" msgid "Settings for current device"
msgstr "當前設備設置" msgstr "當前設備設置"
#: users/templates/users/preferences.html:176 #: users/templates/users/preferences.html:195
msgid "theme" msgid "theme"
msgstr "主題" msgstr "主題"
#: users/templates/users/preferences.html:179 #: users/templates/users/preferences.html:198
msgid "system" msgid "system"
msgstr "系統" msgstr "系統"
#: users/templates/users/preferences.html:181 #: users/templates/users/preferences.html:200
msgid "light" msgid "light"
msgstr "明亮" msgstr "明亮"
#: users/templates/users/preferences.html:183 #: users/templates/users/preferences.html:202
msgid "dark" msgid "dark"
msgstr "暗色" msgstr "暗色"
#: users/templates/users/preferences.html:185 #: users/templates/users/preferences.html:204
msgid "Focus mode" msgid "Focus mode"
msgstr "專注模式" msgstr "專注模式"
#: users/templates/users/preferences.html:188 #: users/templates/users/preferences.html:207
msgid "hide reviews and ratings from other users" msgid "hide reviews and ratings from other users"
msgstr "啓用專注模式後搜索和條目頁面將不再顯示來自他人的評價和打分" msgstr "啓用專注模式後搜索和條目頁面將不再顯示來自他人的評價和打分"
#: users/templates/users/preferences.html:190 #: users/templates/users/preferences.html:209
msgid "Custom styles" msgid "Custom styles"
msgstr "自定義樣式代碼" msgstr "自定義樣式代碼"
#: users/templates/users/preferences.html:209 #: users/templates/users/preferences.html:228
msgid "Settings for current device saved" msgid "Settings for current device saved"
msgstr "當前設備設置已保存" msgstr "當前設備設置已保存"
#: users/templates/users/preferences.html:215 #: users/templates/users/preferences.html:234
msgid "Additional Settings" msgid "Additional Settings"
msgstr "更多設置" msgstr "更多設置"
#: users/templates/users/preferences.html:217 #: users/templates/users/preferences.html:236
msgid "View authorized applications" msgid "View authorized applications"
msgstr "查看已授權的應用程序" msgstr "查看已授權的應用程序"
#: users/templates/users/preferences.html:221 #: users/templates/users/preferences.html:240
msgid "Migrate account" msgid "Migrate account"
msgstr "遷移賬號" msgstr "遷移賬號"
#: users/templates/users/preferences.html:223 #: users/templates/users/preferences.html:242
msgid "Link an email so that you can migrate followers from other Fediverse instances." msgid "Link an email so that you can migrate followers from other Fediverse instances."
msgstr "關聯電子郵件後方可從其他實例遷入。" msgstr "關聯電子郵件後方可從其他實例遷入。"

@ -1 +1 @@
Subproject commit 03a4f54a8f9bd3d06dd9f466d40d6f5853699923 Subproject commit d955f37804cf4e39a0e36eb1b394c00cbb64e16a

View file

@ -1118,4 +1118,38 @@ class Migration(migrations.Migration):
"db_table": "api_authorization", "db_table": "api_authorization",
}, },
), ),
migrations.CreateModel(
name="Bookmark",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("created", models.DateTimeField(auto_now_add=True)),
(
"identity",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="bookmarks",
to="takahe.identity",
),
),
(
"post",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="bookmarks",
to="takahe.post",
),
),
],
options={
"db_table": "users_bookmark",
},
),
] ]

View file

@ -2215,3 +2215,21 @@ class Token(models.Model):
revoked = models.DateTimeField(blank=True, null=True) revoked = models.DateTimeField(blank=True, null=True)
# push_subscription: "PushSubscription" # push_subscription: "PushSubscription"
class Bookmark(models.Model):
class Meta:
db_table = "users_bookmark"
identity = models.ForeignKey(
"takahe.Identity",
on_delete=models.CASCADE,
related_name="bookmarks",
)
post = models.ForeignKey(
"takahe.Post",
on_delete=models.CASCADE,
related_name="bookmarks",
)
created = models.DateTimeField(auto_now_add=True)

View file

@ -996,3 +996,7 @@ class Takahe:
@staticmethod @staticmethod
def get_token(token: str) -> Token | None: def get_token(token: str) -> Token | None:
return Token.objects.filter(token=token).first() return Token.objects.filter(token=token).first()
@staticmethod
def bookmark(post_pk: int, identity_pk: int):
Bookmark.objects.get_or_create(post_id=post_pk, identity_id=identity_pk)

View file

@ -23,6 +23,10 @@ from takahe.utils import Takahe
from .user import User from .user import User
def _default_book_cats():
return ["book"]
class Preference(models.Model): class Preference(models.Model):
user = models.OneToOneField(User, models.CASCADE, primary_key=True) user = models.OneToOneField(User, models.CASCADE, primary_key=True)
profile_layout = models.JSONField( profile_layout = models.JSONField(
@ -48,6 +52,7 @@ class Preference(models.Model):
show_last_edit = models.PositiveSmallIntegerField(null=False, default=1) show_last_edit = models.PositiveSmallIntegerField(null=False, default=1)
no_anonymous_view = models.PositiveSmallIntegerField(default=0) # TODO remove no_anonymous_view = models.PositiveSmallIntegerField(default=0) # TODO remove
hidden_categories = models.JSONField(default=list) hidden_categories = models.JSONField(default=list)
auto_bookmark_cats = models.JSONField(default=_default_book_cats)
mastodon_append_tag = models.CharField(max_length=2048, default="") mastodon_append_tag = models.CharField(max_length=2048, default="")
mastodon_default_repost = models.BooleanField(null=False, default=True) mastodon_default_repost = models.BooleanField(null=False, default=True)
mastodon_repost_mode = models.PositiveSmallIntegerField(null=False, default=0) mastodon_repost_mode = models.PositiveSmallIntegerField(null=False, default=0)

View file

@ -136,15 +136,34 @@
{% endfor %} {% endfor %}
</select> </select>
</fieldset> </fieldset>
<fieldset>
<label>{% trans 'Automatic bookmark for these categories' %}</label>
<select name="auto_bookmark_cats" size="3" multiple>
{% all_categories as categories %}
{% for c in categories %}
{% if c.value != 'collection' %}
<option value="{{ c.value }}"
{% if c in request.user.preference.auto_bookmark_cats %}selected{% endif %}>
{{ c.label }}
</option>
{% endif %}
{% endfor %}
</select>
<small>
{% blocktrans %}When start to read/watch/play/... an item in these categories, a bookmark will be created automatically. Bookmarks can be viewed and managed in most <a href="https://joinmastodon.org/apps" target="_blank">Mastodon compatible apps</a>; your replies to these posts will automatically become notes for the item.{% endblocktrans %}
</small>
</fieldset>
<fieldset> <fieldset>
<label>{% trans 'Hide these categories in search results' %}</label> <label>{% trans 'Hide these categories in search results' %}</label>
<select name="hidden_categories" size="3" multiple> <select name="hidden_categories" size="3" multiple>
{% all_categories as categories %} {% all_categories as categories %}
{% for c in categories %} {% for c in categories %}
<option value="{{ c.value }}" {% if c.value != 'collection' %}
{% if c in request.user.preference.hidden_categories %}selected{% endif %}> <option value="{{ c.value }}"
{{ c.label }} {% if c in request.user.preference.hidden_categories %}selected{% endif %}>
</option> {{ c.label }}
</option>
{% endif %}
{% endfor %} {% endfor %}
</select> </select>
</fieldset> </fieldset>