mediawiki-extensions-Discus.../modules/CommentItem.js
Ed Sanders 579b8bb1d4 Implement getTimestampString on CommentItem
Change-Id: I1768e9993debe904d6a228942ad0188486d65c0b
2022-03-24 16:49:35 +00:00

71 lines
2.1 KiB
JavaScript

var ThreadItem = require( './ThreadItem.js' );
/**
* A comment item
*
* @class CommentItem
* @extends ThreadItem
* @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.
* The last node in every signature range is a node containing the timestamp.
* @param {moment} [timestamp] Timestamp (Moment object)
* @param {string} [author] Comment author's username
*/
function CommentItem( level, range, signatureRanges, timestamp, author ) {
// Parent constructor
CommentItem.super.call( this, 'comment', level, range );
this.signatureRanges = signatureRanges || [];
this.timestamp = timestamp || null;
this.author = author || null;
/**
* @member {ThreadItem} Parent thread item
*/
this.parent = null;
}
OO.inheritClass( CommentItem, ThreadItem );
/**
* Get the comment timestamp in a standard format
*
* Uses ISO 8601 date. Almost DateTimeInterface::RFC3339_EXTENDED, but ending with 'Z' instead
* of '+00:00', like Date#toISOString in JavaScript.
*
* @return {string} Comment timestamp in standard format
*/
CommentItem.prototype.getTimestampString = function () {
return this.timestamp.toISOString();
};
/**
* @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;
};
/**
* @return {HeadingItem|null} Closest 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;