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

fix: room mention contact should using roomAlias https://github.com/Chatie/wechaty/issues/1604 #1607

Merged
merged 5 commits into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wechaty",
"version": "0.23.13",
"version": "0.23.14",
"description": "Wechaty is a Bot SDK for Wechat Personal Account",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
Expand Down
26 changes: 18 additions & 8 deletions src/user/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,23 +428,33 @@ export class Room extends Accessory implements Sayable {
textOrContactOrFileOrUrl : string | Contact | FileBox | UrlLink,
mention? : Contact | Contact[],
): Promise<void> {

const replyToList: Contact[] = [].concat(mention as any || [])
Copy link
Member

Choose a reason for hiding this comment

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

use [...mention] should be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but the replyToList is original code, and what if mention is undefine?

Copy link
Member

Choose a reason for hiding this comment

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

[...(undefined||[])]


const mentionAliasPromiseList = replyToList.length > 0
Copy link
Member

Choose a reason for hiding this comment

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

I believe replyToList.length > 0 is not necessary at here.

Rename mentionAliasPromiseList to mentionAliasList because it's not a promise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mentionAliasPromiseList may contain string | null, mentionAliasList should only contain string. Therefore, I think the line 440 is the one being filter.
However, you are right. I should give a good name for the one contain string | null

? await Promise.all(
replyToList
.map(c => this.alias(c) || c.name()))
: []

const mentionAliasList: string[] = mentionAliasPromiseList
Copy link
Member

@huan huan Oct 2, 2018

Choose a reason for hiding this comment

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

This line can be removed because the array should not include the null anymore after the above code this.alias(c) || c.name()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but it is possible promise fail and got null value for c.name(), isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before rename:
image

Copy link
Member

Choose a reason for hiding this comment

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

c.name() will always return a string, so it should never be a null.

However, you can keep this code and I'll have a look after we merged it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok.

.filter(a => a !== null) as string[]

log.verbose('Room', 'say(%s, %s)',
textOrContactOrFileOrUrl,
Array.isArray(mention)
? mention.map(c => c.name()).join(', ')
: mention ? mention.name() : '',
)
let text: string
mentionAliasList.length > 1
Copy link
Member

Choose a reason for hiding this comment

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

mentionAliasList.length > 1 is not necessary at here.

? mentionAliasList.join(', ')
: mentionAliasList.length === 1 ? mentionAliasList[0] : '')

const replyToList: Contact[] = [].concat(mention as any || [])
let text: string

if (typeof textOrContactOrFileOrUrl === 'string') {

if (replyToList.length > 0) {
if (mentionAliasList.length > 0) {
// const AT_SEPRATOR = String.fromCharCode(8197)
const AT_SEPRATOR = FOUR_PER_EM_SPACE
const mentionList = replyToList.map(roomAlias => '@' + roomAlias).join(AT_SEPRATOR)

const mentionList = replyToList.map(c => '@' + c.name()).join(AT_SEPRATOR)
text = mentionList + ' ' + textOrContactOrFileOrUrl
} else {
text = textOrContactOrFileOrUrl
Expand Down