diff --git a/journal/models/mark.py b/journal/models/mark.py index 5f97d44e..2c107e9c 100644 --- a/journal/models/mark.py +++ b/journal/models/mark.py @@ -292,20 +292,24 @@ class Mark: ) self.rating_grade = rating_grade # publish a new or updated ActivityPub post + user = self.owner.user 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 = ( - f"@{self.owner.user.mastodon_acct}\n" + f"@{user.mastodon_acct}\n" if visibility > 0 and share_to_mastodon and not classic_repost else "" ) 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 if post and share_to_mastodon: if classic_repost: share_mark(self, post_as_new) else: - boost_toot_later(self.owner.user, post.url) + boost_toot_later(user, post.url) return True def delete(self, keep_tags=False): diff --git a/locale/zh_Hans/LC_MESSAGES/django.po b/locale/zh_Hans/LC_MESSAGES/django.po index ec4c6408..7a14208c 100644 --- a/locale/zh_Hans/LC_MESSAGES/django.po +++ b/locale/zh_Hans/LC_MESSAGES/django.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\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" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1032,8 +1032,8 @@ msgstr "创建" #: journal/templates/mark.html:147 journal/templates/note.html:39 #: 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/preferences.html:168 -#: users/templates/users/preferences.html:193 +#: users/templates/users/preferences.html:187 +#: users/templates/users/preferences.html:212 msgid "Save" msgstr "保存" @@ -3653,70 +3653,78 @@ msgid "Language" msgstr "语言" #: 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 Mastodon compatible apps; your replies to these posts will automatically become notes for the item." +msgstr "将以下类型的条目设置为在读/在看/在玩/...时,自动把相应帖文添加为书签。这些书签帖文可在登录应用程序(如Phanpy等)后查看和管理,你对这些帖子的回复会自动成为该条目的笔记。" + +#: users/templates/users/preferences.html:157 msgid "Hide these categories in search results" msgstr "搜索时不显示以下类型" -#: users/templates/users/preferences.html:156 +#: users/templates/users/preferences.html:175 msgid "Profile visible to anonymous web visitors and search engines" 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" 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" msgstr "显示你是某条目的最近编辑者" -#: users/templates/users/preferences.html:174 +#: users/templates/users/preferences.html:193 msgid "Settings for current device" msgstr "当前设备设置" -#: users/templates/users/preferences.html:176 +#: users/templates/users/preferences.html:195 msgid "theme" msgstr "主题" -#: users/templates/users/preferences.html:179 +#: users/templates/users/preferences.html:198 msgid "system" msgstr "系统" -#: users/templates/users/preferences.html:181 +#: users/templates/users/preferences.html:200 msgid "light" msgstr "明亮" -#: users/templates/users/preferences.html:183 +#: users/templates/users/preferences.html:202 msgid "dark" msgstr "暗色" -#: users/templates/users/preferences.html:185 +#: users/templates/users/preferences.html:204 msgid "Focus mode" msgstr "专注模式" -#: users/templates/users/preferences.html:188 +#: users/templates/users/preferences.html:207 msgid "hide reviews and ratings from other users" msgstr "启用专注模式后搜索和条目页面将不再显示来自他人的评价和打分" -#: users/templates/users/preferences.html:190 +#: users/templates/users/preferences.html:209 msgid "Custom styles" msgstr "自定义样式代码" -#: users/templates/users/preferences.html:209 +#: users/templates/users/preferences.html:228 msgid "Settings for current device saved" msgstr "当前设备设置已保存" -#: users/templates/users/preferences.html:215 +#: users/templates/users/preferences.html:234 msgid "Additional Settings" msgstr "更多设置" -#: users/templates/users/preferences.html:217 +#: users/templates/users/preferences.html:236 msgid "View authorized applications" msgstr "查看已授权的应用程序" -#: users/templates/users/preferences.html:221 +#: users/templates/users/preferences.html:240 msgid "Migrate account" 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." msgstr "关联电子邮件后方可从其他实例迁入。" diff --git a/locale/zh_Hant/LC_MESSAGES/django.po b/locale/zh_Hant/LC_MESSAGES/django.po index 39a999ca..19d2e5e3 100644 --- a/locale/zh_Hant/LC_MESSAGES/django.po +++ b/locale/zh_Hant/LC_MESSAGES/django.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\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" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1032,8 +1032,8 @@ msgstr "創建" #: journal/templates/mark.html:147 journal/templates/note.html:39 #: 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/preferences.html:168 -#: users/templates/users/preferences.html:193 +#: users/templates/users/preferences.html:187 +#: users/templates/users/preferences.html:212 msgid "Save" msgstr "保存" @@ -3653,70 +3653,78 @@ msgid "Language" msgstr "語言" #: 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 Mastodon compatible apps; your replies to these posts will automatically become notes for the item." +msgstr "將以下類型的條目設置爲在讀/在看/在玩/...時,自動把相應帖文添加爲書籤。這些書籤帖文可在登錄應用程序(如Phanpy等)後查看和管理,你對這些帖子的回覆會自動成爲該條目的筆記。" + +#: users/templates/users/preferences.html:157 msgid "Hide these categories in search results" msgstr "搜索時不顯示以下類型" -#: users/templates/users/preferences.html:156 +#: users/templates/users/preferences.html:175 msgid "Profile visible to anonymous web visitors and search engines" 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" 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" msgstr "顯示你是某條目的最近編輯者" -#: users/templates/users/preferences.html:174 +#: users/templates/users/preferences.html:193 msgid "Settings for current device" msgstr "當前設備設置" -#: users/templates/users/preferences.html:176 +#: users/templates/users/preferences.html:195 msgid "theme" msgstr "主題" -#: users/templates/users/preferences.html:179 +#: users/templates/users/preferences.html:198 msgid "system" msgstr "系統" -#: users/templates/users/preferences.html:181 +#: users/templates/users/preferences.html:200 msgid "light" msgstr "明亮" -#: users/templates/users/preferences.html:183 +#: users/templates/users/preferences.html:202 msgid "dark" msgstr "暗色" -#: users/templates/users/preferences.html:185 +#: users/templates/users/preferences.html:204 msgid "Focus mode" msgstr "專注模式" -#: users/templates/users/preferences.html:188 +#: users/templates/users/preferences.html:207 msgid "hide reviews and ratings from other users" msgstr "啓用專注模式後搜索和條目頁面將不再顯示來自他人的評價和打分" -#: users/templates/users/preferences.html:190 +#: users/templates/users/preferences.html:209 msgid "Custom styles" msgstr "自定義樣式代碼" -#: users/templates/users/preferences.html:209 +#: users/templates/users/preferences.html:228 msgid "Settings for current device saved" msgstr "當前設備設置已保存" -#: users/templates/users/preferences.html:215 +#: users/templates/users/preferences.html:234 msgid "Additional Settings" msgstr "更多設置" -#: users/templates/users/preferences.html:217 +#: users/templates/users/preferences.html:236 msgid "View authorized applications" msgstr "查看已授權的應用程序" -#: users/templates/users/preferences.html:221 +#: users/templates/users/preferences.html:240 msgid "Migrate account" 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." msgstr "關聯電子郵件後方可從其他實例遷入。" diff --git a/neodb-takahe b/neodb-takahe index 03a4f54a..d955f378 160000 --- a/neodb-takahe +++ b/neodb-takahe @@ -1 +1 @@ -Subproject commit 03a4f54a8f9bd3d06dd9f466d40d6f5853699923 +Subproject commit d955f37804cf4e39a0e36eb1b394c00cbb64e16a diff --git a/takahe/migrations/0001_initial.py b/takahe/migrations/0001_initial.py index cb8f1c88..00e00158 100644 --- a/takahe/migrations/0001_initial.py +++ b/takahe/migrations/0001_initial.py @@ -1118,4 +1118,38 @@ class Migration(migrations.Migration): "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", + }, + ), ] diff --git a/takahe/models.py b/takahe/models.py index 6a73080e..dec4c40c 100644 --- a/takahe/models.py +++ b/takahe/models.py @@ -2215,3 +2215,21 @@ class Token(models.Model): revoked = models.DateTimeField(blank=True, null=True) # 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) diff --git a/takahe/utils.py b/takahe/utils.py index 0649e962..776c099f 100644 --- a/takahe/utils.py +++ b/takahe/utils.py @@ -996,3 +996,7 @@ class Takahe: @staticmethod def get_token(token: str) -> Token | None: 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) diff --git a/users/models/preference.py b/users/models/preference.py index a4423d51..1f267ce2 100644 --- a/users/models/preference.py +++ b/users/models/preference.py @@ -23,6 +23,10 @@ from takahe.utils import Takahe from .user import User +def _default_book_cats(): + return ["book"] + + class Preference(models.Model): user = models.OneToOneField(User, models.CASCADE, primary_key=True) profile_layout = models.JSONField( @@ -48,6 +52,7 @@ class Preference(models.Model): show_last_edit = models.PositiveSmallIntegerField(null=False, default=1) no_anonymous_view = models.PositiveSmallIntegerField(default=0) # TODO remove 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_default_repost = models.BooleanField(null=False, default=True) mastodon_repost_mode = models.PositiveSmallIntegerField(null=False, default=0) diff --git a/users/templates/users/preferences.html b/users/templates/users/preferences.html index d5b7771e..fec1b58f 100644 --- a/users/templates/users/preferences.html +++ b/users/templates/users/preferences.html @@ -136,15 +136,34 @@ {% endfor %} +
+ + + + {% 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 Mastodon compatible apps; your replies to these posts will automatically become notes for the item.{% endblocktrans %} + +