Groups: Add ability to hide posts from the global feed

This commit is contained in:
Maxim Leshchenko 2022-01-02 00:52:35 +02:00
parent f820707070
commit cca9151661
No known key found for this signature in database
GPG key ID: BB9C44A8733FBEEE
7 changed files with 22 additions and 13 deletions

View file

@ -140,6 +140,11 @@ class Club extends RowModel
return (bool) $this->getRecord()->display_topics_above_wall; return (bool) $this->getRecord()->display_topics_above_wall;
} }
function isHideFromGlobalFeedEnabled(): bool
{
return (bool) $this->getRecord()->hide_from_global_feed;
}
function getType(): int function getType(): int
{ {
return $this->getRecord()->type; return $this->getRecord()->type;

View file

@ -207,8 +207,8 @@ final class GroupPresenter extends OpenVKPresenter
$club->setShortcode(empty($this->postParam("shortcode")) ? NULL : $this->postParam("shortcode")); $club->setShortcode(empty($this->postParam("shortcode")) ? NULL : $this->postParam("shortcode"));
$club->setWall(empty($this->postParam("wall")) ? 0 : 1); $club->setWall(empty($this->postParam("wall")) ? 0 : 1);
$club->setAdministrators_List_Display(empty($this->postParam("administrators_list_display")) ? 0 : $this->postParam("administrators_list_display")); $club->setAdministrators_List_Display(empty($this->postParam("administrators_list_display")) ? 0 : $this->postParam("administrators_list_display"));
$club->setEveryone_Can_Create_Topics(empty($this->postParam("everyone_can_create_topics")) ? 0 : 1); $club->setDisplay_Topics_Above_Wall(empty($this->postParam("display_topics_above_wall")) ? 0 : 1);
$club->setDisplay_Topics_Above_Wall(empty($this->postParam("display_topics_above_wall")) ? 0 : 1);; $club->setHide_From_Global_Feed(empty($this->postParam("hide_from_global_feed")) ? 0 : 1);
$website = $this->postParam("website") ?? ""; $website = $this->postParam("website") ?? "";
if(empty($website)) if(empty($website))

View file

@ -122,24 +122,24 @@ final class WallPresenter extends OpenVKPresenter
$page = (int) ($_GET["p"] ?? 1); $page = (int) ($_GET["p"] ?? 1);
$pPage = min((int) ($_GET["posts"] ?? OPENVK_DEFAULT_PER_PAGE), 50); $pPage = min((int) ($_GET["posts"] ?? OPENVK_DEFAULT_PER_PAGE), 50);
$posts = DatabaseConnection::i()
->getContext() $queryBase = "FROM `posts` LEFT JOIN `groups` ON GREATEST(`posts`.`wall`, 0) = 0 AND `groups`.`id` = ABS(`posts`.`wall`) WHERE (`groups`.`hide_from_global_feed` = 0 OR `groups`.`name` IS NULL) AND `posts`.`deleted` = 0";
->table("posts")
->where("deleted", 0)
->order("created DESC");
if($this->user->identity->getNsfwTolerance() === User::NSFW_INTOLERANT) if($this->user->identity->getNsfwTolerance() === User::NSFW_INTOLERANT)
$posts = $posts->where("nsfw", false); $queryBase .= " AND `nsfw` = 0";
$posts = DatabaseConnection::i()->getConnection()->query("SELECT `posts`.`id` " . $queryBase . " ORDER BY `created` DESC LIMIT " . $pPage . " OFFSET " . ($page - 1) * $pPage);
$count = DatabaseConnection::i()->getConnection()->query("SELECT COUNT(*) " . $queryBase)->fetch()->{"COUNT(*)"};
$this->template->_template = "Wall/Feed.xml"; $this->template->_template = "Wall/Feed.xml";
$this->template->globalFeed = true; $this->template->globalFeed = true;
$this->template->paginatorConf = (object) [ $this->template->paginatorConf = (object) [
"count" => sizeof($posts), "count" => $count,
"page" => (int) ($_GET["p"] ?? 1), "page" => (int) ($_GET["p"] ?? 1),
"amount" => sizeof($posts->page($page, $pPage)), "amount" => sizeof($posts),
"perPage" => $pPage, "perPage" => $pPage,
]; ];
foreach($posts->page($page, $pPage) as $post) foreach($posts as $post)
$this->template->posts[] = $this->posts->get($post->id); $this->template->posts[] = $this->posts->get($post->id);
} }

View file

@ -74,7 +74,8 @@
<span class="nobold">{_wall}: </span> <span class="nobold">{_wall}: </span>
</td> </td>
<td> <td>
<input type="checkbox" name="wall" value="1" {if $club->canPost()}checked{/if}/> {_group_allow_post_for_everyone} <input type="checkbox" name="wall" value="1" n:attr="checked => $club->canPost()" /> {_group_allow_post_for_everyone}<br>
<input type="checkbox" name="hide_from_global_feed" value="1" n:attr="checked => $club->isHideFromGlobalFeedEnabled()" /> {_group_hide_from_global_feed}
</td> </td>
</tr> </tr>
<tr> <tr>

View file

@ -0,0 +1 @@
ALTER TABLE `groups` ADD COLUMN `hide_from_global_feed` boolean DEFAULT 0 NOT NULL AFTER `display_topics_above_wall`;

View file

@ -245,6 +245,7 @@
"hidden_yes" = "Hidden: Yes"; "hidden_yes" = "Hidden: Yes";
"hidden_no" = "Hidden: No"; "hidden_no" = "Hidden: No";
"group_allow_post_for_everyone" = "Allow posting for everyone"; "group_allow_post_for_everyone" = "Allow posting for everyone";
"group_hide_from_global_feed" = "Don't display posts in the global feed";
"statistics" = "Statistics"; "statistics" = "Statistics";
"group_administrators_list" = "Admins list"; "group_administrators_list" = "Admins list";
"group_display_only_creator" = "Display only group creator"; "group_display_only_creator" = "Display only group creator";

View file

@ -255,6 +255,7 @@
"hidden_yes" = "Скрыт: Да"; "hidden_yes" = "Скрыт: Да";
"hidden_no" = "Скрыт: Нет"; "hidden_no" = "Скрыт: Нет";
"group_allow_post_for_everyone" = "Разрешить публиковать записи всем"; "group_allow_post_for_everyone" = "Разрешить публиковать записи всем";
"group_hide_from_global_feed" = "Не отображать публикации в глобальной ленте";
"statistics" = "Статистика"; "statistics" = "Статистика";
"group_administrators_list" = "Список админов"; "group_administrators_list" = "Список админов";
"group_display_only_creator" = "Отображать только создателя группы"; "group_display_only_creator" = "Отображать только создателя группы";