@@ -293,62 +293,73 @@ angular.module('mm.addons.messages')
293293 var self = { } ;
294294
295295 /**
296- * Whether or not the handler is enabled for the site.
296+ * Whether or not the handler is enabled for a certain site.
297297 *
298- * @return {Boolean }
298+ * @param {String } siteId Site ID.
299+ * @return {Promise } Promise resolved with true if enabled.
299300 */
300- self . isEnabled = function ( ) {
301- return $mmaMessages . isPluginEnabled ( ) ;
302- } ;
301+ function isEnabledForSite ( siteId ) {
302+ return $mmaMessages . isPluginEnabled ( siteId ) ;
303+ }
303304
304305 /**
305306 * Get actions to perform with the link.
306307 *
307- * @param {String } url URL to treat.
308- * @return {Object[] } List of actions. See {@link $mmContentLinksDelegate#registerLinkHandler}.
308+ * @param {String[] } siteIds Site IDs the URL belongs to.
309+ * @param {String } url URL to treat.
310+ * @return {Object[] } Promise resolved with the list of actions.
311+ * See {@link $mmContentLinksDelegate#registerLinkHandler}.
309312 */
310- self . getActions = function ( url ) {
313+ self . getActions = function ( siteIds , url ) {
311314 // Check it's a messages URL.
312315 if ( url . indexOf ( '/message/index.php' ) > - 1 ) {
313- var params = $mmUtil . extractUrlParams ( url ) ;
314- // Return actions.
315- return [ {
316- message : 'mm.core.view' ,
317- icon : 'ion-eye' ,
318- action : function ( siteId ) {
319- var stateName ,
320- stateParams ;
321-
322- if ( typeof params . user1 != 'undefined' && typeof params . user2 != 'undefined' ) {
323- // Check if the current user is in the conversation.
324- if ( $mmSite . getUserId ( ) == params . user1 ) {
325- stateName = 'site.messages-discussion' ;
326- stateParams = { userId : parseInt ( params . user2 , 10 ) } ;
327- } else if ( $mmSite . getUserId ( ) == params . user2 ) {
328- stateName = 'site.messages-discussion' ;
329- stateParams = { userId : parseInt ( params . user1 , 10 ) } ;
330- } else {
331- // He isn't, open in browser.
332- $mmUtil . openInBrowser ( url ) ;
333- return ;
316+ // Pass false because all sites should have the same siteurl.
317+ return $mmContentLinksHelper . filterSupportedSites ( siteIds , isEnabledForSite , false ) . then ( function ( ids ) {
318+ if ( ! ids . length ) {
319+ return [ ] ;
320+ } else {
321+ // Return actions.
322+ var params = $mmUtil . extractUrlParams ( url ) ;
323+ return [ {
324+ message : 'mm.core.view' ,
325+ icon : 'ion-eye' ,
326+ sites : ids ,
327+ action : function ( siteId ) {
328+ var stateName ,
329+ stateParams ;
330+
331+ if ( typeof params . user1 != 'undefined' && typeof params . user2 != 'undefined' ) {
332+ // Check if the current user is in the conversation.
333+ if ( $mmSite . getUserId ( ) == params . user1 ) {
334+ stateName = 'site.messages-discussion' ;
335+ stateParams = { userId : parseInt ( params . user2 , 10 ) } ;
336+ } else if ( $mmSite . getUserId ( ) == params . user2 ) {
337+ stateName = 'site.messages-discussion' ;
338+ stateParams = { userId : parseInt ( params . user1 , 10 ) } ;
339+ } else {
340+ // He isn't, open in browser.
341+ $mmUtil . openInBrowser ( url ) ;
342+ return ;
343+ }
344+ } else if ( typeof params . id != 'undefined' ) {
345+ stateName = 'site.messages-discussion' ;
346+ stateParams = { userId : parseInt ( params . id , 10 ) } ;
347+ }
348+
349+ if ( ! stateName ) {
350+ // Go to messaging index page. We use redirect state to view the side menu.
351+ $state . go ( 'redirect' , {
352+ siteid : siteId ,
353+ state : 'site.messages' ,
354+ params : { }
355+ } ) ;
356+ } else {
357+ $mmContentLinksHelper . goInSite ( stateName , stateParams , siteId ) ;
358+ }
334359 }
335- } else if ( typeof params . id != 'undefined' ) {
336- stateName = 'site.messages-discussion' ;
337- stateParams = { userId : parseInt ( params . id , 10 ) } ;
338- }
339-
340- if ( ! stateName ) {
341- // Go to messaging index page. We use redirect state to view the side menu.
342- $state . go ( 'redirect' , {
343- siteid : siteId ,
344- state : 'site.messages' ,
345- params : { }
346- } ) ;
347- } else {
348- $mmContentLinksHelper . goInSite ( stateName , stateParams , siteId ) ;
349- }
360+ } ] ;
350361 }
351- } ] ;
362+ } ) ;
352363 }
353364 return [ ] ;
354365 } ;
0 commit comments