Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
10729d8
Wall: add early suggestions
Jul 30, 2023
eff2b2b
Fix br
Jul 31, 2023
213f1e2
Fix empty posts
Jul 31, 2023
3809b82
fck
Jul 31, 2023
cd54662
Add offset for api
Jul 31, 2023
61205f6
Add notifications of new suggestion posts
Jul 31, 2023
9a20682
Fix mentions in suggested posts
Aug 1, 2023
1fcc372
🤮🤢
Aug 2, 2023
4ee9a0d
Change regex
Aug 4, 2023
9543fb6
Add da koroche pohuy
Aug 4, 2023
cb8dd4d
Эдд апи метходс
Aug 4, 2023
c3ac279
Pon
Aug 6, 2023
5e67163
Add skloneniyia
Aug 6, 2023
c7e76cc
newlines
Aug 6, 2023
9ff4ff4
int
Aug 6, 2023
be85edf
Update loaders and add avtopodgruzka postov
Aug 6, 2023
c4c476e
Update JOERGK.strings
Aug 6, 2023
2226013
Blin
Aug 7, 2023
ccf618a
Remove repeated code, fix loaded buttons on chr...
Aug 9, 2023
7065465
Merge branch 'master' into suggests
Aug 9, 2023
499bec2
Fix polls
Aug 9, 2023
e9a0b5a
Merge branch 'suggests' of https://github.com/lalka2016/openvkuh into…
Aug 9, 2023
f1fdb15
Fihes
Aug 10, 2023
793a87c
Merge branch 'master' into suggests
Aug 11, 2023
adef21d
Remove ability to delete your accepted psto
Aug 12, 2023
f585183
oi blin
Aug 13, 2023
c8ef5cc
Improvements 2 api
Aug 15, 2023
5f51881
g
Aug 17, 2023
6bd475a
openvk.uk
Aug 19, 2023
77fe2fb
aiaks
Aug 20, 2023
ba77162
al_wall.js -> al_suggestions.js
Aug 21, 2023
2ddd454
👨‍💻 Add 👨‍💻 fading 👨‍💻
Aug 27, 2023
e1f1035
Add "owner's posts' and "other's posts"
Aug 28, 2023
500107f
planshet openvk
Sep 2, 2023
a0e8958
Merge branch 'master' into suggests
Oct 8, 2023
029d21c
Simplefai ze kod
Oct 10, 2023
12775d0
Merge branch 'master' into suggests
Nov 15, 2023
029ce27
PHP 8 FIX WATAFAK
Nov 15, 2023
2cc1b03
Add indesk
Nov 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions ServiceAPI/Wall.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace openvk\ServiceAPI;
use openvk\Web\Models\Entities\Post;
use openvk\Web\Models\Entities\User;
use openvk\Web\Models\Entities\Notifications\{PostAcceptedNotification};
use openvk\Web\Models\Repositories\{Posts, Notes};

class Wall implements Handler
Expand Down Expand Up @@ -95,4 +96,64 @@ function getMyNotes(callable $resolve, callable $reject)

$resolve($arr);
}

function declinePost(int $id, callable $resolve, callable $reject)
{
$post = $this->posts->get($id);
if(!$post || $post->isDeleted())
$reject(11, "No post with id=$id");

if($post->getSuggestionType() == 0)
$reject(19, "Post is not suggested");

if($post->getSuggestionType() == 2)
$reject(10, "Post is already declined");

if(!$post->canBePinnedBy($this->user))
$reject(22, "Access to post denied");

$post->setSuggested(2);
$post->setDeleted(1);
$post->save();

$resolve($this->posts->getSuggestedPostsCount($post->getWallOwner()->getId()));
}

