From a0311dfb2bdf33d80b0a556b93a0169d22ece809 Mon Sep 17 00:00:00 2001 From: Chisato Nishikigi Date: Tue, 22 Oct 2024 02:09:48 +0800 Subject: [PATCH] feat(sticky): make excerpt optional in sticky (#4016) --- extensions/sticky/extend.php | 4 +++ extensions/sticky/js/src/admin/extend.tsx | 25 +++++++++++++------ .../sticky/js/src/forum/addStickyExcerpt.js | 4 +-- extensions/sticky/locale/en.yml | 1 + 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/extensions/sticky/extend.php b/extensions/sticky/extend.php index 4ef2ab7c8..fac39e501 100644 --- a/extensions/sticky/extend.php +++ b/extensions/sticky/extend.php @@ -31,6 +31,10 @@ return [ new Extend\Locales(__DIR__.'/locale'), + (new Extend\Settings()) + ->serializeToForum('excerptDisplayEnabled', 'flarum-sticky.enable_display_excerpt', 'boolval') + ->default('flarum-sticky.enable_display_excerpt', true), + (new Extend\Model(Discussion::class)) ->cast('is_sticky', 'bool'), diff --git a/extensions/sticky/js/src/admin/extend.tsx b/extensions/sticky/js/src/admin/extend.tsx index 2093712b7..3ca276305 100644 --- a/extensions/sticky/js/src/admin/extend.tsx +++ b/extensions/sticky/js/src/admin/extend.tsx @@ -15,11 +15,22 @@ export default [ 'moderate', 95 ) - .setting(() => ({ - setting: 'flarum-sticky.only_sticky_unread_discussions', - name: 'onlyStickyUnreadDiscussions', - type: 'boolean', - label: app.translator.trans('flarum-sticky.admin.settings.only_sticky_unread_discussions_label'), - help: app.translator.trans('flarum-sticky.admin.settings.only_sticky_unread_discussions_help'), - })), + .setting( + () => ({ + setting: 'flarum-sticky.only_sticky_unread_discussions', + name: 'onlyStickyUnreadDiscussions', + type: 'boolean', + label: app.translator.trans('flarum-sticky.admin.settings.only_sticky_unread_discussions_label'), + help: app.translator.trans('flarum-sticky.admin.settings.only_sticky_unread_discussions_help'), + }), + 90 + ) + .setting( + () => ({ + type: 'switch', + setting: 'flarum-sticky.enable_display_excerpt', + label: app.translator.trans('flarum-sticky.admin.settings.enable_display_excerpt'), + }), + 100 + ), ]; diff --git a/extensions/sticky/js/src/forum/addStickyExcerpt.js b/extensions/sticky/js/src/forum/addStickyExcerpt.js index e8e5ffc24..e19d7e25e 100644 --- a/extensions/sticky/js/src/forum/addStickyExcerpt.js +++ b/extensions/sticky/js/src/forum/addStickyExcerpt.js @@ -8,7 +8,7 @@ import { truncate } from 'flarum/common/utils/string'; export default function addStickyExcerpt() { extend(DiscussionListState.prototype, 'requestParams', function (params) { - if (app.current.matches(IndexPage) || app.current.matches(DiscussionPage)) { + if (app.forum.attribute('excerptDisplayEnabled') && (app.current.matches(IndexPage) || app.current.matches(DiscussionPage))) { params.include.push('firstPost'); } }); @@ -16,7 +16,7 @@ export default function addStickyExcerpt() { extend(DiscussionListItem.prototype, 'infoItems', function (items) { const discussion = this.attrs.discussion; - if (discussion.isSticky() && !this.attrs.params.q && !discussion.lastReadPostNumber()) { + if (app.forum.attribute('excerptDisplayEnabled') && discussion.isSticky() && !this.attrs.params.q && !discussion.lastReadPostNumber()) { const firstPost = discussion.firstPost(); if (firstPost) { diff --git a/extensions/sticky/locale/en.yml b/extensions/sticky/locale/en.yml index 05b37d701..03868879a 100644 --- a/extensions/sticky/locale/en.yml +++ b/extensions/sticky/locale/en.yml @@ -7,6 +7,7 @@ flarum-sticky: # Translations in this namespace are used by the admin interface. admin: settings: + enable_display_excerpt: Show an excerpt of the first post when a sticky discussion is unread only_sticky_unread_discussions_label: Only sticky unread discussions only_sticky_unread_discussions_help: On the All Discussions page, unread sticky discussions pin to the top, while read sticky discussions follow the regular order.