Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add wechaty document #725

Merged
merged 20 commits into from
Aug 31, 2017
Merged

add wechaty document #725

merged 20 commits into from
Aug 31, 2017

Conversation

lijiarui
Copy link
Member

@huan
Copy link
Member

huan commented Aug 12, 2017

Thanks! Please get at least three votes(approved) from our contributor team first, because the document needs to be improved heavily and continuously.

Copy link
Member

@huan huan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all those hard works for the documentation, I believe it will help other developers a lot after published.

There have two additional jobs of this PR:

  1. Please also generate the MarkDown file for the jsdoc by run npm run doc and make sure the generated document file at docs/index.md is what we want.
  2. Please add @private to all the methods/functions which are not listed at the README API Reference section because they are just for internal use and should not be treat as published API

I also post all my reviews to the PR, please follow them as well.

src/room.ts Outdated
@@ -547,9 +766,51 @@ export class Room extends EventEmitter implements Sayable {
}

/**
* @todo document me
* Find member by name | roomAlias(alias) | contactAlias.
* It got many, return the first
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It -> If
return -> returns

src/room.ts Outdated
* @returns {(Contact | null)}
* @example
* ```ts
* // change 'wechaty' to any room in your wechat
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any room -> any room name

src/room.ts Outdated
* @example
* ```ts
* // change 'wechaty' to any room in your wechat
* const room = await Room.find({topic: wechaty})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- const room = await Room.find({topic: wechaty})
+ const room = await Room.find({topic: 'wechaty'})

src/room.ts Outdated
* @example
* ```ts
* // change 'wechaty' to any room in your wechat
* const room = await Room.find({topic: wechaty})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'wechaty'

src/room.ts Outdated
@@ -611,7 +893,18 @@ export class Room extends EventEmitter implements Sayable {
}

/**
* @todo document me
* Find room by topic, return all the match room
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the matched room

src/room.ts Outdated
* Get room leave event, emitted when bot remove someone from the room or someone remove the bot from the room.
* If both personA and personB are not the bot itselt, the event cannot be fired if personA remove personB from the room
* This is Sayable for all listeners.
* Which means there will be a this.say() the method inside listener call,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.say()

src/room.ts Outdated
/**
* @todo document me
* Get room join event, emitted when someone join the room
* This is Sayable for all listeners.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need not to document the this is sayable so many times.

One time is enough.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think it should document on each function because not all of the developers will read the whole doc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So do you mean that if something is important, then we should put it everywhere?

I have to disagree with you.

src/room.ts Outdated
/**
* @todo document me
* Get EVENT_PARAM_ERROR event
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The EVENT_PARAM_ERROR is just a guard for IDE Intelligence.

Need not be documented, and should be set to @private

src/room.ts Outdated
/**
* @todo document me
* Get RoomEventName event
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is the implementation of all the event listeners above.

No need to be documented too.

src/room.ts Outdated
* @example
* ```ts
* const room = await Room.find({name: 'wechaty'}) // change 'wechaty' to any of your room in wechat
* await room.say('/test.jpg') // put the filePath you want to send here
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await room.say(new MediaMessage('/test.jpg'))

@huan huan removed the request for review from imWildCat August 16, 2017 19:39
@lijiarui
Copy link
Member Author

lijiarui commented Aug 17, 2017

here is the auto generate doc: https://github.com/lijiarui/wechaty/blob/new-doc/docs/index.md

not sure why it has double wechaty intro....

will keep on dig in it, or anyone can help? @ax4

src/message.ts Outdated
*
* Enum for MsgType values.
* @enum {number}
*/
Copy link
Contributor

@kis87988 kis87988 Aug 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should include message type in to documentation
update: I saw you write below. then should we just private this in documentation?

Copy link
Member Author

@lijiarui lijiarui Aug 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks nice:)

@kis87988
Copy link
Contributor

maybe we should add all return promise type with notice "await"

@huan
Copy link
Member

huan commented Aug 18, 2017

In our current implementation of the doc generator script npm run doc, when we are generating the document, it is actually reading the jsdoc from dist/**/*.js, like dist/src/wechaty.js. You can generate the files under dist/ directory by run npm run dist, and make sure all the javascript class with jsdoc looks good.

BTW: I saw lots of ISC License in the generated document, it's not right. The license of the Wechaty project is Apache-2.0. There might have some comments say "ISC license", should be replaced.

@huan huan requested review from hczhcz and mukaiu August 18, 2017 02:16
@kis87988
Copy link
Contributor

ISC License should be changed in whchaty.ts @line#68

@huan
Copy link
Member

huan commented Aug 18, 2017

Thanks, @kis87988, I had fixed that by removing the LICENSE info.

@lijiarui lijiarui requested a review from huan August 18, 2017 06:31
@coveralls
Copy link

coveralls commented Aug 18, 2017

Coverage Status

Coverage remained the same at 54.688% when pulling 5a7802b on lijiarui:master into d3aa251 on Chatie:master.

Copy link
Member

@huan huan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update, it looks better now.

Could you please include the docs/index.md in the next PR?

Please make sure that the index.md file content is expected.

Have a nice weekend!

src/contact.ts Outdated
@@ -651,6 +679,9 @@ export class Contact implements Sayable {
})
}

/**
* @deprecated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also @private for @deprecated, please.

src/message.ts Outdated
* Set the destination as Contact for the message
*
* @param {Contact} contact
* @returns {void}
*/
public to(contact: Contact): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should be marked as @private because normally use should not use Wechaty API to set the destination of the message by call to().

We use Sayables to send message to contact, like contact.say() and room.say()

src/message.ts Outdated
/**
* Set the destination as Contact by 'weixinID', eg: 'filehelper', for the message
*
* @param {string} id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be marked as @private

src/message.ts Outdated
/**
* Set the destination as Contact by 'weixinID', eg: 'filehelper', for the message
*
* @param {string} id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be marked as @private

src/message.ts Outdated
* Set the room for a message
*
* @param {Room} room
* @returns {void}
*/
public room(room: Room): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be marked as @private

