BlueGit

ict rusty-teams

fix(edit): adding a channel mention to a channel post no longer fails

- channel edits with mentions go through chatsvc like Teams web, not the Graph PATCH (needs ChannelMessage.ReadWrite)
- chatsvc channel mention: mri = channel thread id, mentionType channel (shape checked on received Teams messages)
- team and tag mentions in channel edits stay on Graph

Closes #88

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-25 · 6 days ago

Hash
797e287e447aad9a1e7e2bdbd4798ed1a9ddd504
Parent
184914cb
2 files changed +27 −12
crates/core/src/remote.rs +11 −8
@@ -7,9 +7,9 @@ use chatsvc::substrate_search::{
7 7 QueryRequest, QueryResults, SearchIdentity, SearchSession, SubstrateSearch, Suggestions,
8 8 };
9 9 use chatsvc::{
10 parse_app_consumption_horizon, ActivityFeed, ActivitySnapshot, AppConsumptionHorizon,
11 ChatNotificationMode, ChatNotificationWrite, ChatSettingChange, ChatSettingsClient,
12 ChatSettingsDocument, DesktopNotifications, UserSettings,
10 ActivityFeed, ActivitySnapshot, AppConsumptionHorizon, ChatNotificationMode,
11 ChatNotificationWrite, ChatSettingChange, ChatSettingsClient, ChatSettingsDocument,
12 DesktopNotifications, UserSettings, parse_app_consumption_horizon,
13 13 };
14 14 use chatsvc::{
15 15 BotProfile, BotProfiles, CallLogEntry, CardActions, ChatApp, ConversationRef,
@@ -976,10 +976,13 @@ impl Remote for Graph {
976 976 .edit_message(&conversation, target.message_id(), &html)
977 977 .await?)
978 978 }
979 Some(conversation @ ConversationRef::Chat { .. }) => {
980 let entries = crate::teams_quote::mention_entries(mentions).ok_or(
981 Error::Unsupported("editing in a team, channel or tag mention"),
982 )?;
979 Some(conversation) => {
980 let Some(entries) = crate::teams_quote::mention_entries(mentions) else {
981 if matches!(conversation, ConversationRef::Chat { .. }) {
982 return Err(Error::Unsupported("editing in a team or tag mention"));
983 }
984 return Ok(Graph::edit_message(self, target, html, mentions, extras).await?);
985 };
983 986 let html = format!(
984 987 "{}{}{}",
985 988 extras.kept_html(),
@@ -995,7 +998,7 @@ impl Remote for Graph {
995 998 )
996 999 .await?)
997 1000 }
998 Some(_) | None => Ok(Graph::edit_message(self, target, html, mentions, extras).await?),
1001 None => Ok(Graph::edit_message(self, target, html, mentions, extras).await?),
999 1002 }
1000 1003 }
1001 1004
@@ -7,9 +7,9 @@ use chatsvc::substrate_search::{
7 QueryRequest, QueryResults, SearchIdentity, SearchSession, SubstrateSearch, Suggestions,
7 QueryRequest, QueryResults, SearchIdentity, SearchSession, SubstrateSearch, Suggestions,
8};
8};
9use chatsvc::{
9use chatsvc::{
10 parse_app_consumption_horizon, ActivityFeed, ActivitySnapshot, AppConsumptionHorizon,
10 ActivityFeed, ActivitySnapshot, AppConsumptionHorizon, ChatNotificationMode,
11 ChatNotificationMode, ChatNotificationWrite, ChatSettingChange, ChatSettingsClient,
11 ChatNotificationWrite, ChatSettingChange, ChatSettingsClient, ChatSettingsDocument,
12 ChatSettingsDocument, DesktopNotifications, UserSettings,
12 DesktopNotifications, UserSettings, parse_app_consumption_horizon,
13};
13};
14use chatsvc::{
14use chatsvc::{
15 BotProfile, BotProfiles, CallLogEntry, CardActions, ChatApp, ConversationRef,
15 BotProfile, BotProfiles, CallLogEntry, CardActions, ChatApp, ConversationRef,
@@ -976,10 +976,13 @@ impl Remote for Graph {
976 .edit_message(&conversation, target.message_id(), &html)
976 .edit_message(&conversation, target.message_id(), &html)
977 .await?)
977 .await?)
978 }
978 }
979 Some(conversation @ ConversationRef::Chat { .. }) => {
979 Some(conversation) => {
980 let entries = crate::teams_quote::mention_entries(mentions).ok_or(
980 let Some(entries) = crate::teams_quote::mention_entries(mentions) else {
981 Error::Unsupported("editing in a team, channel or tag mention"),
981 if matches!(conversation, ConversationRef::Chat { .. }) {
982 )?;
982 return Err(Error::Unsupported("editing in a team or tag mention"));
983 }
984 return Ok(Graph::edit_message(self, target, html, mentions, extras).await?);
985 };
983 let html = format!(
986 let html = format!(
984 "{}{}{}",
987 "{}{}{}",
985 extras.kept_html(),
988 extras.kept_html(),
@@ -995,7 +998,7 @@ impl Remote for Graph {
995 )
998 )
996 .await?)
999 .await?)
997 }
1000 }
998 Some(_) | None => Ok(Graph::edit_message(self, target, html, mentions, extras).await?),
1001 None => Ok(Graph::edit_message(self, target, html, mentions, extras).await?),
999 }
1002 }
1000 }
1003 }
1001
1004
crates/core/src/teams_quote.rs +16 −4
@@ -67,7 +67,7 @@ pub(crate) fn message_properties(
67 67 }))
68 68 }
69 69
70 /// The chatsvc `mentions` entries; `None` when a mention is not a person.
70 /// The chatsvc `mentions` entries; `None` for a team or tag mention (their chatsvc ids are not at hand).
71 71 pub(crate) fn mention_entries(mentions: &[OutgoingMention]) -> Option<Vec<Value>> {
72 72 mentions.iter().map(mention_entry).collect()
73 73 }
@@ -76,7 +76,8 @@ fn mention_entry(mention: &OutgoingMention) -> Option<Value> {
76 76 let (mri, mention_type) = match &mention.target {
77 77 MentionTarget::User { user_id } => (user_mri(user_id), "person"),
78 78 MentionTarget::Everyone { chat_id } => (chat_id.clone(), "everyone"),
79 _ => return None,
79 MentionTarget::Channel { channel_id } => (channel_id.clone(), "channel"),
80 MentionTarget::Team { .. } | MentionTarget::Tag { .. } => return None,
80 81 };
81 82 Some(json!({
82 83 "@type": MENTION_ITEMTYPE,
@@ -201,11 +202,22 @@ mod tests {
201 202 }
202 203
203 204 #[test]
204 fn group_mentions_have_no_chatsvc_shape() {
205 for target in [
205 fn a_channel_mention_names_the_channel_thread() {
206 let channel = mention(
207 1,
206 208 MentionTarget::Channel {
207 209 channel_id: "19:c@thread.tacv2".into(),
208 210 },
211 );
212 let entries = mention_entries(&[channel]).unwrap();
213 assert_eq!(entries[0]["mri"], "19:c@thread.tacv2");
214 assert_eq!(entries[0]["mentionType"], "channel");
215 assert_eq!(entries[0]["itemid"], "1");
216 }
217
218 #[test]
219 fn team_and_tag_mentions_have_no_chatsvc_shape() {
220 for target in [
209 221 MentionTarget::Team {
210 222 team_id: "team-1".into(),
211 223 },
@@ -67,7 +67,7 @@ pub(crate) fn message_properties(
67 }))
67 }))
68}
68}
69
69
70/// The chatsvc `mentions` entries; `None` when a mention is not a person.
70/// The chatsvc `mentions` entries; `None` for a team or tag mention (their chatsvc ids are not at hand).
71pub(crate) fn mention_entries(mentions: &[OutgoingMention]) -> Option<Vec<Value>> {
71pub(crate) fn mention_entries(mentions: &[OutgoingMention]) -> Option<Vec<Value>> {
72 mentions.iter().map(mention_entry).collect()
72 mentions.iter().map(mention_entry).collect()
73}
73}
@@ -76,7 +76,8 @@ fn mention_entry(mention: &OutgoingMention) -> Option<Value> {
76 let (mri, mention_type) = match &mention.target {
76 let (mri, mention_type) = match &mention.target {
77 MentionTarget::User { user_id } => (user_mri(user_id), "person"),
77 MentionTarget::User { user_id } => (user_mri(user_id), "person"),
78 MentionTarget::Everyone { chat_id } => (chat_id.clone(), "everyone"),
78 MentionTarget::Everyone { chat_id } => (chat_id.clone(), "everyone"),
79 _ => return None,
79 MentionTarget::Channel { channel_id } => (channel_id.clone(), "channel"),
80 MentionTarget::Team { .. } | MentionTarget::Tag { .. } => return None,
80 };
81 };
81 Some(json!({
82 Some(json!({
82 "@type": MENTION_ITEMTYPE,
83 "@type": MENTION_ITEMTYPE,
@@ -201,11 +202,22 @@ mod tests {
201 }
202 }
202
203
203 #[test]
204 #[test]
204 fn group_mentions_have_no_chatsvc_shape() {
205 fn a_channel_mention_names_the_channel_thread() {
205 for target in [
206 let channel = mention(
207 1,
206 MentionTarget::Channel {
208 MentionTarget::Channel {
207 channel_id: "19:c@thread.tacv2".into(),
209 channel_id: "19:c@thread.tacv2".into(),
208 },
210 },
211 );
212 let entries = mention_entries(&[channel]).unwrap();
213 assert_eq!(entries[0]["mri"], "19:c@thread.tacv2");
214 assert_eq!(entries[0]["mentionType"], "channel");
215 assert_eq!(entries[0]["itemid"], "1");
216 }
217
218 #[test]
219 fn team_and_tag_mentions_have_no_chatsvc_shape() {
220 for target in [
209 MentionTarget::Team {
221 MentionTarget::Team {
210 team_id: "team-1".into(),
222 team_id: "team-1".into(),
211 },
223 },