Repository navigation
fix: track listened audio and send played receipts #257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
92678fd
fix: record voice playback and played receipts
jlucaso1 c91bb82
fix: retain played receipt state across identity reconciliation
jlucaso1 f16da80
test: validate played receipt routing and playback feedback
jlucaso1 492c388
fix: retain linked playback until message materialization
jlucaso1 3585b6d
fix: report short playback before user media switches
jlucaso1 9f931a0
fix: leave authorless linked group plays unclaimed
jlucaso1 9b503a3
Merge remote-tracking branch 'origin/main' into fix/audio-played-rece…
jlucaso1 52144a7
fix: preserve listened hydration and reject unproven live group plays
jlucaso1 76dc7c5
Merge remote-tracking branch 'origin/main' into fix/audio-played-rece…
jlucaso1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| //! Evidence that a sink advanced, independent of seeking or decoder completion. | ||
| use std::sync::atomic::{AtomicBool, Ordering}; | ||
|
|
||
| #[derive(Default)] | ||
| pub(crate) struct PlaybackStart { | ||
| observed: AtomicBool, | ||
| reported: AtomicBool, | ||
| } | ||
|
|
||
| impl PlaybackStart { | ||
| #[cfg(any(not(target_family = "wasm"), test))] | ||
| pub(crate) fn samples(&self, consumed: usize) { | ||
| if consumed > 0 { | ||
| self.observed.store(true, Ordering::Release); | ||
| } | ||
| } | ||
|
|
||
| #[cfg(any(target_family = "wasm", test))] | ||
| pub(crate) fn clock(&self, playing: bool, now: f64, started_at: f64) { | ||
| if playing && now > started_at { | ||
| self.observed.store(true, Ordering::Release); | ||
| } | ||
| } | ||
|
|
||
| pub(crate) fn take(&self, accepted: bool) -> bool { | ||
| accepted | ||
| && self.observed.load(Ordering::Acquire) | ||
| && !self.reported.swap(true, Ordering::AcqRel) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn native_requires_consumed_samples_and_an_accepted_stream() { | ||
| let start = PlaybackStart::default(); | ||
| assert!(!start.take(true)); // load or successful stream installation alone | ||
| start.samples(0); | ||
| assert!(!start.take(true)); // empty callback or seek to the end | ||
| start.samples(24); | ||
| assert!(!start.take(false)); // output start failed | ||
| assert!(start.take(true)); | ||
| start.samples(48); | ||
| assert!(!start.take(true)); // repeated callbacks and polling | ||
| } | ||
|
|
||
| #[test] | ||
| fn web_requires_running_clock_and_reports_short_clips_after_end() { | ||
| let start = PlaybackStart::default(); | ||
| start.clock(true, 5.0, 5.0); // suspended context, including seek offset | ||
| start.clock(false, 6.0, 5.0); // paused or failed node | ||
| assert!(!start.take(true)); | ||
| start.clock(true, 6.001, 6.0); // actual playing or natural ended callback | ||
| assert!(start.take(true)); | ||
| start.clock(true, 8.0, 7.0); // resume or seek replaces the node | ||
| assert!(!start.take(true)); | ||
| assert!(!PlaybackStart::default().take(true)); // stopped/new clip | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
crates/chat-store/migrations/2026-10-26-140000_audio_played/down.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| DROP TABLE audio_played_receipts; |
5 changes: 5 additions & 0 deletions
5
crates/chat-store/migrations/2026-10-26-140000_audio_played/up.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| CREATE TABLE audio_played_receipts ( | ||
| device_id INTEGER NOT NULL REFERENCES device(id) ON DELETE CASCADE, | ||
| message_row_id BIGINT NOT NULL REFERENCES messages(id) ON DELETE CASCADE, | ||
| PRIMARY KEY (device_id, message_row_id) | ||
| ); |
1 change: 1 addition & 0 deletions
1
crates/chat-store/migrations/2026-10-26-140001_pending_audio_plays/down.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| DROP TABLE audio_played_pending; |
9 changes: 9 additions & 0 deletions
9
crates/chat-store/migrations/2026-10-26-140001_pending_audio_plays/up.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| CREATE TABLE audio_played_pending ( | ||
| device_id INTEGER NOT NULL REFERENCES device(id) ON DELETE CASCADE, | ||
| chat_jid TEXT NOT NULL, | ||
| msg_id TEXT NOT NULL, | ||
| author_jid TEXT NOT NULL, | ||
| received_at_ms BIGINT NOT NULL, | ||
| ambiguous BOOLEAN NOT NULL DEFAULT FALSE, | ||
| PRIMARY KEY (device_id, chat_jid, msg_id, author_jid) | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.