src/message.ts Outdated
@@ -667,12 +858,34 @@ export class Message implements Sayable {
// Message.initType()

export class MediaMessage extends Message {
/**
* @private
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if the class property is already private, then we will not need to use @private in jsdoc again?

src/message.ts Outdated
*
* @returns {string}
* @example
* ```ts
Copy link
Member

@huan huan Aug 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please help me to find a button with resolve text on it, near this review message?

Because @binsee also need that button... thanks.

src/message.ts Outdated
*
* @returns {string}
* @example
* ```ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please mark the review as resolved by GitHub button.

src/room.ts Outdated
@@ -440,7 +667,9 @@ export class Room extends EventEmitter implements Sayable {
}

/**
* @todo document me
* Get room's owner from the room.
* Not recommend, because cannot always get the owner
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add @deprecated because it is very useless, almost no use.

src/wechaty.ts Outdated
* const nameList = leaverList.map(c => c.name()).join(',')
* console.log(`Room ${room.topic()} lost member ${nameList}`)
* })
* ```
*/
public on(event: 'room-leave' , listener: (this: Wechaty, room: Room, leaverList: Contact[]) => void): this
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a notice about the silent leave:

If someone leaves the room by themselves, wechat will not notice other people in the room, so the bot will never get the "leave" event.

@lijiarui lijiarui requested a review from huan August 20, 2017 20:40
Copy link
Member

@huan huan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are too many unrelated changes in the diff.

Please only keep the related change in PR.

docs/index.md Outdated
if (ret) {
console.log(`change ${contact.name()}'s alias successfully!`)
} else {
console.error('failed to change ${contact.name()}'s alias!')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- console.error('failed to change ${contact.name()}'s alias!')
+ console.error(`failed to change ${contact.name()}`s alias!')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

src/contact.ts Outdated
@@ -1,7 +1,8 @@
/**
* @ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move @ignore to the end of the comment, instead of at the beginning of?

src/message.ts Outdated
public typeApp(): AppMsgType {
if (!this.rawObj) {
throw new Error('no rawObj')
public say(textOrMedia: string | MediaMessage, replyTo?: Contact|Contact[]): Promise<any> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you rewrite so many original methods, could you get rid of all the unrelated changes?

Because it makes the diff shows lots of mess, and make the review becomes a hard job.

src/message.ts Outdated
* @see {@link MsgType}
* @returns {MsgType}
*/
public type(): MsgType {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same question as above: your diff should not include unrelated changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@lijiarui lijiarui requested a review from huan August 21, 2017 07:42
Copy link
Member

@huan huan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The jsdoc looks better to me now, thank you very much for all the work of writing the documents and examples!

I have some minor reviews. After resolved them, I'll be able to vote for my approvement.

docs/index.md Outdated
if (ret) {
console.log(`change ${contact.name()}'s alias successfully!`)
} else {
console.error('failed to change ${contact.name()}'s alias!')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

* @example
* ```ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could please confirm it for me that we do not need "```ts" block inside @example?

Copy link
Member Author

@lijiarui lijiarui Aug 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I looked into the doc and confirmed, then changed all ``` inside @example

see http://usejsdoc.org/tags-example.html

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks.

@@ -277,52 +278,40 @@ export class Contact implements Sayable {
/**
* Contact gender
*
* @returns Gender.Male(2) | Gender.Female(1) | Gender.Unknown(0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use Gender.Male Gender.Female and Gender.Unknown, there's no need to refer the number value of them because that's why ENUM type exists: Do not rely on the magic numbers.

So does the other ENUM types.

Copy link
Member Author

@lijiarui lijiarui Aug 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, m.type() return too much type, are you sure use like this?

https://github.com/lijiarui/wechaty/blob/master/docs/index.md#Message+type

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Just use the ENUM names please.

src/contact.ts Outdated
* The way to search Contact
*
* @typedef ContactQueryFilter
* @property {string} name -the name-string set by user-self, should be called name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-the name to - The name?

src/contact.ts Outdated
*/
public async say(text: string)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you deleted the overloading function declaration?

They should be kept because those are for TypeScript IDE Intelligence.

src/message.ts Outdated
* Enum for AppMsgType values.
*
* @enum {number}
* @property {number} TEXT - 1 for TEXT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just let users know AppMsgType.IMG, without the exact number.

When we use Wechaty, we should just use AppMsgType.IMG instead of 2

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean change 1 to AppMsgType .TEXT here?

Copy link
Member

@huan huan Aug 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so if there's no other problem.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After I thought more if any want to know the number for more development, such as ipad protocol or xposed, maybe we should tell them the wechat raw number, So I add both AppMsgType .TEXT and 1 here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll not argue with you about that, It's ok.

But I'd like to assume that the other protocols are different with the Web.

src/message.ts Outdated
*/
public content(): string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the overloading method declaration.

src/room.ts Outdated
* @todo document me
* @desc Room Class Event Function
* @typedef RoomEventFunction
* @property {Function} room-join -(this: Room, inviteeList: Contact[] , inviter: Contact) => void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a space? - (this...

@lijiarui lijiarui requested a review from huan August 27, 2017 11:47
@huan huan mentioned this pull request Aug 30, 2017
Copy link
Member

@hczhcz hczhcz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job! The documentation looks good to me.

There might be something need to be modified, but I would suggest merge this PR and do these updates in successor PRs.

* Wechaty - https://github.com/chatie/wechaty
*
* Copyright 2016-2017 Huan LI <zixia@zixia.net>
* @copyright 2016-2017 Huan LI <zixia@zixia.net>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better if all files share the same header (copyright info, license, etc)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hczhcz thanks! I'll do that later by an util script written by me at https://github.com/Chatie/wechaty/blob/master/script/update-license.ts, in case you are interested at.

@binsee
Copy link

binsee commented Aug 31, 2017

look forward to merge

@lijiarui
Copy link
Member Author

@binsee Could you help to approve this pull request? then @zixia can merge this, thanks!

@lijiarui lijiarui requested a review from binsee August 31, 2017 11:59
Copy link

@binsee binsee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job

@huan
Copy link
Member

huan commented Aug 31, 2017

Great! Thank you @hczhcz @binsee for reviewing this PR, appreciate that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants