openvk/ServiceAPI/Wall.php
lalka2018 4699fcbeb9
Groups: Wall: add suggestions (#935)
* Wall: add early suggestions

* Fix br

* Fix empty posts

* fck

* Add offset for api

* Add notifications of new suggestion posts

* Fix mentions in suggested posts

* 🤮🤢

* Change regex

Теперь оно удаляет все теги а не только <br>

* Add da koroche pohuy

* Эдд апи метходс

Методы нестандартные немного

* Pon

* Add skloneniyia

* newlines

* int

* Update loaders and add avtopodgruzka postov

* Update JOERGK.strings

* Blin

* Remove repeated code, fix loaded buttons on chr...

...ome and fix getting suggested posts via API.Wall.getPost

* Fix polls

* Fihes

Теперь уведомление о принятии поста не приходит, если вы приняли свой же пост

Пофикшен баг перехода в предложку

Добавлен старый вид постов в предложке

Теперь счётчик постов в предложке у прикреплённой группы обновляется при принятии или отклонении поста

Убрано всплывающее уведомление об отклонении поста (оно раздражает)

Теперь если вы посмотрели все посты на одной странице (не на первой) и на ней не осталось постов, вас телепортирует на предыдущую страницу

* Remove ability to delete your accepted psto

* oi blin

* Improvements 2 api

* g

* openvk.uk

Возможно, приведение кода к кодстайлу (удаление скобочек то есть)

* aiaks

* al_wall.js -> al_suggestions.js

* 👨‍💻 Add 👨‍💻 fading 👨‍💻

* Add "owner's posts' and "other's posts"

Давайте рофлить👨‍💻👨‍💻👨‍💻

* planshet openvk

Add tabs for post view, add signer's object in wall get and add person icon in microblog

* Simplefai ze kod

* PHP 8 FIX WATAFAK

* Add indesk
2023-11-16 19:44:12 +03:00

143 lines
4.3 KiB
PHP

<?php declare(strict_types=1);
namespace openvk\ServiceAPI;
use openvk\Web\Models\Entities\Post;
use openvk\Web\Models\Entities\User;
use openvk\Web\Models\Repositories\{Posts, Notes, Videos};
class Wall implements Handler
{
protected $user;
protected $posts;
protected $notes;
function __construct(?User $user)
{
$this->user = $user;
$this->posts = new Posts;
$this->notes = new Notes;
$this->videos = new Videos;
}
function getPost(int $id, callable $resolve, callable $reject): void
{
$post = $this->posts->get($id);
if(!$post || $post->isDeleted())
$reject(53, "No post with id=$id");
if($post->getSuggestionType() != 0)
$reject(25, "Can't get suggested post");
$res = (object) [];
$res->id = $post->getId();
$res->wall = $post->getTargetWall();
$res->author = (($owner = $post->getOwner())) instanceof User
? ($owner->getId())
: ($owner->getId() * -1);
if($post->isSigned())
$res->signedOffBy = $post->getOwnerPost();
$res->pinned = $post->isPinned();
$res->sponsored = $post->isAd();
$res->nsfw = $post->isExplicit();
$res->text = $post->getText();
$res->likes = [
"count" => $post->getLikesCount(),
"hasLike" => $post->hasLikeFrom($this->user),
"likedBy" => [],
];
foreach($post->getLikers() as $liker) {
$res->likes["likedBy"][] = [
"id" => $liker->getId(),
"url" => $liker->getURL(),
"name" => $liker->getCanonicalName(),
"avatar" => $liker->getAvatarURL(),
];
}
$res->created = (string) $post->getPublicationTime();
$res->canPin = $post->canBePinnedBy($this->user);
$res->canEdit = $res->canDelete = $post->canBeDeletedBy($this->user);
$resolve((array) $res);
}
function newStatus(string $text, callable $resolve, callable $reject): void
{
$post = new Post;
$post->setOwner($this->user->getId());
$post->setWall($this->user->getId());
$post->setCreated(time());
$post->setContent($text);
$post->setAnonymous(false);
$post->setFlags(0);
$post->setNsfw(false);
$post->save();
$resolve($post->getId());
}
function getMyNotes(callable $resolve, callable $reject)
{
$count = $this->notes->getUserNotesCount($this->user);
$myNotes = $this->notes->getUserNotes($this->user, 1, $count);
$arr = [
"count" => $count,
"closed" => $this->user->getPrivacySetting("notes.read"),
"items" => [],
];
foreach($myNotes as $note) {
$arr["items"][] = [
"id" => $note->getId(),
"name" => ovk_proc_strtr($note->getName(), 30),
#"preview" => $note->getPreview()
];
}
$resolve($arr);
}
function getVideos(int $page = 1, callable $resolve, callable $reject)
{
$videos = $this->videos->getByUser($this->user, $page, 8);
$count = $this->videos->getUserVideosCount($this->user);
$arr = [
"count" => $count,
"items" => [],
];
foreach($videos as $video) {
$res = json_decode(json_encode($video->toVkApiStruct($this->user)), true);
$res["video"]["author_name"] = $video->getOwner()->getCanonicalName();
$arr["items"][] = $res;
}
$resolve($arr);
}
function searchVideos(int $page = 1, string $query, callable $resolve, callable $reject)
{
$dbc = $this->videos->find($query);
$videos = $dbc->page($page, 8);
$count = $dbc->size();
$arr = [
"count" => $count,
"items" => [],
];
foreach($videos as $video) {
$res = json_decode(json_encode($video->toVkApiStruct($this->user)), true);
$res["video"]["author_name"] = $video->getOwner()->getCanonicalName();
$arr["items"][] = $res;
}
$resolve($arr);
}
}