Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions src/Parts/ForumThread.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Tempcord\Discord\Parts;

/**
* A post in a forum or media channel.
*
* A thread in every other respect, but Discord answers the call that creates
* one with the opening message attached — the only place a channel comes back
* carrying a message. That message is what reactions and edits address, so it
* is worth having a name rather than being reached for through a cast.
*
* @see https://discord.com/developers/docs/resources/channel#start-thread-in-forum-or-media-channel
*/
class ForumThread extends Channel
{
public Message $message;
}
10 changes: 4 additions & 6 deletions src/Rest/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Discord\Http\Multipart\MultipartBody;
use Tempcord\Discord\Parts\ArchivedThreads;
use Tempcord\Discord\Parts\Channel as PartsChannel;
use Tempcord\Discord\Parts\ForumThread;
use Tempcord\Discord\Parts\Invite;
use Tempcord\Discord\Parts\Message;
use Tempcord\Discord\Parts\ThreadMember;
Expand Down Expand Up @@ -699,24 +700,21 @@ public function startThreadWithoutMessage(
/**
* @see https://discord.com/developers/docs/resources/channel#start-thread-in-forum-or-media-channel
*
* @return PromiseInterface<\Tempcord\Discord\Parts\Channel> includes $message property
* @return PromiseInterface<\Tempcord\Discord\Parts\ForumThread> the post, with
* the opening message Discord answers with attached
*/
public function startThreadInForumChannel(
string $channelId,
MultipartBody|array $params,
?string $reason = null
): PromiseInterface {
$forumChannelWithMessage = new class () extends Channel {
public Message $message;
};

return $this->mapPromise(
$this->http->post(
Endpoint::bind(Endpoint::CHANNEL_THREADS, $channelId),
$params,
$this->getAuditLogReasonHeader($reason),
),
$forumChannelWithMessage::class,
ForumThread::class,
);
}

Expand Down
15 changes: 15 additions & 0 deletions tests/Rest/ChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Tests\Tempcord\Discord\Rest;

use Tempcord\Discord\Parts\ArchivedThreads;
use Tempcord\Discord\Parts\ForumThread;
use Tempcord\Discord\Parts\Channel as PartsChannel;
use Tempcord\Discord\Parts\Invite;
use Tempcord\Discord\Parts\Message;
Expand Down Expand Up @@ -204,6 +205,20 @@ public static function httpBindingsProvider(): array
'returnType' => PartsChannel::class,
]
],
'Start thread in forum channel' => [
'method' => 'startThreadInForumChannel',
'args' => ['::channel id::', ['name' => '::post::', 'message' => ['content' => '::text::']]],
'mockOptions' => [
'method' => 'post',
'return' => (object) [
'id' => '::thread id::',
'message' => (object) ['id' => '::message id::'],
],
],
'validationOptions' => [
'returnType' => ForumThread::class,
]
],
'Delete channel' => [
'method' => 'delete',
'args' => ['::channel id::'],
Expand Down