mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
client: Store recordings that are from the server
This commit is contained in:
parent
46ff9bdad1
commit
51f2b34701
3 changed files with 34 additions and 1 deletions
|
|
@ -168,6 +168,17 @@ impl Database {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Check whether the database contains a recording.
|
||||
pub fn recording_exists(&self, id: &str) -> Result<bool> {
|
||||
let exists = recordings::table
|
||||
.filter(recordings::id.eq(id))
|
||||
.load::<RecordingRow>(&self.connection)?
|
||||
.first()
|
||||
.is_some();
|
||||
|
||||
Ok(exists)
|
||||
}
|
||||
|
||||
/// Retrieve all available information on a recording from related tables.
|
||||
fn get_recording_data(&self, row: RecordingRow) -> Result<Recording> {
|
||||
let mut performance_descriptions: Vec<Performance> = Vec::new();
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ enum Action {
|
|||
GetRecordingsForPerson(String, Sender<Result<Vec<Recording>>>),
|
||||
GetRecordingsForEnsemble(String, Sender<Result<Vec<Recording>>>),
|
||||
GetRecordingsForWork(String, Sender<Result<Vec<Recording>>>),
|
||||
RecordingExists(String, Sender<Result<bool>>),
|
||||
UpdateTracks(String, Vec<Track>, Sender<Result<()>>),
|
||||
DeleteTracks(String, Sender<Result<()>>),
|
||||
GetTracks(String, Sender<Result<Vec<Track>>>),
|
||||
|
|
@ -120,6 +121,9 @@ impl DbThread {
|
|||
GetRecordingsForWork(id, sender) => {
|
||||
sender.send(db.get_recordings_for_work(&id)).unwrap();
|
||||
}
|
||||
RecordingExists(id, sender) => {
|
||||
sender.send(db.recording_exists(&id)).unwrap();
|
||||
}
|
||||
UpdateTracks(recording_id, tracks, sender) => {
|
||||
sender
|
||||
.send(db.update_tracks(&recording_id, tracks))
|
||||
|
|
@ -300,6 +304,14 @@ impl DbThread {
|
|||
receiver.await?
|
||||
}
|
||||
|
||||
/// Check whether a recording exists within the database.
|
||||
pub async fn recording_exists(&self, id: &str) -> Result<bool> {
|
||||
let (sender, receiver) = oneshot::channel();
|
||||
self.action_sender
|
||||
.send(RecordingExists(id.to_string(), sender))?;
|
||||
receiver.await?
|
||||
}
|
||||
|
||||
/// Add or change the tracks associated with a recording. This will fail, if there are still
|
||||
/// other items referencing this recording.
|
||||
pub async fn update_tracks(&self, recording_id: &str, tracks: Vec<Track>) -> Result<()> {
|
||||
|
|
|
|||
|
|
@ -80,8 +80,18 @@ impl TracksEditor {
|
|||
let context = glib::MainContext::default();
|
||||
let this = this.clone();
|
||||
context.spawn_local(async move {
|
||||
let recording = this.recording.borrow().as_ref().unwrap().clone();
|
||||
|
||||
// Add the recording first, if it's from the server.
|
||||
|
||||
if !this.backend.db().recording_exists(&recording.id).await.unwrap() {
|
||||
this.backend.db().update_recording(recording.clone()).await.unwrap();
|
||||
}
|
||||
|
||||
// Add the actual tracks.
|
||||
|
||||
this.backend.db().update_tracks(
|
||||
&this.recording.borrow().as_ref().unwrap().id,
|
||||
&recording.id,
|
||||
this.tracks.borrow().clone(),
|
||||
).await.unwrap();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue