fix(chats): deleted accounts show as Unknown User instead of "?"
- Graph names a deleted chat member "?", Teams shows "Unknown User" - a stored "?" title gives way to Unknown User (or the name from the history) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -2,6 +2,8 @@ use chrono::{DateTime, Utc};
2
2
use serde::Deserialize;
3
3
4
4
pub const UNKNOWN_USER_NAME: &str = "Unknown User";
5
/// Graph names a deleted account "?" in chat members.
6
const DELETED_USER_NAME: &str = "?";
5
7
6
8
#[derive(Debug, Clone, Deserialize, PartialEq)]
7
9
#[serde(rename_all = "camelCase")]
@@ -30,7 +32,7 @@ impl Member {
30
32
.into_iter()
31
33
.flatten()
32
34
.map(|name| name.trim())
33
.find(|name| !name.is_empty())
35
.find(|name| !name.is_empty() && *name != DELETED_USER_NAME)
34
36
.unwrap_or(UNKNOWN_USER_NAME)
35
37
}
36
38
}
@@ -2,6 +2,8 @@ use chrono::{DateTime, Utc};2
use serde::Deserialize;2
use serde::Deserialize;3
3
4
pub const UNKNOWN_USER_NAME: &str = "Unknown User";4
pub const UNKNOWN_USER_NAME: &str = "Unknown User";5
/// Graph names a deleted account "?" in chat members.6
const DELETED_USER_NAME: &str = "?";5
7
6
#[derive(Debug, Clone, Deserialize, PartialEq)]8
#[derive(Debug, Clone, Deserialize, PartialEq)]7
#[serde(rename_all = "camelCase")]9
#[serde(rename_all = "camelCase")]@@ -30,7 +32,7 @@ impl Member {30
.into_iter()32
.into_iter()31
.flatten()33
.flatten()32
.map(|name| name.trim())34
.map(|name| name.trim())33
.find(|name| !name.is_empty())35
.find(|name| !name.is_empty() && *name != DELETED_USER_NAME)34
.unwrap_or(UNKNOWN_USER_NAME)36
.unwrap_or(UNKNOWN_USER_NAME)35
}37
}36
}38
}@@ -1,4 +1,4 @@
1
use graph::{Chat, Message, User};
1
use graph::{Chat, Member, Message, UNKNOWN_USER_NAME, User};
2
2
use serde_json::Value;
3
3
4
4
fn fixture(name: &str) -> Value {
@@ -20,6 +20,15 @@ fn parses_user() {
20
20
assert!(user.mail.is_none());
21
21
}
22
22
23
#[test]
24
fn a_deleted_member_is_an_unknown_user() {
25
let member: Member = serde_json::from_value(serde_json::json!({
26
"id": "m1", "userId": "gone", "displayName": "?", "email": null,
27
}))
28
.unwrap();
29
assert_eq!(member.name(), UNKNOWN_USER_NAME);
30
}
31
23
32
#[test]
24
33
fn chat_titles_follow_topic_then_other_members() {
25
34
let chats: Vec<Chat> = items("chats.json");
@@ -1,4 +1,4 @@1
use graph::{Chat, Message, User};1
use graph::{Chat, Member, Message, UNKNOWN_USER_NAME, User};2
use serde_json::Value;2
use serde_json::Value;3
3
4
fn fixture(name: &str) -> Value {4
fn fixture(name: &str) -> Value {@@ -20,6 +20,15 @@ fn parses_user() {20
assert!(user.mail.is_none());20
assert!(user.mail.is_none());21
}21
}22
22
23
#[test]24
fn a_deleted_member_is_an_unknown_user() {25
let member: Member = serde_json::from_value(serde_json::json!({26
"id": "m1", "userId": "gone", "displayName": "?", "email": null,27
}))28
.unwrap();29
assert_eq!(member.name(), UNKNOWN_USER_NAME);30
}31
23
#[test]32
#[test]24
fn chat_titles_follow_topic_then_other_members() {33
fn chat_titles_follow_topic_then_other_members() {25
let chats: Vec<Chat> = items("chats.json");34
let chats: Vec<Chat> = items("chats.json");@@ -22,7 +22,7 @@ impl Store {
22
22
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11)
23
23
ON CONFLICT (id) DO UPDATE SET
24
24
kind = excluded.kind,
25
title = CASE WHEN excluded.title IN ('(only you)', 'Unknown User') AND chats.title NOT IN ('', '(only you)', 'Unknown User')
25
title = CASE WHEN excluded.title IN ('(only you)', 'Unknown User') AND chats.title NOT IN ('', '?', '(only you)', 'Unknown User')
26
26
THEN chats.title ELSE excluded.title END,
27
27
member_summary = excluded.member_summary,
28
28
last_message_at = excluded.last_message_at,
@@ -22,7 +22,7 @@ impl Store {22
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11)22
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11)23
ON CONFLICT (id) DO UPDATE SET23
ON CONFLICT (id) DO UPDATE SET24
kind = excluded.kind,24
kind = excluded.kind,25
title = CASE WHEN excluded.title IN ('(only you)', 'Unknown User') AND chats.title NOT IN ('', '(only you)', 'Unknown User')25
title = CASE WHEN excluded.title IN ('(only you)', 'Unknown User') AND chats.title NOT IN ('', '?', '(only you)', 'Unknown User')26
THEN chats.title ELSE excluded.title END,26
THEN chats.title ELSE excluded.title END,27
member_summary = excluded.member_summary,27
member_summary = excluded.member_summary,28
last_message_at = excluded.last_message_at,28
last_message_at = excluded.last_message_at,@@ -283,6 +283,13 @@ fn chat_upsert_keeps_a_real_title_over_the_only_you_fallback() {
283
283
.upsert_chats(&[chat("chat-2", "Sample Bot", Some(at(3)))])
284
284
.unwrap();
285
285
assert_eq!(store.chat("chat-2").unwrap().unwrap().title, "Sample Bot");
286
store
287
.upsert_chats(&[chat("chat-3", "?", Some(at(1)))])
288
.unwrap();
289
store
290
.upsert_chats(&[chat("chat-3", UNKNOWN_USER_NAME, Some(at(2)))])
291
.unwrap();
292
assert_eq!(store.chat("chat-3").unwrap().unwrap().title, UNKNOWN_USER_NAME);
286
293
}
287
294
288
295
#[test]
@@ -283,6 +283,13 @@ fn chat_upsert_keeps_a_real_title_over_the_only_you_fallback() {283
.upsert_chats(&[chat("chat-2", "Sample Bot", Some(at(3)))])283
.upsert_chats(&[chat("chat-2", "Sample Bot", Some(at(3)))])284
.unwrap();284
.unwrap();285
assert_eq!(store.chat("chat-2").unwrap().unwrap().title, "Sample Bot");285
assert_eq!(store.chat("chat-2").unwrap().unwrap().title, "Sample Bot");286
store287
.upsert_chats(&[chat("chat-3", "?", Some(at(1)))])288
.unwrap();289
store290
.upsert_chats(&[chat("chat-3", UNKNOWN_USER_NAME, Some(at(2)))])291
.unwrap();292
assert_eq!(store.chat("chat-3").unwrap().unwrap().title, UNKNOWN_USER_NAME);286
}293
}287
294
288
#[test]295
#[test]