-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add API for notifications * Add editing methods * Add apis for likes and polls * Add attaching polls * can_edit * Fix getting voters in anonymous posts and use c... ...anBeEditedBy instead of checking user's id
- Loading branch information
Showing
20 changed files
with
645 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php declare(strict_types=1); | ||
namespace openvk\VKAPI\Handlers; | ||
use openvk\Web\Models\Entities\Club; | ||
use openvk\Web\Models\Repositories\{Notifications as Notifs, Clubs, Users}; | ||
|
||
final class Notifications extends VKAPIRequestHandler | ||
{ | ||
function get(int $count = 10, | ||
string $from = "", | ||
int $offset = 0, | ||
string $start_from = "", | ||
string $filters = "", | ||
int $start_time = 0, | ||
int $end_time = 0, | ||
int $archived = 0) | ||
{ | ||
$this->requireUser(); | ||
|
||
$res = (object)[ | ||
"items" => [], | ||
"profiles" => [], | ||
"groups" => [], | ||
"last_viewed" => $this->getUser()->getNotificationOffset() | ||
]; | ||
|
||
if($count > 100) | ||
$this->fail(125, "Count is too big"); | ||
|
||
if(!eventdb()) | ||
$this->fail(1289, "EventDB is disabled on this instance"); | ||
|
||
$notifs = array_slice(iterator_to_array((new Notifs)->getNotificationsByUser($this->getUser(), $this->getUser()->getNotificationOffset(), (bool)$archived, 1, $offset + $count)), $offset); | ||
$tmpProfiles = []; | ||
foreach($notifs as $notif) { | ||
$sxModel = $notif->getModel(1); | ||
|
||
if(!method_exists($sxModel, "getAvatarUrl")) | ||
$sxModel = $notif->getModel(0); | ||
|
||
|
||
$tmpProfiles[] = $sxModel instanceof Club ? $sxModel->getId() * -1 : $sxModel->getId(); | ||
$res->items[] = $notif->toVkApiStruct(); | ||
} | ||
|
||
foreach(array_unique($tmpProfiles) as $id) { | ||
if($id > 0) { | ||
$sxModel = (new Users)->get($id); | ||
$result = (object)[ | ||
"uid" => $sxModel->getId(), | ||
"first_name" => $sxModel->getFirstName(), | ||
"last_name" => $sxModel->getLastName(), | ||
"photo" => $sxModel->getAvatarUrl(), | ||
"photo_medium_rec" => $sxModel->getAvatarUrl("tiny"), | ||
"screen_name" => $sxModel->getShortCode() | ||
]; | ||
|
||
$res->profiles[] = $result; | ||
} else { | ||
$sxModel = (new Clubs)->get(abs($id)); | ||
$result = $sxModel->toVkApiStruct($this->getUser()); | ||
|
||
$res->groups[] = $result; | ||
} | ||
} | ||
|
||
return $res; | ||
} | ||
|
||
function markAsViewed() | ||
{ | ||
$this->requireUser(); | ||
$this->willExecuteWriteAction(); | ||
|
||
try { | ||
$this->getUser()->updateNotificationOffset(); | ||
$this->getUser()->save(); | ||
} catch(\Throwable $e) { | ||
return 0; | ||
} | ||
|
||
return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.