~phw/discourse-listenbrainz

7f95710a67c968d98b383f528028f21313ac1fba — Philipp Wolfer 4 months ago 204a4dd
Link artist and releases to ListenBrainz pages

Fixes #8
M assets/javascripts/discourse/components/listenbrainz-listening.js => assets/javascripts/discourse/components/listenbrainz-listening.js +3 -3
@@ 1,7 1,7 @@
import Component from '@glimmer/component'
import { tracked } from '@glimmer/tracking'
import { ajax } from 'discourse/lib/ajax'
import { buildMbUrl } from '../lib/listenbrainz-utils'
import { buildMbidUrl } from '../lib/listenbrainz-utils'

// 280 characters is the maximum length of the blurb allowed by ListenBrainz UI.
// But it might be longer if created by API.


@@ 96,11 96,11 @@ export default class ListeningComponent extends Component {
    }

    get recordingUrl() {
        return buildMbUrl('recording', this.recordingMbid)
        return buildMbidUrl('recording', this.recordingMbid)
    }

    get releaseUrl() {
        return buildMbUrl('release', this.releaseMbid)
        return buildMbidUrl('release', this.releaseMbid)
    }

    get playUrl() {

M assets/javascripts/discourse/components/listenbrainz-profile.js => assets/javascripts/discourse/components/listenbrainz-profile.js +2 -2
@@ 4,7 4,7 @@ import { htmlSafe } from "@ember/template"
import { ajax } from 'discourse/lib/ajax'
import I18n from 'I18n'
import { escapeExpression } from 'discourse/lib/utilities'
import { buildMbUrl } from '../lib/listenbrainz-utils'
import { buildMbidUrl } from '../lib/listenbrainz-utils'

export default class ProfileComponent extends Component {



@@ 63,7 63,7 @@ export default class ProfileComponent extends Component {
function wrapMbidLink(name, entity, mbid) {
    let html = escapeExpression(name)
    if (html && mbid) {
        const url = buildMbUrl(entity, mbid)
        const url = buildMbidUrl(entity, mbid)
        html = `<a href="${escapeExpression(url)}" target="_blank">${html}</a>`
    }
    return html

M assets/javascripts/discourse/lib/listenbrainz-utils.js => assets/javascripts/discourse/lib/listenbrainz-utils.js +6 -2
@@ 1,5 1,9 @@
export function buildMbUrl(entity, mbid) {
export function buildMbidUrl(entity, mbid) {
    if (mbid) {
        return `https://musicbrainz.org/${encodeURIComponent(entity)}/${encodeURIComponent(mbid)}`
        var hostname = 'musicbrainz.org'
        if (entity == 'album' || entity == 'release' || entity == 'artist') {
            hostname = 'listenbrainz.org'
        }
        return `https://${hostname}/${encodeURIComponent(entity)}/${encodeURIComponent(mbid)}`
    }
}

M assets/javascripts/discourse/templates/components/listenbrainz-artist-credits.hbs => assets/javascripts/discourse/templates/components/listenbrainz-artist-credits.hbs +1 -1
@@ 1,6 1,6 @@
{{#each @artists as |c|~}}
    {{#if c.artist_mbid~}}
        <a href="https://musicbrainz.org/artist/{{c.artist_mbid}}"
        <a href="https://listenbrainz.org/artist/{{c.artist_mbid}}"
            target="_blank">{{c.artist_credit_name}}</a>
    {{~else~}}
        {{c.artist_credit_name}}

M test/javascripts/acceptance/listenbrainz-listening-card-test.js => test/javascripts/acceptance/listenbrainz-listening-card-test.js +3 -3
@@ 85,10 85,10 @@ acceptance('ListenBrainz - User Summary - Listen Card', needs => {
            }),
            [{
                name: 'Airghoul',
                href: 'https://musicbrainz.org/artist/554a5819-6c3f-4734-ae4c-11eabb7ca2e0'
                href: 'https://listenbrainz.org/artist/554a5819-6c3f-4734-ae4c-11eabb7ca2e0'
            }, {
                name: 'Priest',
                href: 'https://musicbrainz.org/artist/56ff293f-ec9a-4741-9d14-0537c4fb8f97'
                href: 'https://listenbrainz.org/artist/56ff293f-ec9a-4741-9d14-0537c4fb8f97'
            }],
            'it links each artist'
        )


@@ 99,7 99,7 @@ acceptance('ListenBrainz - User Summary - Listen Card', needs => {
        )
        assert.equal(
            query('.listenbrainz-card-thumbnail a').href,
            'https://musicbrainz.org/release/fb7d69d6-0b4b-4f99-a77a-c3a0d786b52c',
            'https://listenbrainz.org/release/fb7d69d6-0b4b-4f99-a77a-c3a0d786b52c',
            'it links the coverart to MB release page'
        )
        assert.equal(

M test/javascripts/acceptance/listenbrainz-profile-card-test.js => test/javascripts/acceptance/listenbrainz-profile-card-test.js +1 -1
@@ 89,7 89,7 @@ acceptance('ListenBrainz - User Summary - Profile Card', needs => {
        )
        assert.equal(
            recordingCreditLinks[1].href,
            'https://musicbrainz.org/artist/8f4cf6d8-8979-4396-8fd9-505c29d5dbbb',
            'https://listenbrainz.org/artist/8f4cf6d8-8979-4396-8fd9-505c29d5dbbb',
            'it links the artist credits'
        )
        assert.equal(