Skip to content

Commit 73dcc44

Browse files
committed
Merge remote-tracking branch 'origin/feature/20200518-renxiaoya' into feature/20200518-renxiaoya
2 parents a4d0836 + 5a64a9c commit 73dcc44

File tree

1 file changed

+25
-4
lines changed
  • wechaty/src/main/kotlin/io/github/wechaty/user

1 file changed

+25
-4
lines changed

wechaty/src/main/kotlin/io/github/wechaty/user/Room.kt

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import java.util.*
2020
import java.util.concurrent.CompletableFuture
2121
import java.util.concurrent.Future
2222

23+
const val FOUR_PER_EM_SPACE = "\u2005"
24+
2325
class Room(wechaty: Wechaty, val id: String) : Accessory(wechaty), Sayable {
2426

2527
private val puppet: Puppet = wechaty.getPuppet()
@@ -54,9 +56,10 @@ class Room(wechaty: Wechaty, val id: String) : Accessory(wechaty), Sayable {
5456
}
5557
}
5658

57-
fun say(something: Any, vararg varList: List<Any>): Future<Any> {
59+
fun say(something: Any, vararg varList: Any): Future<Any> {
5860

5961
var msgId: String?
62+
var text: String
6063

6164
return CompletableFuture.supplyAsync {
6265
when (something) {
@@ -70,16 +73,34 @@ class Room(wechaty: Wechaty, val id: String) : Accessory(wechaty), Sayable {
7073
throw Exception("mentionList must be contact when not using String array function call.")
7174
}
7275
}
73-
//todo(varList ? List<List<Any>>)
74-
mentionList = varList[0]
76+
mentionList = varList.toList()
77+
78+
val mentionAlias = mentionList.map {
79+
contact ->
80+
val alias = alias(contact as Contact)
81+
val concatText = if (StringUtils.isNotBlank(alias)) {
82+
alias!!
83+
} else {
84+
contact.name()
85+
}
86+
return@map "@$concatText"
87+
}
88+
val mentionText = mentionAlias.joinToString(separator = FOUR_PER_EM_SPACE)
89+
text = mentionText
90+
} else {
91+
text = something
7592
}
7693

77-
msgId = wechaty.getPuppet().messageSendText(id, something).get()
94+
msgId = wechaty.getPuppet().messageSendText(id, text, mentionList.map { c -> (c as Contact).id }).get()
7895
}
7996
is FileBox -> {
8097
msgId = wechaty.getPuppet().messageSendFile(id, something).get()
8198
}
8299

100+
is Contact -> {
101+
msgId = wechaty.getPuppet().messageSendContact(id, something.id).get()
102+
}
103+
83104
is UrlLink -> {
84105
msgId = wechaty.getPuppet().messageSendUrl(id, something.payload).get()
85106
}

0 commit comments

Comments
 (0)