Encapsulate spotify integration inside rocketchat:spotify package. No more inside rocketchat:oembed.

Remove rocketchat:spotify from default list of packages inside `.meteor/{packages,version}`
pull/904/head
kakawait 10 years ago
parent 4f137830a7
commit ecb2770a30
  1. 1
      .meteor/packages
  2. 1
      .meteor/versions
  3. 8
      packages/rocketchat-oembed/client/baseWidget.coffee
  4. 1
      packages/rocketchat-oembed/package.js
  5. 2
      packages/rocketchat-spotify/client/oembedSpotifyWidget.html
  6. 3
      packages/rocketchat-spotify/client/widget.coffee
  7. 5
      packages/rocketchat-spotify/package.js
  8. 10
      packages/rocketchat-spotify/spotify.coffee

@ -41,7 +41,6 @@ rocketchat:oembed
rocketchat:slashcommands-invite
rocketchat:slashcommands-join
rocketchat:slashcommands-leave
rocketchat:spotify
rocketchat:statistics
rocketchat:webrtc
#rocketchat:livechat

@ -120,7 +120,6 @@ rocketchat:oembed@0.0.1
rocketchat:slashcommands-invite@0.0.1
rocketchat:slashcommands-join@0.0.1
rocketchat:slashcommands-leave@0.0.1
rocketchat:spotify@0.0.1
rocketchat:statistics@0.0.1
rocketchat:webrtc@0.0.1
rocketchat:wordpress@0.0.1

@ -8,7 +8,10 @@ Template.registerHelper 'match', (source, regex) ->
Template.oembedBaseWidget.helpers
template: ->
# console.log this
# console.log this
if this._overrideTemplate
return this._overrideTemplate
if this.headers?.contentType?.match(/image\/.*/)?
return 'oembedImageWidget'
@ -18,7 +21,4 @@ Template.oembedBaseWidget.helpers
if this.parsedUrl?.host is 'www.youtube.com' and this.meta?.twitterPlayer?
return 'oembedYoutubeWidget'
if this.parsedUrl?.host is 'open.spotify.com' and this.meta?.ogAudio?
return 'oembedSpotifyWidget'
return 'oembedUrlWidget'

@ -23,7 +23,6 @@ Package.onUse(function(api) {
api.addFiles('client/oembedAudioWidget.html', 'client');
api.addFiles('client/oembedYoutubeWidget.html', 'client');
api.addFiles('client/oembedSpotifyWidget.html', 'client');
api.addFiles('client/oembedUrlWidget.html', 'client');
api.addFiles('client/oembedUrlWidget.coffee', 'client');

@ -3,7 +3,7 @@
<blockquote>
<a href="https://www.spotify.com" style="color: #9e9ea6">Spotify</a><br/>
{{#if match meta.ogAudio "spotify:artist:\\S+"}}
<a href="{{url}}">{{{meta.ogTitle}}}</a><br/>
<a href="{{url}}">{{{meta.ogTitle}}}</a><br/>
{{else}}
<a href="{{url}}">{{{replace meta.ogDescription ", an? (?:song|album) by (.+?) on Spotify" " - $1" true}}}</a><br/>
{{/if}}

@ -0,0 +1,3 @@
Template.oembedBaseWidget.onCreated () ->
if this.data?.parsedUrl?.host is 'open.spotify.com' and this.data?.meta?.ogAudio?
this.data._overrideTemplate = 'oembedSpotifyWidget'

@ -10,10 +10,15 @@ Package.onUse(function(api) {
api.use([
'coffeescript',
'templating',
'underscore',
'rocketchat:oembed@0.0.1',
'rocketchat:lib@0.0.1'
]);
api.addFiles('client/widget.coffee', 'client');
api.addFiles('client/oembedSpotifyWidget.html', 'client');
api.addFiles('spotify.coffee', ['server','client']);
});

@ -1,5 +1,5 @@
###
# Spotify a named function that will process Spotify (ex: spotify:track:1q6IK1l4qpYykOaWaLJkWG)
# Spotify a named function that will process Spotify links or syntaxes (ex: spotify:track:1q6IK1l4qpYykOaWaLJkWG)
# @param {Object} message - The message object
###
@ -23,7 +23,7 @@ class Spotify
changed = false
process message, message.msg, (message, msgParts, part) ->
re = /spotify:([^:]+):(\S+)/g
re = /(?:^|\s)spotify:([^:]+):(\S+)(?:\s|$)/g
while match = re.exec(part)
url = "https://open.spotify.com/" + _.escape match[1] + "/" + _.escape match[2]
urls.push {'url': url}
@ -37,9 +37,9 @@ class Spotify
@render: (message) ->
process message, message.html, (message, msgParts, part, index) ->
msgParts[index] = part.replace /(^|\s)spotify:([^:]+):(\S+)(\s|$)/g, (match, p1, p2, p3, p4) ->
url = 'https://open.spotify.com/' + _.escape p2 + '/' + _.escape p3
return p1 + '<a href="' + url + '" target="_blank">spotify:' + p2 + ':' + p3 + '</a>' + p4
msgParts[index] = part.replace /(^|\s)spotify:([^:]+):(\S+)(\s|$)/g, (match, before, type, id, after) ->
url = 'https://open.spotify.com/' + _.escape type + '/' + _.escape id
return before + '<a href="' + url + '" target="_blank">spotify:' + type + ':' + id + '</a>' + after
message.html = msgParts.join('')
return message

Loading…
Cancel
Save