Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
314 changes: 62 additions & 252 deletions .github/workspace-dep-closures.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/call/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ entity_access_db_utils = { path = "../entity_access_db_utils", optional = true }
filter_ast = { path = "../filter_ast" }
futures = { workspace = true, optional = true }
item_filters = { path = "../item_filters" }
models_soup = { path = "../models_soup" }
invite_email = { path = "../invite_email" }
livekit-api = { workspace = true, optional = true }
livekit-protocol = { workspace = true, optional = true }
Expand Down
2 changes: 2 additions & 0 deletions crates/call/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ pub mod inbound;
/// Outbound layer: LiveKit RTC client adapter.
#[cfg(feature = "outbound")]
pub mod outbound;
/// Conversion into the Soup wire model.
pub mod soup;
60 changes: 60 additions & 0 deletions crates/call/src/soup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//! Conversion from call records into their Soup wire shape.

use crate::domain::models::{CallRecord, CallRecordParticipant};
use item_filters::CallStatus;
use models_soup::call_record::{SoupCallRecord, SoupCallRecordGuest, SoupCallRecordParticipant};

#[cfg(test)]
mod test;

/// Build a [`SoupCallRecord`] from a domain [`CallRecord`] in the context of
/// a specific viewer.
pub fn soup_call_record_for_user(record: CallRecord, user_id: &str) -> SoupCallRecord {
let status = record
.status
.unwrap_or_else(|| participant_derived_status(&record.participants, user_id));
let attended = status == CallStatus::Attended;

SoupCallRecord {
call_id: record.call_id,
channel_id: record.channel_id,
created_by: record.created_by,
started_at: record.started_at,
ended_at: record.ended_at,
duration_ms: record.duration_ms,
channel_name: record.channel_name,
custom_name: record.custom_name,
summary: record.summary,
is_active: record.is_active,
status,
attended,
participants: record
.participants
.into_iter()
.map(|p| SoupCallRecordParticipant {
user_id: p.user_id,
joined_at: p.joined_at,
left_at: p.left_at,
})
.collect(),
guests: record
.guests
.into_iter()
.map(|g| SoupCallRecordGuest {
id: g.id.as_uuid(),
display_name: g.display_name,
joined_at: g.joined_at,
left_at: g.left_at,
})
.collect(),
extra: (),
}
}

