diff --git a/src/contact.ts b/src/contact.ts index d38410b3964d0c189e8e7dda953a71d74d502799..b05a13e968e4d9f731cc0122dcea93aacc525f45 100644 --- a/src/contact.ts +++ b/src/contact.ts @@ -104,6 +104,9 @@ export class Contact implements Sayable { private dirtyObj: ContactObj | null private rawObj: ContactRawObj + /** + * @private + */ constructor( public readonly id: string, ) { diff --git a/src/message.ts b/src/message.ts index 2b1a589cef3315e8645cecbfcd5edf7a656410fb..0cb92cd12f426ccbb301a362f32cbabf9922dfb7 100644 --- a/src/message.ts +++ b/src/message.ts @@ -244,6 +244,9 @@ export class Message implements Sayable { throw Error('not a media message') } + /** + * @private + */ constructor(public rawObj?: MsgRawObj) { this._counter = Message.counter++ log.silly('Message', 'constructor() SN:%d', this._counter) @@ -315,6 +318,9 @@ export class Message implements Sayable { return '{' + this.type() + '}' + content } + /** + * @todo document me + */ public from(contact: Contact): void public from(id: string): void public from(): Contact @@ -340,6 +346,9 @@ export class Message implements Sayable { // public to(room: Room): void // public to(): Contact|Room // public to(contact?: Contact|Room|string): Contact|Room|void { + /** + * @todo document me + */ public to(contact: Contact): void public to(id: string): void public to(): Contact|null // if to is not set, then room must had set @@ -364,6 +373,9 @@ export class Message implements Sayable { return Contact.load(this.obj.to) } + /** + * @todo document me + */ public room(room: Room): void public room(id: string): void public room(): Room|null @@ -384,6 +396,9 @@ export class Message implements Sayable { return null } + /** + * @todo document me + */ public content(): string public content(content: string): void @@ -395,10 +410,16 @@ export class Message implements Sayable { return this.obj.content } + /** + * @todo document me + */ public type(): MsgType { return this.obj.type } + /** + * @todo document me + */ public typeSub(): MsgType { if (!this.rawObj) { throw new Error('no rawObj') @@ -406,6 +427,9 @@ export class Message implements Sayable { return this.rawObj.SubMsgType } + /** + * @todo document me + */ public typeApp(): AppMsgType { if (!this.rawObj) { throw new Error('no rawObj') @@ -413,9 +437,18 @@ export class Message implements Sayable { return this.rawObj.AppMsgType } + /** + * @todo document me + */ public typeEx() { return MsgType[this.obj.type] } + /** + * @todo document me + */ public count() { return this._counter } + /** + * @todo document me + */ public self(): boolean { const userId = config.puppetInstance() .userId @@ -579,6 +612,9 @@ export class Message implements Sayable { // }) // } + /** + * @todo document me + */ public say(text: string, replyTo?: Contact | Contact[]): Promise public say(mediaMessage: MediaMessage, replyTo?: Contact | Contact[]): Promise @@ -736,6 +772,9 @@ export class MediaMessage extends Message { } } + /** + * @todo document me + */ public ext(): string { if (this.fileExt) return this.fileExt @@ -770,6 +809,9 @@ export class MediaMessage extends Message { throw new Error('not support type: ' + this.type()) } + /** + * @todo document me + */ public filename(): string { if (this.fileName && this.fileExt) { return this.fileName + '.' + this.fileExt diff --git a/src/room.ts b/src/room.ts index 4af33413fe5813de181b1bb5083a8765b11a5642..c1cc1248d5415cfe54b55ac980b22400552fd06e 100644 --- a/src/room.ts +++ b/src/room.ts @@ -92,11 +92,17 @@ export class Room extends EventEmitter implements Sayable { private obj: RoomObj | null private rawObj: RoomRawObj + /** + * @private + */ constructor(public id: string) { super() log.silly('Room', `constructor(${id})`) } + /** + * @private + */ public toString() { return this.id } public toStringEx() { return `Room(${this.obj && this.obj.topic}[${this.id}])` } @@ -104,6 +110,9 @@ export class Room extends EventEmitter implements Sayable { return !!(this.obj && this.obj.memberList && this.obj.memberList.length) } + /** + * @todo document me + */ public async refresh(): Promise { if (this.isReady()) { this.dirtyObj = this.obj @@ -161,11 +170,25 @@ export class Room extends EventEmitter implements Sayable { } } + /** + * @todo document me + */ public on(event: 'leave', listener: (this: Room, leaver: Contact) => void): this + /** + * @todo document me + */ public on(event: 'join' , listener: (this: Room, inviteeList: Contact[] , inviter: Contact) => void): this + /** + * @todo document me + */ public on(event: 'topic', listener: (this: Room, topic: string, oldTopic: string, changer: Contact) => void): this + /** + * @todo document me + */ public on(event: 'EVENT_PARAM_ERROR', listener: () => void): this - + /** + * @todo document me + */ public on(event: RoomEventName, listener: (...args: any[]) => any): this { log.verbose('Room', 'on(%s, %s)', event, typeof listener) @@ -173,6 +196,9 @@ export class Room extends EventEmitter implements Sayable { return this } + /** + * @todo document me + */ public say(mediaMessage: MediaMessage) public say(content: string) public say(content: string, replyTo: Contact) @@ -212,6 +238,9 @@ export class Room extends EventEmitter implements Sayable { public get(prop): string { return (this.obj && this.obj[prop]) || (this.dirtyObj && this.dirtyObj[prop]) } + /** + * @private + */ private parse(rawObj: RoomRawObj): RoomObj | null { if (!rawObj) { log.warn('Room', 'parse() on a empty rawObj?') @@ -278,6 +307,9 @@ export class Room extends EventEmitter implements Sayable { Object.keys(this.obj).forEach(k => console.error(`${k}: ${this.obj && this.obj[k]}`)) } + /** + * @todo document me + */ public async add(contact: Contact): Promise { log.verbose('Room', 'add(%s)', contact) @@ -290,6 +322,9 @@ export class Room extends EventEmitter implements Sayable { return n } + /** + * @todo document me + */ public async del(contact: Contact): Promise { log.verbose('Room', 'del(%s)', contact.name()) @@ -302,6 +337,9 @@ export class Room extends EventEmitter implements Sayable { return n } + /** + * @todo document me + */ private delLocal(contact: Contact): number { log.verbose('Room', 'delLocal(%s)', contact) @@ -379,6 +417,9 @@ export class Room extends EventEmitter implements Sayable { return this.roomAlias(contact) } + /** + * @todo document me + */ public roomAlias(contact: Contact): string | null { if (!this.obj || !this.obj.roomAliasMap) { return null @@ -386,6 +427,9 @@ export class Room extends EventEmitter implements Sayable { return this.obj.roomAliasMap[contact.id] || null } + /** + * @todo document me + */ public has(contact: Contact): boolean { if (!this.obj || !this.obj.memberList) { return false @@ -395,6 +439,9 @@ export class Room extends EventEmitter implements Sayable { .length > 0 } + /** + * @todo document me + */ public owner(): Contact | null { const ownerUin = this.obj && this.obj.ownerUin @@ -499,6 +546,9 @@ export class Room extends EventEmitter implements Sayable { } } + /** + * @todo document me + */ public member(name: string): Contact | null public member(filter: MemberQueryFilter): Contact | null @@ -524,6 +574,9 @@ export class Room extends EventEmitter implements Sayable { return memberList[0] } + /** + * @todo document me + */ public memberList(): Contact[] { log.verbose('Room', 'memberList') @@ -538,6 +591,9 @@ export class Room extends EventEmitter implements Sayable { return this.obj.memberList } + /** + * @todo document me + */ public static create(contactList: Contact[], topic?: string): Promise { log.verbose('Room', 'create(%s, %s)', contactList.join(','), topic) @@ -554,6 +610,9 @@ export class Room extends EventEmitter implements Sayable { }) } + /** + * @todo document me + */ public static async findAll(query?: RoomQueryFilter): Promise { if (!query) { query = { topic: /.*/ } diff --git a/src/wechaty.ts b/src/wechaty.ts index 64749ea64e9ccb052d634a1496f04b8f4992a82a..7803dbcadae82cfac8b9e4dc270fd11e006dc4c6 100644 --- a/src/wechaty.ts +++ b/src/wechaty.ts @@ -170,6 +170,9 @@ export class Wechaty extends EventEmitter implements Sayable { return config.npmVersion() } + /** + * @todo document me + */ public version(forceNpm?) { return Wechaty.version(forceNpm) } @@ -281,7 +284,6 @@ export class Wechaty extends EventEmitter implements Sayable { /** * @todo document me */ - public on(event: WechatyEventName, listener: (...args: any[]) => any): this { log.verbose('Wechaty', 'addListener(%s, %s)', event, typeof listener) @@ -447,7 +449,6 @@ export class Wechaty extends EventEmitter implements Sayable { /** * @todo document me * @static - * */ public static async sleep(millisecond: number): Promise { await new Promise(resolve => {