Thread viewer for Bluesky
at 2.0 126 lines 2.2 kB view raw
1import { atURI, castToInt } from '../utils.js'; 2 3/** 4 * Generic record type, base class for all records or record view objects. 5 */ 6 7export class ATProtoRecord { 8 9 /** @param {json} data, @param {json} [extra] */ 10 constructor(data, extra) { 11 this.data = data; 12 Object.assign(this, extra ?? {}); 13 } 14 15 /** @returns {string} */ 16 get uri() { 17 return this.data.uri; 18 } 19 20 /** @returns {string} */ 21 get cid() { 22 return this.data.cid; 23 } 24 25 /** @returns {string} */ 26 get rkey() { 27 return atURI(this.uri).rkey; 28 } 29 30 /** @returns {string} */ 31 get type() { 32 return this.data.$type; 33 } 34} 35 36 37/** 38 * Record representing a feed generator. 39 */ 40 41export class FeedGeneratorRecord extends ATProtoRecord { 42 43 /** @param {json} data */ 44 constructor(data) { 45 super(data); 46 this.author = data.creator; 47 } 48 49 /** @returns {string | undefined} */ 50 get title() { 51 return this.data.displayName; 52 } 53 54 /** @returns {string | undefined} */ 55 get description() { 56 return this.data.description; 57 } 58 59 /** @returns {number} */ 60 get likeCount() { 61 return castToInt(this.data.likeCount); 62 } 63 64 /** @returns {string | undefined} */ 65 get avatar() { 66 return this.data.avatar; 67 } 68} 69 70 71/** 72 * Record representing a user list or moderation list. 73 */ 74 75export class UserListRecord extends ATProtoRecord { 76 77 /** @param {json} data */ 78 constructor(data) { 79 super(data); 80 this.author = data.creator; 81 } 82 83 /** @returns {string | undefined} */ 84 get title() { 85 return this.data.name; 86 } 87 88 /** @returns {string | undefined} */ 89 get purpose() { 90 return this.data.purpose; 91 } 92 93 /** @returns {string | undefined} */ 94 get description() { 95 return this.data.description; 96 } 97 98 /** @returns {string | undefined} */ 99 get avatar() { 100 return this.data.avatar; 101 } 102} 103 104 105/** 106 * Record representing a starter pack. 107 */ 108 109export class StarterPackRecord extends ATProtoRecord { 110 111 /** @param {json} data */ 112 constructor(data) { 113 super(data); 114 this.author = data.creator; 115 } 116 117 /** @returns {string | undefined} */ 118 get title() { 119 return this.data.record.name; 120 } 121 122 /** @returns {string | undefined} */ 123 get description() { 124 return this.data.record.description; 125 } 126}