mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-09-23 18:38:18 +00:00
Merge "Implement getSubscribableHeading/isSubscribable in JS and use"
This commit is contained in:
commit
793c8e990e
|
@ -42,6 +42,17 @@ CommentItem.prototype.getHeading = function () {
|
|||
return parent;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {HeadingItem|null} losest heading that can be used for topic subscriptions
|
||||
*/
|
||||
CommentItem.prototype.getSubscribableHeading = function () {
|
||||
var heading = this.getHeading();
|
||||
while ( heading && heading.type === 'heading' && !heading.isSubscribable() ) {
|
||||
heading = heading.parent;
|
||||
}
|
||||
return ( heading && heading.type === 'heading' ) ? heading : null;
|
||||
};
|
||||
|
||||
// TODO: Implement getBodyRange/getBodyHTML/getBodyText/getMentions if required
|
||||
|
||||
module.exports = CommentItem;
|
||||
|
|
|
@ -45,4 +45,22 @@ HeadingItem.prototype.getHeading = function () {
|
|||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check whether this heading can be used for topic subscriptions.
|
||||
*
|
||||
* @return {boolean}
|
||||
*/
|
||||
HeadingItem.prototype.isSubscribable = function () {
|
||||
return (
|
||||
// Placeholder headings have nothing to attach the button to.
|
||||
!this.placeholderHeading &&
|
||||
// We only allow subscribing to level 2 headings, because the user interface for sub-headings
|
||||
// would be difficult to present.
|
||||
this.headingLevel === 2 &&
|
||||
// Check if the name corresponds to a section that contain no comments (only sub-sections).
|
||||
// They can't be distinguished from each other, so disallow subscribing.
|
||||
this.name !== 'h-'
|
||||
);
|
||||
};
|
||||
|
||||
module.exports = HeadingItem;
|
||||
|
|
|
@ -8,7 +8,6 @@ var
|
|||
storage = mw.storage.session,
|
||||
Parser = require( './Parser.js' ),
|
||||
ThreadItem = require( './ThreadItem.js' ),
|
||||
HeadingItem = require( './HeadingItem.js' ),
|
||||
CommentItem = require( './CommentItem.js' ),
|
||||
CommentDetails = require( './CommentDetails.js' ),
|
||||
ReplyLinksController = require( './ReplyLinksController.js' ),
|
||||
|
@ -862,14 +861,13 @@ function init( $container, state ) {
|
|||
}
|
||||
}
|
||||
}
|
||||
for ( i = 0; i < recentComments.length; i++ ) {
|
||||
var headingItem = recentComments[ i ].getHeading();
|
||||
while ( headingItem instanceof HeadingItem && headingItem.headingLevel !== 2 ) {
|
||||
headingItem = headingItem.parent;
|
||||
recentComments.forEach( function ( recentComment ) {
|
||||
var headingItem = recentComment.getSubscribableHeading();
|
||||
if ( headingItem ) {
|
||||
// Use names as object keys to deduplicate if there are multiple comments in a topic.
|
||||
headingsToUpdate[ headingItem.name ] = headingItem;
|
||||
}
|
||||
// Use names as object keys to deduplicate if there are multiple comments in a topic.
|
||||
headingsToUpdate[ headingItem.name ] = headingItem;
|
||||
}
|
||||
} );
|
||||
updateSubscriptionStates( $container, headingsToUpdate );
|
||||
}
|
||||
} );
|
||||
|
|
Loading…
Reference in a new issue