-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Implement Label related methods #1864
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
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution!
The basic design looks great, I think you had understood my design very well after reading your code.
Please follow my reviews, and leave your comments if you want any discussion about this PR.
…nd implemented all methods relates to Label.
@huan I have implemented all Label related methods conform to design, waiting for your review and suggestions. Thank you. |
src/user/tag.ts
Outdated
log.verbose('Tag', 'get()') | ||
|
||
try { | ||
const tagPayload: TagPayload = await this.puppet.createTag(tag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the tag exists, we should not create a new tag here, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will return the existed tag instead of creating.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then the function is misleading. We shouldn't call it createTag
, it should be getOrCreateTag
or something else. createTag
explicitly tell the user that this is creating a tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, getOrCreateTag()
is better for the puppet method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess @huan might not like this design :P
Let's wait for his review.
@huan ping |
I have re-write some code in this PR for designing a more clear & easy to use published API. Please let me know what you think @su-chang @windmemory @xinbenlv , thank you very much! The biggest change is that I decided to do not use any This design will leave all the implementation details inside the puppet, and we get the highest abstract for our end user API. |
src/user/tag.ts
Outdated
* @example | ||
* await tag.del() | ||
*/ | ||
public async del (from: Contact): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to delete a tag entirely, how to achieve that with the current design?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can not do delete tag itself operations in this design.
I think we can just leave tag as they are will be cleaner for the Tag API.
BTW: I think we should rename all del()
to remove()
because it's more intuitive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleaner Tag API will make Tags in WeChat not clean.
If we don't remove tag which we do not need any more, the tag will make WeChat Tags worse. I think this design will make our user who use tag frequently feel not well.
remove()
is better for this case.
src/user/tag.ts
Outdated
tag: string, | ||
): Promise<T['prototype']> { | ||
log.verbose('Tag', 'get(%s)', tag) | ||
return this.load(tag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the get
function, there is no actual puppet call, then when shall we create the tag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my current design, I want to use Lazy Operation for the Tag.
in the get()
we only save the tag string in the class. The actual operation will happen when we call add()
or del()
, and we pass the tag string to the puppet API, then puppet API deal with the tag name with the Contact or Favorite.
I think this will be a clear design with the high-level API, please feel free to let me know what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lazy Operation is perfect.
So we could use this method like this way :
const tag = await bot.Tag.get('myTag')
const friend =bot.Contact.load(xxx)
await tag.add(friend) // we will create a new tag named myTag in this method
So we need to check the tag exist or not each time when we use add()
?
I have a question about it, how could we know the tag exist or not ? Or just create new tag each time when we use add()
?
This design will make tagAddContact()
a little heavy, it means create()
+ add()
, if something wrong happened in create()
, it will wrong many times.
BTW, this method should check the tag's length, if user input a string which length over 15, we can not give a right tag back to user. It will be exposed when they use add()
method.
I have see these methods only maintain the relationship between Tag and Contact, but no method work for Tag. For example, if we want to remove one tag from tag list, we need |
Any suggestions? |
I'd love to the Lazy Operation, and Do we need a method which named It has been supported by the WeChat Protocol, and it will make the Tag system be better. But not must. I'm not insist on it. Just a suggestion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added all required methods for the Tag class, please have a look into it, and please feel free to let me know if you have any questions.
The Tag class will be available from Wechaty v0.29.41 or later. |
I'm submitting a...
Checklist
Description
please describe the changes that you are making
for features, please describe how to use the new feature
please include a reference to an existing issue, if applicable
Does this PR introduce a breaking change?