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

revise room.say() mention function #1729

Merged
merged 6 commits into from
Mar 30, 2019
Merged

revise room.say() mention function #1729

merged 6 commits into from
Mar 30, 2019

Conversation

windmemory
Copy link
Member

I'm submitting a...

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

Refer to #1718

This PR involves a BREAKING CHANGE

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.

Please also add a unit test for the new Tagged Template modification.

And also please add a description of your BREAKING CHANGE with your PR, so that we could put it into the CHANGELOG later.

@windmemory
Copy link
Member Author

windmemory commented Mar 29, 2019

BREAKING CHANGE:

room.say() function no longer accept arguments like below:

room.say(text: string, mention: Contact[])

Alternative solution

To mention multiple contacts when sending out text messages, there are two new ways of doing that:

room.say(text: string, ...mentionList: Contact[])

Sample code:

// Assume you got there Contact instance
// contactA assume the name is Alex
// contactB assume the name is Bob
// contactC assume the name is Carson
await room.say('let\'s party', contactA, contactB, contactC)

Send out text will be

@Alex @Bob @Carson let's party

Tagged Template

Sample code:

// Assume you got there Contact instance
// contactA assume the name is Alex
// contactB assume the name is Bob
// contactC assume the name is Carson
room.say`Hello ${contactA} and ${contactB}, this is ${contactC}`

Send out text will be

Hello @Alex and @Bob, this is @Carson

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.

Good job for adding the unit tests.

Please:

  1. Bump the minor version in package.json file, and add the BREAKING CHANGES to README(in HISTORY section, with the new VERSION).
  2. Follow my latest comments before we merge this PR.

@@ -23,7 +23,7 @@
import test from 'blue-tape'
import sinon from 'sinon'

import { RoomPayload } from 'wechaty-puppet'
import { ContactPayload, RoomMemberPayload, RoomPayload } from 'wechaty-puppet'
Copy link
Member

Choose a reason for hiding this comment

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

import { 
  ContactPayload,
  RoomMemberPayload,
  RoomPayload,
}                            from 'wechaty-puppet'

await room.say('hey buddies, let\'s party', contact1, contact2)
await room.say('')

t.deepEqual(callback.getCall(0).args, [
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 subtests for each room.say test.

i.e.

test('say()', async t => {
  // tear up...
  test('say() with param1', async t => {
    // do say() test 1
  })
  test('say() with param2', async t => {
    // do say() test 2
  })
  // other subtests ...
})

/**
* 4. Link Message
*/
await this.puppet.messageSendUrl({
contactId : this.id
}, textOrContactOrFileOrUrl.payload)
}, textOrListOrContactOrFileOrUrl.payload)
} else if (textOrListOrContactOrFileOrUrl instanceof Array) {
Copy link
Member

@huan huan Mar 30, 2019

Choose a reason for hiding this comment

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

Please add a new private function for the following codes for sayTemplateStringsArray().

    } else if (textOrListOrContactOrFileOrUrl instanceof Array) {
      return sayTemplateStringsArray(
        textOrListOrContactOrFileOrUrl, 
        ...mentionList,
      )
    }

@windmemory
Copy link
Member Author

@huan Done.

@huan huan merged commit 382cedf into wechaty:master Mar 30, 2019
@huan
Copy link
Member

huan commented Mar 30, 2019

Thanks for your great PR!

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.

2 participants