fix(chat): creator not listed among the people added to a new chat
- "You added You and Nataliia" reads "You added Nataliia to the chat" like Teams Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -152,10 +152,16 @@ impl RosterEvent {
152
152
/// Teams wording; `name_of` gets each user id with the name the event carries.
153
153
pub fn text(&self, name_of: impl Fn(Option<&str>, Option<&str>) -> String) -> String {
154
154
let initiator = name_of(self.initiator_id.as_deref(), self.initiator_name.as_deref());
155
let initiator_among_others = self.change == RosterChange::Added
156
&& self.member_ids.len() > 1
157
&& self.initiator_id.is_some();
155
158
let targets: Vec<String> = self
156
159
.member_ids
157
160
.iter()
158
161
.zip(&self.member_names)
162
.filter(|(user_id, _)| {
163
!initiator_among_others || self.initiator_id.as_deref() != Some(user_id.as_str())
164
})
159
165
.map(|(user_id, name)| name_of(Some(user_id), name.as_deref()))
160
166
.collect();
161
167
let targets = join_targets(&targets);
@@ -383,6 +389,22 @@ mod tests {
383
389
);
384
390
}
385
391
392
#[test]
393
fn the_creator_of_a_chat_is_not_listed_among_the_added() {
394
let event = RosterEvent {
395
change: RosterChange::Added,
396
initiator_id: Some("me".to_owned()),
397
initiator_name: Some("Daniel".to_owned()),
398
member_ids: vec!["me".to_owned(), "nr".to_owned()],
399
member_names: vec![Some("Daniel".to_owned()), Some("Nataliia".to_owned())],
400
history: SharedHistory::None,
401
topic: None,
402
app_name: None,
403
};
404
let names = |_: Option<&str>, name: Option<&str>| name.unwrap_or_default().to_owned();
405
assert_eq!(event.text(names), "Daniel added Nataliia to the chat.");
406
}
407
386
408
#[test]
387
409
fn self_removal_is_leaving() {
388
410
let detail = json!({
@@ -152,10 +152,16 @@ impl RosterEvent {152
/// Teams wording; `name_of` gets each user id with the name the event carries.152
/// Teams wording; `name_of` gets each user id with the name the event carries.153
pub fn text(&self, name_of: impl Fn(Option<&str>, Option<&str>) -> String) -> String {153
pub fn text(&self, name_of: impl Fn(Option<&str>, Option<&str>) -> String) -> String {154
let initiator = name_of(self.initiator_id.as_deref(), self.initiator_name.as_deref());154
let initiator = name_of(self.initiator_id.as_deref(), self.initiator_name.as_deref());155
let initiator_among_others = self.change == RosterChange::Added156
&& self.member_ids.len() > 1157
&& self.initiator_id.is_some();155
let targets: Vec<String> = self158
let targets: Vec<String> = self156
.member_ids159
.member_ids157
.iter()160
.iter()158
.zip(&self.member_names)161
.zip(&self.member_names)162
.filter(|(user_id, _)| {163
!initiator_among_others || self.initiator_id.as_deref() != Some(user_id.as_str())164
})159
.map(|(user_id, name)| name_of(Some(user_id), name.as_deref()))165
.map(|(user_id, name)| name_of(Some(user_id), name.as_deref()))160
.collect();166
.collect();161
let targets = join_targets(&targets);167
let targets = join_targets(&targets);@@ -383,6 +389,22 @@ mod tests {383
);389
);384
}390
}385
391
392
#[test]393
fn the_creator_of_a_chat_is_not_listed_among_the_added() {394
let event = RosterEvent {395
change: RosterChange::Added,396
initiator_id: Some("me".to_owned()),397
initiator_name: Some("Daniel".to_owned()),398
member_ids: vec!["me".to_owned(), "nr".to_owned()],399
member_names: vec![Some("Daniel".to_owned()), Some("Nataliia".to_owned())],400
history: SharedHistory::None,401
topic: None,402
app_name: None,403
};404
let names = |_: Option<&str>, name: Option<&str>| name.unwrap_or_default().to_owned();405
assert_eq!(event.text(names), "Daniel added Nataliia to the chat.");406
}407
386
#[test]408
#[test]387
fn self_removal_is_leaving() {409
fn self_removal_is_leaving() {388
let detail = json!({410
let detail = json!({