Skip to content

Commit e2c6a37

Browse files
authored
Merge pull request #1181 from discord-php/feat-reactions-fetch
Add reactions::fetch()
2 parents b6f155e + 1552401 commit e2c6a37

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/Discord/Parts/Channel/Reaction.php

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
use Discord\Parts\Guild\Emoji;
1717
use Discord\Parts\Guild\Guild;
1818
use Discord\Parts\Part;
19+
use Discord\Parts\Thread\Thread;
1920
use Discord\Parts\User\User;
2021
use React\Promise\ExtendedPromiseInterface;
22+
use stdClass;
2123
use Symfony\Component\OptionsResolver\OptionsResolver;
2224

2325
use function Discord\normalizePartId;
@@ -49,6 +51,7 @@ class Reaction extends Part
4951
* {@inheritDoc}
5052
*/
5153
protected $fillable = [
54+
'id', // internal
5255
'count',
5356
'me',
5457
'emoji',
@@ -80,6 +83,42 @@ public function fetch(): ExtendedPromiseInterface
8083
});
8184
}
8285

86+
/**
87+
* Sets the emoji identifier.
88+
*
89+
* @internal Used for ReactionRepository::fetch()
90+
*
91+
* @param string $value name:id or the character of standard emoji
92+
*
93+
* @return void
94+
*
95+
* @since 10.0.0
96+
*/
97+
protected function setIdAttribute(string $value): void
98+
{
99+
if (! isset($this->attributes['emoji'])) {
100+
$this->attributes['emoji'] = new stdClass;
101+
}
102+
103+
$colonDelimiter = explode(':', $value);
104+
$delimitedCount = count($colonDelimiter);
105+
$emojiId = $emojiAnimated = null;
106+
107+
if ($delimitedCount == 2) { // Custom emoji name:id
108+
[$emojiName, $emojiId] = $colonDelimiter;
109+
} elseif ($delimitedCount == 3) { // Custom animated emoji a:name:id
110+
[$emojiAnimated, $emojiName, $emojiId] = $colonDelimiter;
111+
} else { // Standard emoji (or just have abnormal colon count)
112+
$emojiName = $value;
113+
}
114+
115+
$this->attributes['emoji']->id = $emojiId;
116+
$this->attributes['emoji']->name = $emojiName;
117+
if ($emojiAnimated == 'a') {
118+
$this->attributes['emoji']->animated = true;
119+
}
120+
}
121+
83122
/**
84123
* Gets the emoji identifier.
85124
*
@@ -101,7 +140,7 @@ protected function getIdAttribute(): string
101140
*
102141
* @link https://discord.com/developers/docs/resources/channel#get-reactions
103142
*
104-
* @return ExtendedPromiseInterface<Collection|Users[]>
143+
* @return ExtendedPromiseInterface<Collection|User[]>
105144
*/
106145
public function getUsers(array $options = []): ExtendedPromiseInterface
107146
{
@@ -144,7 +183,7 @@ public function getUsers(array $options = []): ExtendedPromiseInterface
144183
*
145184
* @see Message::getUsers()
146185
*
147-
* @return ExtendedPromiseInterface<Collection|Users[]>
186+
* @return ExtendedPromiseInterface<Collection|User[]>
148187
*/
149188
public function getAllUsers(): ExtendedPromiseInterface
150189
{

src/Discord/Repository/Channel/ReactionRepository.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class ReactionRepository extends AbstractRepository
3636
* {@inheritDoc}
3737
*/
3838
protected $endpoints = [
39+
'get' => Endpoint::MESSAGE_REACTION_EMOJI,
3940
'delete' => Endpoint::MESSAGE_REACTION_EMOJI,
4041
];
4142

0 commit comments

Comments
 (0)