Skip to content

Commit aadc2da

Browse files
committed
feat(plan-59 Phase 5a): CMC chat-stream awareness on Contact
- initStreamCache: also seed accessibleStreamIds with each CMC relationship's localChatStreamId + remoteChatStreamId so doctor-side chat events fetched via back-channel pass eventIsAccessible. - chatEventInfos: recognize CMC chat streams. Events on the patient's outgoing stream resolve to source='me'; events on the doctor's chat stream (read via back-channel) resolve to source='contact'. - Legacy fallback path preserved for collectorClients-backed chat (deleted in Phase 10). Closes the chat-display gap for hds-webapp's polling fetchCmcIncomingChat. 513/513 tests pass.
1 parent 6f5d569 commit aadc2da

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

ts/appTemplates/Contact.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,17 @@ export class Contact {
230230
ids.forEach((id: string) => this.#accessibleStreamIds!.add(id));
231231
}
232232
}
233+
// Plan 59 Phase 5a — also accept chat-stream ids from CMC relationships
234+
// (both the local outgoing stream on the patient's account and the
235+
// remote incoming stream on the doctor's account). Without this, doctor-
236+
// side chat events fetched via back-channel wouldn't pass
237+
// eventIsAccessible because they're not under any access permission
238+
// entry on the patient's side. Bare add — both streams have at most
239+
// one event each per chat message so no children to expand.
240+
for (const rel of this.cmcRelationships) {
241+
if (rel.localChatStreamId) this.#accessibleStreamIds.add(rel.localChatStreamId);
242+
if (rel.remoteChatStreamId) this.#accessibleStreamIds.add(rel.remoteChatStreamId);
243+
}
233244
}
234245

235246
/**
@@ -291,6 +302,24 @@ export class Contact {
291302

292303
/** Determine chat event source: 'me', 'contact', or 'unknown' */
293304
chatEventInfos (event: pryv.Event): { source: 'me' | 'contact' | 'unknown' } {
305+
// Plan 59 Phase 5a — CMC chat-stream identification. The patient's
306+
// outgoing chat lives on `<patientScope>:chats:<doctorSlug>`; the
307+
// doctor's outgoing chat (incoming for the patient) lives on
308+
// `<doctorScope>:chats:<patientSlug>` and is fetched via back-channel.
309+
if (event.streamIds) {
310+
for (const rel of this.cmcRelationships) {
311+
if (!rel.features.chat) continue;
312+
for (const sid of event.streamIds) {
313+
if (rel.localChatStreamId && sid === rel.localChatStreamId) {
314+
return { source: 'me' };
315+
}
316+
if (rel.remoteChatStreamId && sid === rel.remoteChatStreamId) {
317+
return { source: 'contact' };
318+
}
319+
}
320+
}
321+
}
322+
// Legacy fallback
294323
for (const cc of this.collectorClients) {
295324
if (!cc.hasChatFeature) continue;
296325
const infos = cc.chatEventInfos(event);

0 commit comments

Comments
 (0)