diff --git a/models.js b/models.js index f4bb9c4..871eb03 100644 --- a/models.js +++ b/models.js @@ -250,12 +250,12 @@ class Post extends ATProtoRecord { /** @returns {number} */ get likeCount() { - return this.data.likeCount; + return castToInt(this.data.likeCount); } /** @returns {number} */ get replyCount() { - return this.data.replyCount; + return castToInt(this.data.replyCount); } /** @returns {boolean} */ @@ -265,7 +265,7 @@ class Post extends ATProtoRecord { /** @returns {number} */ get repostCount() { - return this.data.repostCount; + return castToInt(this.data.repostCount); } /** @returns {boolean} */ @@ -356,7 +356,7 @@ class FeedGeneratorRecord extends ATProtoRecord { /** @returns {number} */ get likeCount() { - return this.data.likeCount; + return castToInt(this.data.likeCount); } /** @returns {string | undefined} */ diff --git a/utils.js b/utils.js index 277327a..b486dce 100644 --- a/utils.js +++ b/utils.js @@ -60,6 +60,14 @@ function atURI(uri) { return new AtURI(uri); } +function castToInt(value) { + if (value === undefined || value === null || typeof value == "number") { + return value; + } else { + return parseInt(value, 10); + } +} + /** @param {string} html, @returns {string} */ function escapeHTML(html) {