BlueGit

ict rusty-teams

refactor(calling): build chatsvc thread URLs in chatsvc::conversations

- new conversations::thread_url replaces two inline chatsvc URLs in meeting.rs and signaling.rs

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

metis Daniel Däschle · pushed by metis

Authored 2026-10-17 · 6 weeks ago

Hash
a3113617dc0a97d0683030f614f2d789e0da4764
Parent
68e37821
3 files changed +18 −8
crates/calling/src/meeting.rs +1 −4
@@ -97,10 +97,7 @@ pub fn live_meeting(thread_id: &str, properties: &Value, now_unix: i64) -> Optio
97 97 }
98 98
99 99 pub async fn fetch_live_meeting(session: &Session, thread_id: &str) -> Result<Option<LiveMeeting>> {
100 let url = format!(
101 "https://teams.cloud.microsoft/api/chatsvc/{CHATSVC_REGION}/v1/users/ME/conversations/{}?view=msnp24Equivalent",
102 thread_id.replace(':', "%3A").replace('@', "%40")
103 );
100 let url = chatsvc::conversations::thread_url(CHATSVC_REGION, thread_id);
104 101 let response = session.send(Request::get(url), &ic3_scope()).await?;
105 102 let now = std::time::SystemTime::now()
106 103 .duration_since(std::time::UNIX_EPOCH)
@@ -97,10 +97,7 @@ pub fn live_meeting(thread_id: &str, properties: &Value, now_unix: i64) -> Optio
97}
97}
98
98
99pub async fn fetch_live_meeting(session: &Session, thread_id: &str) -> Result<Option<LiveMeeting>> {
99pub async fn fetch_live_meeting(session: &Session, thread_id: &str) -> Result<Option<LiveMeeting>> {
100 let url = format!(
100 let url = chatsvc::conversations::thread_url(CHATSVC_REGION, thread_id);
101 "https://teams.cloud.microsoft/api/chatsvc/{CHATSVC_REGION}/v1/users/ME/conversations/{}?view=msnp24Equivalent",
102 thread_id.replace(':', "%3A").replace('@', "%40")
103 );
104 let response = session.send(Request::get(url), &ic3_scope()).await?;
101 let response = session.send(Request::get(url), &ic3_scope()).await?;
105 let now = std::time::SystemTime::now()
102 let now = std::time::SystemTime::now()
106 .duration_since(std::time::UNIX_EPOCH)
103 .duration_since(std::time::UNIX_EPOCH)
crates/calling/src/signaling.rs +1 −4
@@ -1062,10 +1062,7 @@ pub async fn find_echo_bot_thread(session: &Session, self_object_id: &str) -> Re
1062 1062 format!("19:{self_object_id}_{bot_id}@unq.gbl.spaces"),
1063 1063 format!("19:{bot_id}_{self_object_id}@unq.gbl.spaces"),
1064 1064 ] {
1065 let url = format!(
1066 "https://teams.cloud.microsoft/api/chatsvc/{CHATSVC_REGION}/v1/users/ME/conversations/{}?view=msnp24Equivalent",
1067 thread_id.replace(':', "%3A").replace('@', "%40")
1068 );
1065 let url = chatsvc::conversations::thread_url(CHATSVC_REGION, &thread_id);
1069 1066 let response = session.batch(&[Request::get(url)], &ic3_scope()).await?.remove(0);
1070 1067 if response.is_success() {
1071 1068 return Ok(Some(thread_id));
@@ -1062,10 +1062,7 @@ pub async fn find_echo_bot_thread(session: &Session, self_object_id: &str) -> Re
1062 format!("19:{self_object_id}_{bot_id}@unq.gbl.spaces"),
1062 format!("19:{self_object_id}_{bot_id}@unq.gbl.spaces"),
1063 format!("19:{bot_id}_{self_object_id}@unq.gbl.spaces"),
1063 format!("19:{bot_id}_{self_object_id}@unq.gbl.spaces"),
1064 ] {
1064 ] {
1065 let url = format!(
1065 let url = chatsvc::conversations::thread_url(CHATSVC_REGION, &thread_id);
1066 "https://teams.cloud.microsoft/api/chatsvc/{CHATSVC_REGION}/v1/users/ME/conversations/{}?view=msnp24Equivalent",
1067 thread_id.replace(':', "%3A").replace('@', "%40")
1068 );
1069 let response = session.batch(&[Request::get(url)], &ic3_scope()).await?.remove(0);
1066 let response = session.batch(&[Request::get(url)], &ic3_scope()).await?.remove(0);
1070 if response.is_success() {
1067 if response.is_success() {
1071 return Ok(Some(thread_id));
1068 return Ok(Some(thread_id));
crates/chatsvc/src/conversations.rs +16 −0
@@ -118,6 +118,14 @@ impl<T: MessageTransport> Conversations<T> {
118 118 }
119 119 }
120 120
121 /// One conversation with its thread properties, as Teams reads a meeting or 1:1 thread.
122 pub fn thread_url(region: &str, thread_id: &str) -> String {
123 format!(
124 "https://teams.cloud.microsoft/api/chatsvc/{region}/v1/users/ME/conversations/{}?view=msnp24Equivalent",
125 thread_id.replace(':', "%3A").replace('@', "%40")
126 )
127 }
128
121 129 fn backward_link(body: &Value) -> Option<String> {
122 130 body.pointer("/_metadata/backwardLink")
123 131 .and_then(Value::as_str)
@@ -208,6 +216,14 @@ mod tests {
208 216
209 217 const BASE: &str = "https://teams.cloud.microsoft/api/chatsvc/emea/v1/users/ME/conversations";
210 218
219 #[test]
220 fn thread_url_escapes_the_thread_id() {
221 assert_eq!(
222 thread_url("emea", "19:meeting_a@thread.v2"),
223 "https://teams.cloud.microsoft/api/chatsvc/emea/v1/users/ME/conversations/19%3Ameeting_a%40thread.v2?view=msnp24Equivalent"
224 );
225 }
226
211 227 #[tokio::test]
212 228 async fn mute_states_pair_every_conversation_with_its_flag() {
213 229 let transport = canned(vec![(
@@ -118,6 +118,14 @@ impl<T: MessageTransport> Conversations<T> {
118 }
118 }
119}
119}
120
120
121/// One conversation with its thread properties, as Teams reads a meeting or 1:1 thread.
122pub fn thread_url(region: &str, thread_id: &str) -> String {
123 format!(
124 "https://teams.cloud.microsoft/api/chatsvc/{region}/v1/users/ME/conversations/{}?view=msnp24Equivalent",
125 thread_id.replace(':', "%3A").replace('@', "%40")
126 )
127}
128
121fn backward_link(body: &Value) -> Option<String> {
129fn backward_link(body: &Value) -> Option<String> {
122 body.pointer("/_metadata/backwardLink")
130 body.pointer("/_metadata/backwardLink")
123 .and_then(Value::as_str)
131 .and_then(Value::as_str)
@@ -208,6 +216,14 @@ mod tests {
208
216
209 const BASE: &str = "https://teams.cloud.microsoft/api/chatsvc/emea/v1/users/ME/conversations";
217 const BASE: &str = "https://teams.cloud.microsoft/api/chatsvc/emea/v1/users/ME/conversations";
210
218
219 #[test]
220 fn thread_url_escapes_the_thread_id() {
221 assert_eq!(
222 thread_url("emea", "19:meeting_a@thread.v2"),
223 "https://teams.cloud.microsoft/api/chatsvc/emea/v1/users/ME/conversations/19%3Ameeting_a%40thread.v2?view=msnp24Equivalent"
224 );
225 }
226
211 #[tokio::test]
227 #[tokio::test]
212 async fn mute_states_pair_every_conversation_with_its_flag() {
228 async fn mute_states_pair_every_conversation_with_its_flag() {
213 let transport = canned(vec![(
229 let transport = canned(vec![(