-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Conversation
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.
Please think deep and read my reviews carefully.
src/user/room.ts
Outdated
@@ -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 || []) |
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.
use [...mention]
should be better.
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.
but the replyToList is original code, and what if mention is undefine?
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.
[...(undefined||[])]
src/user/room.ts
Outdated
|
||
const replyToList: Contact[] = [].concat(mention as any || []) | ||
|
||
const mentionAliasPromiseList = replyToList.length > 0 |
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 believe replyToList.length > 0
is not necessary at here.
Rename mentionAliasPromiseList
to mentionAliasList
because it's not a promise.
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.
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
src/user/room.ts
Outdated
: mention ? mention.name() : '', | ||
) | ||
let text: string | ||
mentionAliasList.length > 1 |
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.
mentionAliasList.length > 1
is not necessary at here.
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.
Please follow my review and change those line as required.
I'll merge this PR after that, thanks!
@@ -428,23 +428,31 @@ export class Room extends Accessory implements Sayable { | |||
textOrContactOrFileOrUrl : string | Contact | FileBox | UrlLink, | |||
mention? : Contact | Contact[], | |||
): Promise<void> { | |||
|
|||
const replyToList: Contact[] = Array.isArray(mention) |
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.
Change this line to:
const replyToList: Contact[] = [...(mention || [])]
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.
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.
Yes, you are right.
Then could we use [].concat(mention || [])
instead? Because I want to here be as simple as possible.
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.
? [...mention] | ||
: mention ? [mention] : [] | ||
|
||
const mentionAliasPromiseList = await Promise.all( |
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.
Rename mentionAliasPromiseList
to mentionAliasList
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.
since below discussion, we should give a better name since that is await.
However, mentionAliasList
contain string | null
base on Promise.all()
fail will return null
.
Therefore, I suggest name should be mentionAliasListResult
or mentionAliasListPromiseResult
, but the second one name may be too long..
replyToList | ||
.map(c => this.alias(c) || c.name())) | ||
|
||
const mentionAliasList: string[] = mentionAliasPromiseList |
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.
This line can be removed because the array should not include the null anymore after the above code this.alias(c) || c.name()
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.
but it is possible promise fail and got null value for c.name()
, isn't it?
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.
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.
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.
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.
ok.
This is a PR continue with #1605 with clean commit
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?