Skip to content

Conversation

su-chang
Copy link
Member

@su-chang su-chang commented Oct 11, 2019

I'm submitting a...

[ ] Bug Fix
[x] Feature
[ ] Other (Refactoring, Added tests, Documentation, ...)

Checklist

  • Commit Messages follow the Conventional Commits pattern
    • A feature commit message is prefixed "feat:"
    • A bugfix commit message is prefixed "fix:"
  • Tests for the changes have been added

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?

[ ] Yes
[ ] No

@CLAassistant
Copy link

CLAassistant commented Oct 11, 2019

CLA assistant check
All committers have signed the CLA.

@su-chang
Copy link
Member Author

su-chang commented Oct 11, 2019

related issues:
#1627
#1856

@su-chang su-chang changed the title feat: implement Label related methods Implement Label related methods Oct 11, 2019
@huan

This comment has been minimized.

@huan huan requested a review from windmemory October 12, 2019 07:25
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.

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.

@su-chang
Copy link
Member Author

su-chang commented Dec 2, 2019

@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)
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

@su-chang su-chang requested a review from huan December 5, 2019 02:00
@su-chang
Copy link
Member Author

@huan ping

@huan
Copy link
Member

huan commented Dec 30, 2019

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 payload for Tag class because the tag string itself can be the id of the Tag class.

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> {
Copy link
Member

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?

Copy link
Member

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?

Copy link
Member Author

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)
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member Author

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.

@su-chang
Copy link
Member Author

su-chang commented Jan 6, 2020

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 delete method, so that we could never see this tag again in our WeChat App. If we do not have this method, the tags in our WeChat App will be mess really, and so does modify.

@huan
Copy link
Member

huan commented Jan 8, 2020

  1. I'll consider adding a delete() method to clean the Tag for the system
  2. I'll assume that the Tag length will not longer than 15 characters. (in UTF8)
  3. I believe it will be better to let the puppet to decide if they need to create a tag before using it.

Any suggestions?

@su-chang
Copy link
Member Author

su-chang commented Jan 8, 2020

I'd love to the Lazy Operation, and delete() is great for Tag system.

Do we need a method which named modify()?

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.

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.

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.

@huan huan merged commit ea604bf into wechaty:master Jan 16, 2020
@huan
Copy link
Member

huan commented Jan 16, 2020

The Tag class will be available from Wechaty v0.29.41 or later.

@huan huan mentioned this pull request Jan 16, 2020
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.

4 participants