function acceptPost(int $id, bool $sign, string $content, callable $resolve, callable $reject)
{
$post = $this->posts->get($id);
if(!$post || $post->isDeleted())
$reject(11, "No post with id=$id");

if($post->getSuggestionType() == 0)
$reject(19, "Post is not suggested");

if($post->getSuggestionType() == 2)
$reject(10, "Post is declined");

if(!$post->canBePinnedBy($this->user))
$reject(22, "Access to post denied");

$author = $post->getOwner();
$flags = 0;
$flags |= 0b10000000;

if($sign) {
$flags |= 0b01000000;
}

$post->setSuggested(0);
$post->setCreated(time());
$post->setFlags($flags);

if(mb_strlen($content) > 0) {
$post->setContent($content);
}

$post->save();

(new PostAcceptedNotification($author, $post, $post->getWallOwner()))->emit();

$resolve(["id" => $post->getPrettyId(), "new_count" => $this->posts->getSuggestedPostsCount($post->getWallOwner()->getId())]);
}
}
36 changes: 24 additions & 12 deletions VKAPI/Handlers/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ function edit(
string $description = NULL,
string $screen_name = NULL,
string $website = NULL,
int $wall = NULL,
int $wall = -1,
int $topics = NULL,
int $adminlist = NULL,
int $topicsAboveWall = NULL,
Expand All @@ -303,17 +303,29 @@ function edit(
if(!$club || !$club->canBeModifiedBy($this->getUser())) $this->fail(15, "You can't modify this group.");
if(!empty($screen_name) && !$club->setShortcode($screen_name)) $this->fail(103, "Invalid shortcode.");

!is_null($title) ? $club->setName($title) : NULL;
!is_null($description) ? $club->setAbout($description) : NULL;
!is_null($screen_name) ? $club->setShortcode($screen_name) : NULL;
!is_null($website) ? $club->setWebsite((!parse_url($website, PHP_URL_SCHEME) ? "https://" : "") . $website) : NULL;
!is_null($wall) ? $club->setWall($wall) : NULL;
!is_null($topics) ? $club->setEveryone_Can_Create_Topics($topics) : NULL;
!is_null($adminlist) ? $club->setAdministrators_List_Display($adminlist) : NULL;
!is_null($topicsAboveWall) ? $club->setDisplay_Topics_Above_Wall($topicsAboveWall) : NULL;
!is_null($hideFromGlobalFeed) ? $club->setHide_From_Global_Feed($hideFromGlobalFeed) : NULL;
!empty($title) ? $club->setName($title) : NULL;
!empty($description) ? $club->setAbout($description) : NULL;
!empty($screen_name) ? $club->setShortcode($screen_name) : NULL;
!empty($website) ? $club->setWebsite((!parse_url($website, PHP_URL_SCHEME) ? "https://" : "") . $website) : NULL;

try {
$wall != -1 ? $club->setWall($wall) : NULL;
} catch(\Exception $e) {
$this->fail(50, "Invalid wall value");
}

$club->save();
!empty($topics) ? $club->setEveryone_Can_Create_Topics($topics) : NULL;
!empty($adminlist) ? $club->setAdministrators_List_Display($adminlist) : NULL;
!empty($topicsAboveWall) ? $club->setDisplay_Topics_Above_Wall($topicsAboveWall) : NULL;
!empty($hideFromGlobalFeed) ? $club->setHide_From_Global_Feed($hideFromGlobalFeed) : NULL;

try {
$club->save();
} catch(\TypeError $e) {
$this->fail(15, "Nothing changed");
} catch(\Exception $e) {
$this->fail(18, "An unknown error occurred: maybe you set an incorrect value?");
}

return 1;
}
Expand Down Expand Up @@ -466,7 +478,7 @@ function getSettings(string $group_id)
"title" => $club->getName(),
"description" => $club->getDescription() != NULL ? $club->getDescription() : "",
"address" => $club->getShortcode(),
"wall" => $club->canPost() == true ? 1 : 0,
"wall" => $club->getWallType(), # отличается от вкшных но да ладно
"photos" => 1,
"video" => 0,
"audio" => 0,
Expand Down
143 changes: 139 additions & 4 deletions VKAPI/Handlers/Wall.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php declare(strict_types=1);
namespace openvk\VKAPI\Handlers;
use openvk\Web\Models\Entities\User;
use openvk\Web\Models\Entities\Notifications\{WallPostNotification, RepostNotification, CommentNotification};
use openvk\Web\Models\Entities\Notifications\{PostAcceptedNotification, WallPostNotification, NewSuggestedPostsNotification, RepostNotification, CommentNotification};
use openvk\Web\Models\Repositories\Users as UsersRepo;
use openvk\Web\Models\Entities\Club;
use openvk\Web\Models\Repositories\Clubs as ClubsRepo;
Expand All @@ -18,7 +18,7 @@

final class Wall extends VKAPIRequestHandler
{
function get(int $owner_id, string $domain = "", int $offset = 0, int $count = 30, int $extended = 0): object
function get(int $owner_id, string $domain = "", int $offset = 0, int $count = 30, int $extended = 0, string $filter = "all"): object
{
$this->requireUser();

Expand All @@ -27,7 +27,7 @@ function get(int $owner_id, string $domain = "", int $offset = 0, int $count = 3
$items = [];
$profiles = [];
$groups = [];
$cnt = $posts->getPostCountOnUserWall($owner_id);
$cnt = 0;

if ($owner_id > 0)
$wallOnwer = (new UsersRepo)->get($owner_id);
Expand All @@ -41,7 +41,47 @@ function get(int $owner_id, string $domain = "", int $offset = 0, int $count = 3
if(!$wallOnwer)
$this->fail(15, "Access denied: wall is disabled"); // Don't search for logic here pls

foreach($posts->getPostsFromUsersWall($owner_id, 1, $count, $offset) as $post) {
$iteratorv;

switch($filter) {
case "all":
$iteratorv = $posts->getPostsFromUsersWall($owner_id, 1, $count, $offset);
$cnt = $posts->getPostCountOnUserWall($owner_id);
break;
case "owner":
$this->fail(66666, "Not implemented :(");
break;
case "others":
$this->fail(66666, "Not implemented :(");
break;
case "postponed":
$this->fail(66666, "Otlojka is not implemented :)");
break;
# В вкапи, походу, нету метода, который бы публиковал запись из предложки.
# Либо он закрыт для неофициальных клиентов, как gifts.send
case "suggests":
if($owner_id < 0) {
if($wallOnwer->getWallType() != 2)
$this->fail(125, "Group's wall type is open or closed");

if($wallOnwer->canBeModifiedBy($this->getUser())) {
$iteratorv = $posts->getSuggestedPosts($owner_id * -1, 1, $count, $offset);
$cnt = $posts->getSuggestedPostsCount($owner_id * -1);
} else {
$iteratorv = $posts->getSuggestedPostsByUser($owner_id * -1, $this->getUser()->getId(), 1, $count, $offset);
$cnt = $posts->getSuggestedPostsCountByUser($owner_id * -1, $this->getUser()->getId());
}
} else {
$this->fail(528, "Suggested posts avaiable only at groups");
}

break;
default:
$this->fail(254, "Invalid filter");
break;
}

foreach($iteratorv as $post) {
$from_id = get_class($post->getOwner()) == "openvk\Web\Models\Entities\Club" ? $post->getOwner()->getId() * (-1) : $post->getOwner()->getId();

$attachments = [];
Expand Down Expand Up @@ -428,6 +468,11 @@ function post(string $owner_id, string $message = "", int $from_group = 0, int $
$post->setContent($message);
$post->setFlags($flags);
$post->setApi_Source_Name($this->getPlatform());

if($owner_id < 0 && !$wallOwner->canBeModifiedBy($this->getUser()) && $wallOwner->getWallType() == 2) {
$post->setSuggested(1);
}

$post->save();
} catch(\LogicException $ex) {
$this->fail(100, "One of the parameters specified was missing or invalid");
Expand Down Expand Up @@ -494,6 +539,22 @@ function post(string $owner_id, string $message = "", int $from_group = 0, int $
if($wall > 0 && $wall !== $this->user->identity->getId())
(new WallPostNotification($wallOwner, $post, $this->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"];
}

return (object)["post_id" => $post->getVirtualId()];
}

Expand Down Expand Up @@ -776,6 +837,80 @@ function deleteComment(int $comment_id) {
return 1;
}

# !!! Нестандартный метод
function acceptPost(int $club, int $post_id, string $new_message = "", bool $sign = true)
{
$this->requireUser();
$this->willExecuteWriteAction();

if($club < 0) {
$this->fail(62, "Club's id is negative");
}

$post = (new PostsRepo)->getPostById($club * -1, $post_id, true);
if(!$post || $post->isDeleted())
$this->fail(32, "Invald post");

if($post->getSuggestionType() == 0)
$this->fail(20, "Post is not suggested");

if($post->getSuggestionType() == 2)
$this->fail(16, "Post is declined");

if(!$post->canBePinnedBy($this->getUser()))
$this->fail(51, "Access denied");

$author = $post->getOwner();
$flags = 0;
$flags |= 0b10000000;

if($sign)
$flags |= 0b01000000;

$post->setSuggested(0);
$post->setCreated(time());
$post->setFlags($flags);

if(!empty($new_message) && iconv_strlen($new_message) > 0)
$post->setContent($new_message);

$post->save();
(new PostAcceptedNotification($author, $post, $post->getWallOwner()))->emit();

return 1;
}

# !!! Нестандартный метод
function declinePost(int $club, int $post_id)
{
$this->requireUser();
$this->willExecuteWriteAction();

if($club < 0) {
$this->fail(62, "Club's id is negative");
}

$post = (new PostsRepo)->getPostById($club * -1, $post_id, true);

if(!$post || $post->isDeleted())
$this->fail(32, "Invald post");

if($post->getSuggestionType() == 0)
$this->fail(20, "Post is not suggested");

if($post->getSuggestionType() == 2)
$this->fail(16, "Post is already declined");

if(!$post->canBePinnedBy($this->getUser()))
$this->fail(51, "Access denied");

$post->setSuggested(2);
$post->setDeleted(1);
$post->save();

return 1;
}

private function getApiPhoto($attachment) {
return [
"type" => "photo",
Expand Down
26 changes: 25 additions & 1 deletion Web/Models/Entities/Club.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use openvk\Web\Util\DateTime;
use openvk\Web\Models\RowModel;
use openvk\Web\Models\Entities\{User, Manager};
use openvk\Web\Models\Repositories\{Users, Clubs, Albums, Managers};
use openvk\Web\Models\Repositories\{Users, Clubs, Albums, Managers, Posts};
use Nette\Database\Table\{ActiveRow, GroupedSelection};
use Chandler\Database\DatabaseConnection as DB;
use Chandler\Security\User as ChandlerUser;
Expand All @@ -23,6 +23,10 @@ class Club extends RowModel
const NOT_RELATED = 0;
const SUBSCRIBED = 1;
const REQUEST_SENT = 2;

const WALL_CLOSED = 0;
const WALL_OPEN = 1;
const WALL_LIMITED = 2;

function getId(): int
{
Expand All @@ -45,6 +49,11 @@ function getAvatarUrl(string $size = "miniscule"): string

return is_null($avPhoto) ? "$serverUrl/assets/packages/static/openvk/img/camera_200.png" : $avPhoto->getURLBySizeId($size);
}

function getWallType(): int
{
return $this->getRecord()->wall;
}

function getAvatarLink(): string
{
Expand Down Expand Up @@ -182,6 +191,14 @@ function setShortCode(?string $code = NULL): ?bool
$this->stateChanges("shortcode", $code);
return true;
}

function setWall(int $type)
{
if($type > 3 || $type < 0)
throw new \LogicException("Invalid wall");

$this->stateChanges("wall", $type);
}

function isSubscriptionAccepted(User $user): bool
{
Expand Down Expand Up @@ -291,6 +308,13 @@ function getFollowers(int $page = 1, int $perPage = 6, string $sort = "follower
yield $rel;
}
}

function getSuggestedPostsCount()
{
$count = (new Posts)->getSuggestedPostsCount($this->getId());

return $count;
}

function getManagers(int $page = 1, bool $ignoreHidden = false): \Traversable
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php declare(strict_types=1);
namespace openvk\Web\Models\Entities\Notifications;
use openvk\Web\Models\Entities\{User, Club};

final class NewSuggestedPostsNotification extends Notification
{
protected $actionCode = 7;

function __construct(User $owner, Club $group)
{
parent::__construct($owner, $owner, $group, time(), "");
}
}
Loading