BlueGit

ict rusty-teams

feat(chat): app added to a chat as a Teams notice line

- teamsAppInstalled events read "{initiator} added {app} to the chat." (Teams string k1bo0x6ne)
- Samples from the live account: Jira, Confluence Cloud

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

metis Daniel Däschle · pushed by metis

Authored 2026-11-08 · 3 weeks ago

Hash
d15e3cba0fb6248f421dd0c504d1841f1f2a7562
Parent
c5287e41
2 files changed +32 −0
crates/app-state/src/chat_actions.rs +2 −0
@@ -302,6 +302,7 @@ impl AppState {
302 302 HistoryShare::All => SharedHistory::All,
303 303 },
304 304 topic: None,
305 app_name: None,
305 306 };
306 307 self.store_demo_roster_line(chat_id, &event, cx);
307 308 }
@@ -371,6 +372,7 @@ impl AppState {
371 372 member_names: Vec::new(),
372 373 history: SharedHistory::None,
373 374 topic: (!topic.is_empty()).then(|| topic.clone()),
375 app_name: None,
374 376 };
375 377 self.store_demo_roster_line(chat_id, &event, cx);
376 378 return;
@@ -302,6 +302,7 @@ impl AppState {
302 HistoryShare::All => SharedHistory::All,
302 HistoryShare::All => SharedHistory::All,
303 },
303 },
304 topic: None,
304 topic: None,
305 app_name: None,
305 };
306 };
306 self.store_demo_roster_line(chat_id, &event, cx);
307 self.store_demo_roster_line(chat_id, &event, cx);
307 }
308 }
@@ -371,6 +372,7 @@ impl AppState {
371 member_names: Vec::new(),
372 member_names: Vec::new(),
372 history: SharedHistory::None,
373 history: SharedHistory::None,
373 topic: (!topic.is_empty()).then(|| topic.clone()),
374 topic: (!topic.is_empty()).then(|| topic.clone()),
375 app_name: None,
374 };
376 };
375 self.store_demo_roster_line(chat_id, &event, cx);
377 self.store_demo_roster_line(chat_id, &event, cx);
376 return;
378 return;
crates/core/src/roster_event.rs +30 −0
@@ -7,8 +7,10 @@ const MEMBERS_ADDED_TYPE: &str = "#microsoft.graph.membersAddedEventMessageDetai
7 7 const MEMBERS_DELETED_TYPE: &str = "#microsoft.graph.membersDeletedEventMessageDetail";
8 8 const MEMBERS_LEFT_TYPE: &str = "#microsoft.graph.membersLeftEventMessageDetail";
9 9 const CHAT_RENAMED_TYPE: &str = "#microsoft.graph.chatRenamedEventMessageDetail";
10 const APP_INSTALLED_TYPE: &str = "#microsoft.graph.teamsAppInstalledEventMessageDetail";
10 11 const UNRESOLVED_NAME_PREFIX: &str = "orgid:";
11 12 const DAY_SECONDS: i64 = 86_400;
13 const UNNAMED_APP: &str = "an app";
12 14
13 15 #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
14 16 pub enum RosterChange {
@@ -16,6 +18,7 @@ pub enum RosterChange {
16 18 Removed,
17 19 Left,
18 20 Renamed,
21 AppAdded,
19 22 }
20 23
21 24 #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
@@ -37,6 +40,8 @@ pub struct RosterEvent {
37 40 pub history: SharedHistory,
38 41 #[serde(default)]
39 42 pub topic: Option<String>,
43 #[serde(default)]
44 pub app_name: Option<String>,
40 45 }
41 46
42 47 #[derive(Serialize, Deserialize)]
@@ -72,6 +77,7 @@ impl RosterEvent {
72 77 MEMBERS_DELETED_TYPE if only_initiator => RosterChange::Left,
73 78 MEMBERS_DELETED_TYPE => RosterChange::Removed,
74 79 CHAT_RENAMED_TYPE => RosterChange::Renamed,
80 APP_INSTALLED_TYPE => RosterChange::AppAdded,
75 81 _ => return None,
76 82 };
77 83 let history = match change {
@@ -97,6 +103,12 @@ impl RosterEvent {
97 103 .map(str::trim)
98 104 .filter(|topic| !topic.is_empty())
99 105 .map(str::to_owned),
106 app_name: (change == RosterChange::AppAdded)
107 .then(|| detail.get("teamsAppDisplayName").and_then(Value::as_str))
108 .flatten()
109 .map(str::trim)
110 .filter(|name| !name.is_empty())
111 .map(str::to_owned),
100 112 })
101 113 }
102 114
@@ -130,6 +142,10 @@ impl RosterEvent {
130 142 None => format!("{initiator} removed the group name for this conversation."),
131 143 },
132 144 RosterChange::Removed => format!("{initiator} removed {targets} from the chat."),
145 RosterChange::AppAdded => {
146 let app = self.app_name.as_deref().unwrap_or(UNNAMED_APP);
147 format!("{initiator} added {app} to the chat.")
148 }
133 149 RosterChange::Added => match self.history {
134 150 SharedHistory::None => format!("{initiator} added {targets} to the chat."),
135 151 SharedHistory::All => {
@@ -340,4 +356,18 @@ mod tests {
340 356 .collect();
341 357 assert_eq!(ids, ["me", "ann", "bob"]);
342 358 }
359
360 #[test]
361 fn an_installed_app_reads_like_teams() {
362 let detail = json!({
363 "@odata.type": APP_INSTALLED_TYPE,
364 "teamsAppId": "app-1",
365 "teamsAppDisplayName": "Jira",
366 "initiator": {"user": {"id": "ann", "displayName": "Ann Example"}},
367 });
368 let event = RosterEvent::from_graph(&detail, created()).unwrap();
369 assert_eq!(event.change, RosterChange::AppAdded);
370 assert!(event.member_ids.is_empty());
371 assert_eq!(event.text(plain_names), "Ann Example added Jira to the chat.");
372 }
343 373 }
@@ -7,8 +7,10 @@ const MEMBERS_ADDED_TYPE: &str = "#microsoft.graph.membersAddedEventMessageDetai
7const MEMBERS_DELETED_TYPE: &str = "#microsoft.graph.membersDeletedEventMessageDetail";
7const MEMBERS_DELETED_TYPE: &str = "#microsoft.graph.membersDeletedEventMessageDetail";
8const MEMBERS_LEFT_TYPE: &str = "#microsoft.graph.membersLeftEventMessageDetail";
8const MEMBERS_LEFT_TYPE: &str = "#microsoft.graph.membersLeftEventMessageDetail";
9const CHAT_RENAMED_TYPE: &str = "#microsoft.graph.chatRenamedEventMessageDetail";
9const CHAT_RENAMED_TYPE: &str = "#microsoft.graph.chatRenamedEventMessageDetail";
10const APP_INSTALLED_TYPE: &str = "#microsoft.graph.teamsAppInstalledEventMessageDetail";
10const UNRESOLVED_NAME_PREFIX: &str = "orgid:";
11const UNRESOLVED_NAME_PREFIX: &str = "orgid:";
11const DAY_SECONDS: i64 = 86_400;
12const DAY_SECONDS: i64 = 86_400;
13const UNNAMED_APP: &str = "an app";
12
14
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
15#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
14pub enum RosterChange {
16pub enum RosterChange {
@@ -16,6 +18,7 @@ pub enum RosterChange {
16 Removed,
18 Removed,
17 Left,
19 Left,
18 Renamed,
20 Renamed,
21 AppAdded,
19}
22}
20
23
21#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
@@ -37,6 +40,8 @@ pub struct RosterEvent {
37 pub history: SharedHistory,
40 pub history: SharedHistory,
38 #[serde(default)]
41 #[serde(default)]
39 pub topic: Option<String>,
42 pub topic: Option<String>,
43 #[serde(default)]
44 pub app_name: Option<String>,
40}
45}
41
46
42#[derive(Serialize, Deserialize)]
47#[derive(Serialize, Deserialize)]
@@ -72,6 +77,7 @@ impl RosterEvent {
72 MEMBERS_DELETED_TYPE if only_initiator => RosterChange::Left,
77 MEMBERS_DELETED_TYPE if only_initiator => RosterChange::Left,
73 MEMBERS_DELETED_TYPE => RosterChange::Removed,
78 MEMBERS_DELETED_TYPE => RosterChange::Removed,
74 CHAT_RENAMED_TYPE => RosterChange::Renamed,
79 CHAT_RENAMED_TYPE => RosterChange::Renamed,
80 APP_INSTALLED_TYPE => RosterChange::AppAdded,
75 _ => return None,
81 _ => return None,
76 };
82 };
77 let history = match change {
83 let history = match change {
@@ -97,6 +103,12 @@ impl RosterEvent {
97 .map(str::trim)
103 .map(str::trim)
98 .filter(|topic| !topic.is_empty())
104 .filter(|topic| !topic.is_empty())
99 .map(str::to_owned),
105 .map(str::to_owned),
106 app_name: (change == RosterChange::AppAdded)
107 .then(|| detail.get("teamsAppDisplayName").and_then(Value::as_str))
108 .flatten()
109 .map(str::trim)
110 .filter(|name| !name.is_empty())
111 .map(str::to_owned),
100 })
112 })
101 }
113 }
102
114
@@ -130,6 +142,10 @@ impl RosterEvent {
130 None => format!("{initiator} removed the group name for this conversation."),
142 None => format!("{initiator} removed the group name for this conversation."),
131 },
143 },
132 RosterChange::Removed => format!("{initiator} removed {targets} from the chat."),
144 RosterChange::Removed => format!("{initiator} removed {targets} from the chat."),
145 RosterChange::AppAdded => {
146 let app = self.app_name.as_deref().unwrap_or(UNNAMED_APP);
147 format!("{initiator} added {app} to the chat.")
148 }
133 RosterChange::Added => match self.history {
149 RosterChange::Added => match self.history {
134 SharedHistory::None => format!("{initiator} added {targets} to the chat."),
150 SharedHistory::None => format!("{initiator} added {targets} to the chat."),
135 SharedHistory::All => {
151 SharedHistory::All => {
@@ -340,4 +356,18 @@ mod tests {
340 .collect();
356 .collect();
341 assert_eq!(ids, ["me", "ann", "bob"]);
357 assert_eq!(ids, ["me", "ann", "bob"]);
342 }
358 }
359
360 #[test]
361 fn an_installed_app_reads_like_teams() {
362 let detail = json!({
363 "@odata.type": APP_INSTALLED_TYPE,
364 "teamsAppId": "app-1",
365 "teamsAppDisplayName": "Jira",
366 "initiator": {"user": {"id": "ann", "displayName": "Ann Example"}},
367 });
368 let event = RosterEvent::from_graph(&detail, created()).unwrap();
369 assert_eq!(event.change, RosterChange::AppAdded);
370 assert!(event.member_ids.is_empty());
371 assert_eq!(event.text(plain_names), "Ann Example added Jira to the chat.");
372 }
343}
373}