Skip to content

Commit

Permalink
fix: room mention contact should using roomAlias #1604 (#1607)
Browse files Browse the repository at this point in the history
* fix: change room say function mention contact roomAlias not name
refer issue: #1604

* change getRoomAlias() to promise.all() and remove getRoomAlias()

* re-deal with null promise array

* 0.23.14

* clean code
  • Loading branch information
kis87988 authored and huan committed Oct 3, 2018
1 parent 1849df5 commit a2b055e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
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
24 changes: 16 additions & 8 deletions src/user/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
? [...mention]
: mention ? [mention] : []

const mentionAliasPromiseList = await Promise.all(
replyToList
.map(c => this.alias(c) || c.name()))

const mentionAliasList: string[] = mentionAliasPromiseList
.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.join(', '))

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

0 comments on commit a2b055e

Please sign in to comment.