Skip to content

Commit

Permalink
Update only the thread name when it has changed
Browse files Browse the repository at this point in the history
  • Loading branch information
gabber235 committed Sep 6, 2024
1 parent 9e1837b commit 1abca7b
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions discord_bot/src/webhooks/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::collections::HashMap;
use indoc::formatdoc;
use itertools::Itertools;
use poise::serenity_prelude::{
ButtonStyle, ChannelId, CreateButton, CreateMessage, EditThread, ForumTag, ForumTagId,
Mentionable, ReactionType, UserId,
futures::TryFutureExt, ButtonStyle, ChannelId, CreateButton, CreateMessage, EditThread,
ForumTag, ForumTagId, Mentionable, ReactionType, UserId,
};

use crate::{
Expand Down Expand Up @@ -87,16 +87,23 @@ async fn update_discord_channel(task_id: &str, moved: bool) -> Result<(), Winsto

let lock = status == TaskStatus::InProduction;

channel
.edit_thread(
&discord,
EditThread::default()
.name(task.name)
.applied_tags(new_tags)
.locked(lock)
.archived(lock),
)
.await?;
let mut edit_thread = EditThread::default()
.applied_tags(new_tags)
.locked(lock)
.archived(lock);

// Since discord sends a message in the thread when the name is changed, even if the name is the same.
// We only want to change the name if it is different.
if task.name
!= channel
.name(&discord)
.await
.unwrap_or_else(|_| "".to_string())
{
edit_thread = edit_thread.name(task.name);
}

channel.edit_thread(&discord, edit_thread).await?;

if !moved {
return Ok(());
Expand Down

0 comments on commit 1abca7b

Please sign in to comment.