« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/things')
-rw-r--r--src/data/things/Track.js43
1 files changed, 39 insertions, 4 deletions
diff --git a/src/data/things/Track.js b/src/data/things/Track.js
index 7ce55e51..ca3e82f7 100644
--- a/src/data/things/Track.js
+++ b/src/data/things/Track.js
@@ -1453,30 +1453,65 @@ export class Track extends Thing {
     return this.album.getAlbumArtPath(filename);
   }
 
-  countOwnContributionInContributionTotals(_contrib) {
+  countOwnContributionInContributionTotals(contrib) {
     if (!this.countInArtistTotals) {
       return false;
     }
 
     if (this.isSecondaryRelease) {
-      return false;
+      const correspondingContrib =
+        this.getCorrespondingMainReleaseContrib(contrib);
+
+      if (correspondingContrib) {
+        return false;
+      }
     }
 
     return true;
   }
 
-  countOwnContributionInDurationTotals(_contrib) {
+  countOwnContributionInDurationTotals(contrib) {
     if (!this.countInArtistTotals) {
       return false;
     }
 
     if (this.isSecondaryRelease) {
-      return false;
+      const correspondingContrib =
+        this.getCorrespondingMainReleaseContrib(contrib);
+
+      if (correspondingContrib) {
+        return false;
+      }
     }
 
     return true;
   }
 
+  getCorrespondingMainReleaseContrib(contrib) {
+    if (!this.isSecondaryRelease) return null;
+
+    const filterMatchingContrib = c =>
+      c.artist === contrib.artist &&
+      c.annotation === contrib.annotation;
+
+    const myList =
+      this[contrib.thingProperty]
+        .filter(filterMatchingContrib);
+
+    const mainList =
+      this.mainReleaseTrack[contrib.thingProperty]
+        .filter(filterMatchingContrib);
+
+    const index = myList.indexOf(contrib);
+
+    if (index === -1) {
+      const key = contrib.thingProperty;
+      throw new Error(`Couldn't find contribution in track's own ${key}`);
+    }
+
+    return mainList.at(index) ?? null;
+  }
+
   [inspect.custom](depth) {
     const parts = [];