Compare commits
2 Commits
5abac79414
...
17d94e59f1
Author | SHA1 | Date | |
---|---|---|---|
17d94e59f1 | |||
dd9141352c |
@ -48,8 +48,12 @@ pub enum MbRefOption<T> {
|
|||||||
impl<T> MbRefOption<T> {
|
impl<T> MbRefOption<T> {
|
||||||
pub fn or(self, optb: MbRefOption<T>) -> MbRefOption<T> {
|
pub fn or(self, optb: MbRefOption<T>) -> MbRefOption<T> {
|
||||||
match self {
|
match self {
|
||||||
x @ MbRefOption::Some(_) => x,
|
opta @ MbRefOption::Some(_) => opta,
|
||||||
MbRefOption::CannotHaveMbid | MbRefOption::None => optb,
|
opta @ MbRefOption::CannotHaveMbid => match optb {
|
||||||
|
MbRefOption::Some(_) => optb,
|
||||||
|
MbRefOption::CannotHaveMbid | MbRefOption::None => opta,
|
||||||
|
},
|
||||||
|
MbRefOption::None => optb,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,8 +395,10 @@ mod tests {
|
|||||||
match matches_info {
|
match matches_info {
|
||||||
EntityMatches::Album(_) => {
|
EntityMatches::Album(_) => {
|
||||||
let album_id = AlbumId::new("Album");
|
let album_id = AlbumId::new("Album");
|
||||||
let mut info = album_meta(album_id.clone()).info;
|
let info = AlbumInfo {
|
||||||
info.musicbrainz = MbRefOption::CannotHaveMbid;
|
musicbrainz: MbRefOption::CannotHaveMbid,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
music_hoard
|
music_hoard
|
||||||
.expect_merge_album_info()
|
.expect_merge_album_info()
|
||||||
.with(eq(artist_id.clone()), eq(album_id.clone()), eq(info))
|
.with(eq(artist_id.clone()), eq(album_id.clone()), eq(info))
|
||||||
@ -404,8 +406,10 @@ mod tests {
|
|||||||
.return_once(|_, _, _| Ok(()));
|
.return_once(|_, _, _| Ok(()));
|
||||||
}
|
}
|
||||||
EntityMatches::Artist(_) => {
|
EntityMatches::Artist(_) => {
|
||||||
let mut info = artist_meta().info;
|
let info = ArtistInfo {
|
||||||
info.musicbrainz = MbRefOption::CannotHaveMbid;
|
musicbrainz: MbRefOption::CannotHaveMbid,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
music_hoard
|
music_hoard
|
||||||
.expect_merge_artist_info()
|
.expect_merge_artist_info()
|
||||||
.with(eq(artist_id.clone()), eq(info))
|
.with(eq(artist_id.clone()), eq(info))
|
||||||
|
39
src/tui/lib/external/musicbrainz/daemon/mod.rs
vendored
39
src/tui/lib/external/musicbrainz/daemon/mod.rs
vendored
@ -252,10 +252,6 @@ impl JobInstance {
|
|||||||
api_params: &MbParams,
|
api_params: &MbParams,
|
||||||
paging: &mut Option<PageSettings>,
|
paging: &mut Option<PageSettings>,
|
||||||
) -> Result<(), JobInstanceError> {
|
) -> Result<(), JobInstanceError> {
|
||||||
if paging.is_none() {
|
|
||||||
*paging = Some(PageSettings::with_max_limit());
|
|
||||||
}
|
|
||||||
|
|
||||||
let result = match api_params {
|
let result = match api_params {
|
||||||
MbParams::Lookup(lookup) => match lookup {
|
MbParams::Lookup(lookup) => match lookup {
|
||||||
LookupParams::Artist(p) => musicbrainz
|
LookupParams::Artist(p) => musicbrainz
|
||||||
@ -280,15 +276,24 @@ impl JobInstance {
|
|||||||
}
|
}
|
||||||
.map(MbReturn::Match),
|
.map(MbReturn::Match),
|
||||||
MbParams::Browse(browse) => match browse {
|
MbParams::Browse(browse) => match browse {
|
||||||
BrowseParams::ReleaseGroup(params) => musicbrainz
|
BrowseParams::ReleaseGroup(params) => {
|
||||||
.browse_release_group(¶ms.artist, paging)
|
Self::init_paging_if_none(paging);
|
||||||
.map(|rv| EntityList::Album(rv.into_iter().map(|rg| rg.entity).collect())),
|
musicbrainz
|
||||||
|
.browse_release_group(¶ms.artist, paging)
|
||||||
|
.map(|rv| EntityList::Album(rv.into_iter().map(|rg| rg.entity).collect()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.map(MbReturn::Fetch),
|
.map(MbReturn::Fetch),
|
||||||
};
|
};
|
||||||
Self::return_result(result_sender, event_sender, result)
|
Self::return_result(result_sender, event_sender, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn init_paging_if_none(paging: &mut Option<PageSettings>) {
|
||||||
|
if paging.is_none() {
|
||||||
|
*paging = Some(PageSettings::with_max_limit());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn return_result(
|
fn return_result(
|
||||||
result_sender: &mut ResultSender,
|
result_sender: &mut ResultSender,
|
||||||
event_sender: &mut dyn IFetchCompleteEventSender,
|
event_sender: &mut dyn IFetchCompleteEventSender,
|
||||||
@ -757,24 +762,12 @@ mod tests {
|
|||||||
let artist_id = album_artist_id();
|
let artist_id = album_artist_id();
|
||||||
|
|
||||||
let result = result_receiver.try_recv().unwrap();
|
let result = result_receiver.try_recv().unwrap();
|
||||||
assert_eq!(
|
let matches = EntityMatches::album_search(artist_id.clone(), album_1.id, matches_1);
|
||||||
result,
|
assert_eq!(result, Ok(MbReturn::Match(matches)));
|
||||||
Ok(MbReturn::Match(EntityMatches::album_search(
|
|
||||||
artist_id.clone(),
|
|
||||||
album_1.id,
|
|
||||||
matches_1
|
|
||||||
)))
|
|
||||||
);
|
|
||||||
|
|
||||||
let result = result_receiver.try_recv().unwrap();
|
let result = result_receiver.try_recv().unwrap();
|
||||||
assert_eq!(
|
let matches = EntityMatches::album_search(artist_id.clone(), album_4.id, matches_4);
|
||||||
result,
|
assert_eq!(result, Ok(MbReturn::Match(matches)));
|
||||||
Ok(MbReturn::Match(EntityMatches::album_search(
|
|
||||||
artist_id.clone(),
|
|
||||||
album_4.id,
|
|
||||||
matches_4
|
|
||||||
)))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user