fn participant_derived_status(participants: &[CallRecordParticipant], user_id: &str) -> CallStatus {
if participants.iter().any(|p| p.user_id == user_id) {
return CallStatus::Attended;
}

CallStatus::Unattended
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
use super::*;
use crate::item::SoupItem;
use call::domain::models::{CallRecord, CallRecordParticipant};
use chrono::{DateTime, Duration, Utc};
use item_filters::CallStatus;
use models_pagination::{SimpleSortMethod, SortOn};
use models_soup::item::SoupItem;
use uuid::Uuid;

fn record_with_participants(user_ids: &[&str]) -> CallRecord {
let now = Utc::now();
CallRecord {
discussion: call::domain::models::CallDiscussion::CallChat {
discussion: crate::domain::models::CallDiscussion::CallChat {
call_id: uuid::Uuid::nil(),
},
call_id: Uuid::now_v7(),
channel_id: Some(Uuid::now_v7()),
room_name: Some("room".to_string()),
created_by: "macro|creator@test.com".to_string(),
created_by: "macro|creator@example.com".to_string(),
started_at: now,
ended_at: None,
duration_ms: None,
Expand Down Expand Up @@ -69,52 +68,46 @@ fn assert_call_recency(item: &SoupItem, expected: DateTime<Utc>) {

#[test]
fn active_call_recency_uses_started_at() {
let record = record_with_participants(&["macro|a@test.com"]);
let record = record_with_participants(&["macro|a@example.com"]);
let started_at = record.started_at;
let item = SoupItem::Call(SoupCallRecord::from_record_for_user(
record,
"macro|a@test.com",
));
let item = SoupItem::Call(soup_call_record_for_user(record, "macro|a@example.com"));

assert_call_recency(&item, started_at);
}

#[test]
fn finished_call_recency_uses_ended_at() {
let mut record = record_with_participants(&["macro|a@test.com"]);
let mut record = record_with_participants(&["macro|a@example.com"]);
let ended_at = record.started_at + Duration::minutes(30);
record.ended_at = Some(ended_at);
record.is_active = false;
let item = SoupItem::Call(SoupCallRecord::from_record_for_user(
record,
"macro|a@test.com",
));
let item = SoupItem::Call(soup_call_record_for_user(record, "macro|a@example.com"));

assert_call_recency(&item, ended_at);
}

#[test]
fn call_record_status_uses_record_status_when_present() {
let record = record_with_status(CallStatus::Missed, &["macro|a@test.com"]);
let soup = SoupCallRecord::from_record_for_user(record, "macro|a@test.com");
let record = record_with_status(CallStatus::Missed, &["macro|a@example.com"]);
let soup = soup_call_record_for_user(record, "macro|a@example.com");

assert_eq!(soup.status, CallStatus::Missed);
assert!(!soup.attended);
}

#[test]
fn call_record_status_attended_true_only_for_attended() {
let attended = SoupCallRecord::from_record_for_user(
let attended = soup_call_record_for_user(
record_with_status(CallStatus::Attended, &[]),
"macro|a@test.com",
"macro|a@example.com",
);
let missed = SoupCallRecord::from_record_for_user(
record_with_status(CallStatus::Missed, &["macro|a@test.com"]),
"macro|a@test.com",
let missed = soup_call_record_for_user(
record_with_status(CallStatus::Missed, &["macro|a@example.com"]),
"macro|a@example.com",
);
let unattended = SoupCallRecord::from_record_for_user(
record_with_status(CallStatus::Unattended, &["macro|a@test.com"]),
"macro|a@test.com",
let unattended = soup_call_record_for_user(
record_with_status(CallStatus::Unattended, &["macro|a@example.com"]),
"macro|a@example.com",
);

assert!(attended.attended);
Expand All @@ -124,73 +117,73 @@ fn call_record_status_attended_true_only_for_attended() {

#[test]
fn call_record_status_falls_back_to_participant_attended_when_status_absent() {
let record = record_with_participants(&["macro|a@test.com", "macro|b@test.com"]);
let soup = SoupCallRecord::from_record_for_user(record, "macro|a@test.com");
let record = record_with_participants(&["macro|a@example.com", "macro|b@example.com"]);
let soup = soup_call_record_for_user(record, "macro|a@example.com");

assert_eq!(soup.status, CallStatus::Attended);
assert!(soup.attended);
}

#[test]
fn call_record_status_falls_back_to_unattended_when_status_absent() {
let record = record_with_participants(&["macro|a@test.com", "macro|b@test.com"]);
let soup = SoupCallRecord::from_record_for_user(record, "macro|c@test.com");
let record = record_with_participants(&["macro|a@example.com", "macro|b@example.com"]);
let soup = soup_call_record_for_user(record, "macro|c@example.com");

assert_eq!(soup.status, CallStatus::Unattended);
assert!(!soup.attended);
}

#[test]
fn from_record_for_user_sets_attended_true_when_user_is_participant() {
let record = record_with_participants(&["macro|a@test.com", "macro|b@test.com"]);
let soup = SoupCallRecord::from_record_for_user(record, "macro|a@test.com");
fn soup_call_record_for_user_sets_attended_true_when_user_is_participant() {
let record = record_with_participants(&["macro|a@example.com", "macro|b@example.com"]);
let soup = soup_call_record_for_user(record, "macro|a@example.com");
assert!(soup.attended);
assert_eq!(soup.participants.len(), 2);
}

#[test]
fn from_record_for_user_sets_attended_false_when_user_not_participant() {
let record = record_with_participants(&["macro|a@test.com", "macro|b@test.com"]);
let soup = SoupCallRecord::from_record_for_user(record, "macro|c@test.com");
fn soup_call_record_for_user_sets_attended_false_when_user_not_participant() {
let record = record_with_participants(&["macro|a@example.com", "macro|b@example.com"]);
let soup = soup_call_record_for_user(record, "macro|c@example.com");
assert!(!soup.attended);
assert_eq!(soup.participants.len(), 2);
}

#[test]
fn from_record_for_user_attended_false_when_no_participants() {
fn soup_call_record_for_user_attended_false_when_no_participants() {
let record = record_with_participants(&[]);
let soup = SoupCallRecord::from_record_for_user(record, "macro|a@test.com");
let soup = soup_call_record_for_user(record, "macro|a@example.com");
assert!(!soup.attended);
assert!(soup.participants.is_empty());
}

#[test]
fn from_record_for_user_passes_summary_through() {
let mut record = record_with_participants(&["macro|a@test.com"]);
fn soup_call_record_for_user_passes_summary_through() {
let mut record = record_with_participants(&["macro|a@example.com"]);
record.summary = Some("AI summary".to_string());
let soup = SoupCallRecord::from_record_for_user(record, "macro|a@test.com");
let soup = soup_call_record_for_user(record, "macro|a@example.com");
assert_eq!(soup.summary.as_deref(), Some("AI summary"));
}

#[test]
fn from_record_for_user_summary_none_when_record_has_none() {
let record = record_with_participants(&["macro|a@test.com"]);
let soup = SoupCallRecord::from_record_for_user(record, "macro|a@test.com");
fn soup_call_record_for_user_summary_none_when_record_has_none() {
let record = record_with_participants(&["macro|a@example.com"]);
let soup = soup_call_record_for_user(record, "macro|a@example.com");
assert!(soup.summary.is_none());
}

#[test]
fn standalone_call_retains_guest_name_and_has_no_channel() {
let mut record = record_with_participants(&[]);
record.channel_id = None;
let guest_id = call::domain::meetings::GuestId::generate();
record.guests = vec![call::domain::models::CallRecordGuest {
let guest_id = crate::domain::meetings::GuestId::generate();
record.guests = vec![crate::domain::models::CallRecordGuest {
id: guest_id,
display_name: "Alex".to_string(),
joined_at: Utc::now(),
left_at: None,
}];
let soup = SoupCallRecord::from_record_for_user(record, "macro|owner@example.com");
let soup = soup_call_record_for_user(record, "macro|owner@example.com");
assert_eq!(soup.channel_id, None);
assert!(soup.participants.is_empty());
assert_eq!(soup.guests[0].id, guest_id.as_uuid());
Expand Down
2 changes: 2 additions & 0 deletions crates/channels/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ kafka_consumer = [
]
list = [
"dep:filter_ast",
"dep:models_soup",
"dep:frecency",
"dep:model-entity",
"dep:recursion",
Expand Down Expand Up @@ -132,6 +133,7 @@ model_notifications = { path = "../model_notifications", optional = true }
model_owner = { path = "../model_owner" }
models_pagination = { path = "../models_pagination" }
models_permissions = { path = "../models_permissions", optional = true }
models_soup = { path = "../models_soup", optional = true }
non_empty = { path = "../non_empty", optional = true }
notification_hex = { path = "../notification", package = "notification", optional = true }
rdkafka = { workspace = true, optional = true }
Expand Down
3 changes: 3 additions & 0 deletions crates/channels/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ pub mod inbound;
/// Outbound layer: postgres repository.
#[cfg(feature = "outbound")]
pub mod outbound;
/// Conversions into the Soup wire models.
#[cfg(feature = "list")]
pub mod soup;
Loading
Loading