VKAPI: Fix 500 error if some peers_id is invalid

This commit is contained in:
veselcraft 2022-10-22 16:52:19 +03:00
parent ca27e0588a
commit c3610cdd4d
No known key found for this signature in database
GPG key ID: AED66BC1AC628A4E

View file

@ -247,32 +247,34 @@ final class Messages extends VKAPIRequestHandler
$user = (new USRRepo)->get((int) $peer); $user = (new USRRepo)->get((int) $peer);
$dialogue = new Correspondence($this->getUser(), $user); if($user) {
$iterator = $dialogue->getMessages(Correspondence::CAP_BEHAVIOUR_START_MESSAGE_ID, 0, 1, 0, false); $dialogue = new Correspondence($this->getUser(), $user);
$msg = $iterator[0]->unwrap(); // шоб удобнее было $iterator = $dialogue->getMessages(Correspondence::CAP_BEHAVIOUR_START_MESSAGE_ID, 0, 1, 0, false);
$output['items'][] = [ $msg = $iterator[0]->unwrap(); // шоб удобнее было
"peer" => [ $output['items'][] = [
"id" => $user->getId(), "peer" => [
"type" => "user", "id" => $user->getId(),
"local_id" => $user->getId() "type" => "user",
], "local_id" => $user->getId()
"last_message_id" => $msg->id, ],
"in_read" => $msg->id, "last_message_id" => $msg->id,
"out_read" => $msg->id, "in_read" => $msg->id,
"sort_id" => [ "out_read" => $msg->id,
"major_id" => 0, "sort_id" => [
"minor_id" => $msg->id, // КОНЕЧНО ЖЕ "major_id" => 0,
], "minor_id" => $msg->id, // КОНЕЧНО ЖЕ
"last_conversation_message_id" => $user->getId(), ],
"in_read_cmid" => $user->getId(), "last_conversation_message_id" => $user->getId(),
"out_read_cmid" => $user->getId(), "in_read_cmid" => $user->getId(),
"is_marked_unread" => $iterator[0]->isUnread(), "out_read_cmid" => $user->getId(),
"important" => false, // целестора когда релиз "is_marked_unread" => $iterator[0]->isUnread(),
"can_write" => [ "important" => false, // целестора когда релиз
"allowed" => ($user->getId() === $this->getUser()->getId() || $user->getPrivacyPermission('messages.write', $this->getUser()) === true) "can_write" => [
] "allowed" => ($user->getId() === $this->getUser()->getId() || $user->getPrivacyPermission('messages.write', $this->getUser()) === true)
]; ]
$userslist[] = $user->getId(); ];
$userslist[] = $user->getId();
}
} }
if($extended == 1) { if($extended == 1) {