2022-06-20 20:12:06 +00:00
|
|
|
var ThreadItem = require( './ThreadItem.js' ),
|
|
|
|
moment = require( './lib/moment-timezone/moment-timezone-with-data-1970-2030.js' );
|
2020-05-22 16:26:05 +00:00
|
|
|
|
2020-06-25 12:23:17 +00:00
|
|
|
/**
|
|
|
|
* A comment item
|
|
|
|
*
|
|
|
|
* @class CommentItem
|
2020-08-26 22:46:34 +00:00
|
|
|
* @extends ThreadItem
|
2020-06-25 12:23:17 +00:00
|
|
|
* @constructor
|
|
|
|
* @param {number} level
|
|
|
|
* @param {Object} range
|
|
|
|
* @param {Object[]} [signatureRanges] Objects describing the extent of signatures (plus
|
|
|
|
* timestamps) for this comment. There is always at least one signature, but there may be
|
|
|
|
* multiple. The author and timestamp of the comment is determined from the first signature.
|
2022-10-04 12:50:57 +00:00
|
|
|
* @param {Object[]} [timestampRanges] Objects describing the extent of timestamps within
|
|
|
|
* the above signatures.
|
2020-06-25 12:23:17 +00:00
|
|
|
* @param {moment} [timestamp] Timestamp (Moment object)
|
|
|
|
* @param {string} [author] Comment author's username
|
2022-02-04 18:16:24 +00:00
|
|
|
* @param {string|null} [displayName] Comment author's display name
|
2020-06-25 12:23:17 +00:00
|
|
|
*/
|
2022-10-04 12:50:57 +00:00
|
|
|
function CommentItem( level, range, signatureRanges, timestampRanges, timestamp, author, displayName ) {
|
2020-05-22 16:26:05 +00:00
|
|
|
// Parent constructor
|
|
|
|
CommentItem.super.call( this, 'comment', level, range );
|
|
|
|
|
|
|
|
this.signatureRanges = signatureRanges || [];
|
2022-10-04 12:50:57 +00:00
|
|
|
this.timestampRanges = timestampRanges || [];
|
2020-05-22 16:26:05 +00:00
|
|
|
this.timestamp = timestamp || null;
|
|
|
|
this.author = author || null;
|
2022-02-04 18:16:24 +00:00
|
|
|
this.displayName = displayName || null;
|
2020-06-25 12:23:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @member {ThreadItem} Parent thread item
|
|
|
|
*/
|
|
|
|
this.parent = null;
|
2020-05-22 16:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OO.inheritClass( CommentItem, ThreadItem );
|
|
|
|
|
2022-03-24 16:48:25 +00:00
|
|
|
/**
|
2022-06-20 20:12:06 +00:00
|
|
|
* Get the comment timestamp in the format used in IDs and names.
|
2022-03-24 16:48:25 +00:00
|
|
|
*
|
2022-06-20 20:12:06 +00:00
|
|
|
* Depending on the date of the comment, this may use one of two formats:
|
|
|
|
*
|
|
|
|
* - For dates prior to 'DiscussionToolsTimestampFormatSwitchTime' (by default 2022-07-12):
|
|
|
|
* Uses ISO 8601 date. Almost DateTimeInterface::RFC3339_EXTENDED, but ending with 'Z' instead
|
|
|
|
* of '+00:00', like Date#toISOString in JavaScript.
|
|
|
|
*
|
|
|
|
* - For dates on or after 'DiscussionToolsTimestampFormatSwitchTime' (by default 2022-07-12):
|
|
|
|
* Uses MediaWiki timestamp (TS_MW in MediaWiki PHP code).
|
2022-03-24 16:48:25 +00:00
|
|
|
*
|
|
|
|
* @return {string} Comment timestamp in standard format
|
|
|
|
*/
|
|
|
|
CommentItem.prototype.getTimestampString = function () {
|
2022-06-20 20:12:06 +00:00
|
|
|
var dtConfig = require( './config.json' );
|
2022-07-12 12:09:39 +00:00
|
|
|
var switchTime = moment.utc( dtConfig.switchTime );
|
2022-06-20 20:12:06 +00:00
|
|
|
if ( this.timestamp < switchTime ) {
|
2022-10-10 13:50:02 +00:00
|
|
|
return this.timestamp.utc().toISOString();
|
2022-06-20 20:12:06 +00:00
|
|
|
} else {
|
2022-07-13 00:33:24 +00:00
|
|
|
// Switch to English locale to avoid number formatting
|
2022-10-10 13:50:02 +00:00
|
|
|
return this.timestamp.utc().locale( 'en' ).format( 'YYYYMMDDHHmmss' );
|
2022-06-20 20:12:06 +00:00
|
|
|
}
|
2022-03-24 16:48:25 +00:00
|
|
|
};
|
|
|
|
|
2020-06-29 13:30:47 +00:00
|
|
|
/**
|
|
|
|
* @return {HeadingItem} Closest ancestor which is a HeadingItem
|
|
|
|
*/
|
|
|
|
CommentItem.prototype.getHeading = function () {
|
|
|
|
var parent = this;
|
|
|
|
while ( parent && parent.type !== 'heading' ) {
|
|
|
|
parent = parent.parent;
|
|
|
|
}
|
|
|
|
return parent;
|
|
|
|
};
|
|
|
|
|
2021-12-20 16:30:07 +00:00
|
|
|
/**
|
2022-01-31 17:01:03 +00:00
|
|
|
* @return {HeadingItem|null} Closest heading that can be used for topic subscriptions
|
2021-12-20 16:30:07 +00:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2020-07-22 18:25:34 +00:00
|
|
|
// TODO: Implement getBodyRange/getBodyHTML/getBodyText/getMentions if required
|
|
|
|
|
2020-05-22 16:26:05 +00:00
|
|
|
module.exports = CommentItem;
|