From 61205f64d9cf29993f564508f9206cc56ef97850 Mon Sep 17 00:00:00 2001 From: lalka2016 <99399973+lalka2016@users.noreply.github.com> Date: Mon, 31 Jul 2023 19:14:24 +0300 Subject: [PATCH] Add notifications of new suggestion posts --- VKAPI/Handlers/Wall.php | 14 +++++++++++++- .../NewSuggestedPostsNotification.php | 13 +++++++++++++ Web/Presenters/WallPresenter.php | 16 +++++++++++++++- .../components/notifications/7/_18_5_.xml | 5 +++++ locales/en.strings | 2 ++ locales/ru.strings | 2 ++ 6 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 Web/Models/Entities/Notifications/NewSuggestedPostsNotification.php create mode 100644 Web/Presenters/templates/components/notifications/7/_18_5_.xml diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index 3b93be2f..74eacb8e 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -1,7 +1,7 @@ user->identity))->emit(); if($owner_id < 0 && !$wallOwner->canBeModifiedBy($this->getUser()) && $wallOwner->getWallType() == 2) { + $suggsCount = (new PostsRepo)->getSuggestedPostsCount($wallOwner->getId()); + + if($suggsCount % 10 == 0) { + $managers = $wallOwner->getManagers(); + $owner = $wallOwner->getOwner(); + (new NewSuggestedPostsNotification($owner, $wallOwner))->emit(); + + foreach($managers as $manager) { + (new NewSuggestedPostsNotification($manager->getUser(), $wallOwner))->emit(); + } + } + return (object)["post_id" => "on_view"]; } diff --git a/Web/Models/Entities/Notifications/NewSuggestedPostsNotification.php b/Web/Models/Entities/Notifications/NewSuggestedPostsNotification.php new file mode 100644 index 00000000..e1795b08 --- /dev/null +++ b/Web/Models/Entities/Notifications/NewSuggestedPostsNotification.php @@ -0,0 +1,13 @@ +getOwner(), strip_tags($post->getText())))->emit(); if($wall < 0 && !$wallOwner->canBeModifiedBy($this->user->identity) && $wallOwner->getWallType() == 2) { + $suggsCount = $this->posts->getSuggestedPostsCount($wallOwner->getId()); + + # Возможно, это заебёт админов групп, но так они хотя бы про паблик вспомнят + # Мб рандома добавить? + if($suggsCount % 10 == 0) { + $managers = $wallOwner->getManagers(); + $owner = $wallOwner->getOwner(); + (new NewSuggestedPostsNotification($owner, $wallOwner))->emit(); + + foreach($managers as $manager) { + (new NewSuggestedPostsNotification($manager->getUser(), $wallOwner))->emit(); + } + } + $this->redirect("/club".$wallOwner->getId()."/suggested"); } else { $this->redirect($wallOwner->getURL()); diff --git a/Web/Presenters/templates/components/notifications/7/_18_5_.xml b/Web/Presenters/templates/components/notifications/7/_18_5_.xml new file mode 100644 index 00000000..4c012edd --- /dev/null +++ b/Web/Presenters/templates/components/notifications/7/_18_5_.xml @@ -0,0 +1,5 @@ +{var $club = $notification->getModel(1)} + +{_nt_in_club} +{$club->getName()} +{_nt_new_suggested_posts} \ No newline at end of file diff --git a/locales/en.strings b/locales/en.strings index 020076a9..e7f616ac 100644 --- a/locales/en.strings +++ b/locales/en.strings @@ -712,6 +712,8 @@ "nt_commented_yours" = "commented"; "nt_written_on_your_wall" = "wrote on your wall"; "nt_accepted_your_post" = "accepted your suggested"; +"nt_in_club" = "In group"; +"nt_new_suggested_posts" = "new posts in suggestions"; "nt_made_you_admin" = "appointed you in the community"; "nt_from" = "from"; diff --git a/locales/ru.strings b/locales/ru.strings index a4f06e47..47a76942 100644 --- a/locales/ru.strings +++ b/locales/ru.strings @@ -671,6 +671,8 @@ "nt_commented_yours" = "оставил(а) комментарий под"; "nt_written_on_your_wall" = "написал(а) на вашей стене"; "nt_accepted_your_post" = "опубликовало вашу предложенную"; +"nt_in_club" = "В сообществе"; +"nt_new_suggested_posts" = "новые записи в предложке"; "nt_made_you_admin" = "назначил(а) вас руководителем сообщества"; "nt_from" = "от"; "nt_yours_adjective" = "вашим";