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
2 changes: 1 addition & 1 deletion src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct SenderContext {
pub channel: String,
pub channel_id: String,
/// Thread identifier, if the message is inside a thread.
/// Slack: thread_ts. Discord: None (threads are separate channels).
/// Slack: thread_ts. Discord: thread channel ID (channel_id holds the parent).
#[serde(skip_serializing_if = "Option::is_none")]
pub thread_id: Option<String>,
pub is_bot: bool,
Expand Down
13 changes: 7 additions & 6 deletions src/discord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,9 @@ impl EventHandler for Handler {
// Thread detection: single to_channel() call for both allowed and
// non-allowed channels. Uses thread_metadata (not parent_id) to
// identify threads — see detect_thread() doc comments for rationale.
let (in_thread, bot_owns_thread) = match msg.channel_id.to_channel(&ctx.http).await {
let (in_thread, bot_owns_thread, thread_parent_id) = match msg.channel_id.to_channel(&ctx.http).await {
Ok(serenity::model::channel::Channel::Guild(gc)) => {
let parent = gc.parent_id.map(|id| id.get().to_string());
let result = detect_thread(
gc.thread_metadata.is_some(),
gc.parent_id.map(|id| id.get()),
Expand All @@ -404,15 +405,15 @@ impl EventHandler for Handler {
bot_owns = ?result.1,
"thread check"
);
(result.0, result.1.unwrap_or(false))
(result.0, result.1.unwrap_or(false), if result.0 { parent } else { None })
}
Ok(other) => {
tracing::debug!(channel_id = %msg.channel_id, kind = ?other, "not a guild thread");
(false, false)
(false, false, None)
}
Err(e) => {
tracing::debug!(channel_id = %msg.channel_id, error = %e, "to_channel failed");
(false, false)
(false, false, None)
}
};

Expand Down Expand Up @@ -495,8 +496,8 @@ impl EventHandler for Handler {
sender_name: msg.author.name.clone(),
display_name: display_name.to_string(),
channel: "discord".into(),
channel_id: msg.channel_id.to_string(),
thread_id: None,
channel_id: thread_parent_id.clone().unwrap_or_else(|| msg.channel_id.to_string()),
thread_id: if thread_parent_id.is_some() { Some(msg.channel_id.to_string()) } else { None },
is_bot: msg.author.bot,
};

Expand Down
Loading