Skip to content

Commit 7cf9921

Browse files
authored
Handle SEND_MESSAGES_IN_THREADS in Message::author_permissions (#3039)
See doc comment.
1 parent 9549110 commit 7cf9921

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/model/channel/message.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ impl Message {
218218

219219
/// Calculates the permissions of the message author in the current channel.
220220
///
221+
/// This handles the [`Permissions::SEND_MESSAGES_IN_THREADS`] permission for threads, setting
222+
/// [`Permissions::SEND_MESSAGES`] accordingly if this message was sent in a thread.
223+
///
221224
/// This may return `None` if:
222225
/// - The [`Cache`] does not have the current [`Guild`]
223226
/// - The [`Guild`] does not have the current channel cached (should never happen).
@@ -230,19 +233,25 @@ impl Message {
230233
};
231234

232235
let guild = cache.as_ref().guild(guild_id)?;
233-
let channel = if let Some(channel) = guild.channels.get(&self.channel_id) {
234-
channel
236+
let (channel, is_thread) = if let Some(channel) = guild.channels.get(&self.channel_id) {
237+
(channel, false)
235238
} else if let Some(thread) = guild.threads.iter().find(|th| th.id == self.channel_id) {
236-
thread
239+
(thread, true)
237240
} else {
238241
return None;
239242
};
240243

241-
if let Some(member) = &self.member {
242-
Some(guild.partial_member_permissions_in(channel, self.author.id, member))
244+
let mut permissions = if let Some(member) = &self.member {
245+
guild.partial_member_permissions_in(channel, self.author.id, member)
243246
} else {
244-
Some(guild.user_permissions_in(channel, guild.members.get(&self.author.id)?))
247+
guild.user_permissions_in(channel, guild.members.get(&self.author.id)?)
248+
};
249+
250+
if is_thread {
251+
permissions.set(Permissions::SEND_MESSAGES, permissions.send_messages_in_threads());
245252
}
253+
254+
Some(permissions)
246255
}
247256

248257
/// Deletes the message.

0 commit comments

Comments
 (0)