Skip to content

Commit

Permalink
Add unpinAllForumTopicMessages and `unpinAllGeneralForumTopicMessag…
Browse files Browse the repository at this point in the history
…es` methods (#66)
  • Loading branch information
vjik authored Jun 28, 2024
1 parent 26703cf commit 764ccec
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
- New #64: Add `getForumTopicIconStickers` method.
- New #65: Add `createForumTopic`, `editForumTopic`, `closeForumTopic`, `reopenForumTopic`, `deleteForumTopic` methods,
`ForumTopic` type and `ForumTopicIconColor` class with constants.
- New #66: Add `unpinAllForumTopicMessages` and `unpinAllGeneralForumTopicMessages` methods.
- Chg #24: Move update methods to `Vjik\TelegramBot\Api\Method\Update` namespace, and update types to
`Vjik\TelegramBot\Api\Type\Update` namespace.
- Chg #30: Remove `TelegramRequestWithFilesInterface`.
Expand Down
45 changes: 45 additions & 0 deletions src/Method/UnpinAllForumTopicMessages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\ParseResult\ValueHelper;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;

/**
* @see https://core.telegram.org/bots/api#unpinallforumtopicmessages
*/
final readonly class UnpinAllForumTopicMessages implements TelegramRequestWithResultPreparingInterface
{
public function __construct(
private int|string $chatId,
private int $messageThreadId,
) {
}

public function getHttpMethod(): HttpMethod
{
return HttpMethod::POST;
}

public function getApiMethod(): string
{
return 'unpinAllForumTopicMessages';
}

public function getData(): array
{
return [
'chat_id' => $this->chatId,
'message_thread_id' => $this->messageThreadId,
];
}

public function prepareResult(mixed $result): true
{
ValueHelper::assertTrueResult($result);
return $result;
}
}
43 changes: 43 additions & 0 deletions src/Method/UnpinAllGeneralForumTopicMessages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\ParseResult\ValueHelper;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;

/**
* @see https://core.telegram.org/bots/api#unpinallgeneralforumtopicmessages
*/
final readonly class UnpinAllGeneralForumTopicMessages implements TelegramRequestWithResultPreparingInterface
{
public function __construct(
private int|string $chatId,
) {
}

public function getHttpMethod(): HttpMethod
{
return HttpMethod::POST;
}

public function getApiMethod(): string
{
return 'unpinAllGeneralForumTopicMessages';
}

public function getData(): array
{
return [
'chat_id' => $this->chatId,
];
}

public function prepareResult(mixed $result): true
{
ValueHelper::assertTrueResult($result);
return $result;
}
}
26 changes: 26 additions & 0 deletions src/TelegramBotApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
use Vjik\TelegramBot\Api\Method\UnbanChatMember;
use Vjik\TelegramBot\Api\Method\UnbanChatSenderChat;
use Vjik\TelegramBot\Api\Method\UnpinAllChatMessages;
use Vjik\TelegramBot\Api\Method\UnpinAllForumTopicMessages;
use Vjik\TelegramBot\Api\Method\UnpinAllGeneralForumTopicMessages;
use Vjik\TelegramBot\Api\Method\UnpinChatMessage;
use Vjik\TelegramBot\Api\Request\TelegramRequestInterface;
use Vjik\TelegramBot\Api\Client\TelegramClientInterface;
Expand Down Expand Up @@ -1868,6 +1870,30 @@ public function unpinAllChatMessages(int|string $chatId): FailResult|true
);
}

/**
* @see https://core.telegram.org/bots/api#unpinallforumtopicmessages
*
* @psalm-suppress MixedInferredReturnType,MixedReturnStatement
*/
public function unpinAllForumTopicMessages(int|string $chatId, int $messageThreadId): FailResult|true
{
return $this->send(
new UnpinAllForumTopicMessages($chatId, $messageThreadId)
);
}

/**
* @see https://core.telegram.org/bots/api#unpinallgeneralforumtopicmessages
*
* @psalm-suppress MixedInferredReturnType,MixedReturnStatement
*/
public function unpinAllGeneralForumTopicMessages(int|string $chatId): FailResult|true
{
return $this->send(
new UnpinAllGeneralForumTopicMessages($chatId)
);
}

/**
* @see https://core.telegram.org/bots/api#uploadstickerfile
*
Expand Down
36 changes: 36 additions & 0 deletions tests/Method/UnpinAllForumTopicMessagesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Tests\Method;

use PHPUnit\Framework\TestCase;
use Vjik\TelegramBot\Api\Method\UnpinAllForumTopicMessages;
use Vjik\TelegramBot\Api\Request\HttpMethod;

final class UnpinAllForumTopicMessagesTest extends TestCase
{
public function testBase(): void
{
$method = new UnpinAllForumTopicMessages(1, 2);

$this->assertSame(HttpMethod::POST, $method->getHttpMethod());
$this->assertSame('unpinAllForumTopicMessages', $method->getApiMethod());
$this->assertSame(
[
'chat_id' => 1,
'message_thread_id' => 2,
],
$method->getData(),
);
}

public function testPrepareResult(): void
{
$method = new UnpinAllForumTopicMessages(1, 2);

$preparedResult = $method->prepareResult(true);

$this->assertTrue($preparedResult);
}
}
35 changes: 35 additions & 0 deletions tests/Method/UnpinAllGeneralForumTopicMessagesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Tests\Method;

use PHPUnit\Framework\TestCase;
use Vjik\TelegramBot\Api\Method\UnpinAllGeneralForumTopicMessages;
use Vjik\TelegramBot\Api\Request\HttpMethod;

final class UnpinAllGeneralForumTopicMessagesTest extends TestCase
{
public function testBase(): void
{
$method = new UnpinAllGeneralForumTopicMessages(1);

$this->assertSame(HttpMethod::POST, $method->getHttpMethod());
$this->assertSame('unpinAllGeneralForumTopicMessages', $method->getApiMethod());
$this->assertSame(
[
'chat_id' => 1,
],
$method->getData(),
);
}

public function testPrepareResult(): void
{
$method = new UnpinAllGeneralForumTopicMessages(1);

$preparedResult = $method->prepareResult(true);

$this->assertTrue($preparedResult);
}
}
24 changes: 24 additions & 0 deletions tests/TelegramBotApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,30 @@ public function testUnpinChatMessage(): void
$this->assertTrue($result);
}

public function testUnpinAllForumTopicMessages(): void
{
$api = $this->createApi([
'ok' => true,
'result' => true,
]);

$result = $api->unpinAllForumTopicMessages(1, 2);

$this->assertTrue($result);
}

public function testUnpinAllGeneralForumTopicMessages(): void
{
$api = $this->createApi([
'ok' => true,
'result' => true,
]);

$result = $api->unpinAllGeneralForumTopicMessages(2);

$this->assertTrue($result);
}

public function testUploadStickerFile(): void
{
$api = $this->createApi([
Expand Down

0 comments on commit 764ccec

Please sign in to comment.