Skip to content

Commit 7d4b1c2

Browse files
committed
reduce rejections version and fix contactSearch and messageSearch method in Puppet
1 parent ab8fda7 commit 7d4b1c2

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@
168168
<artifactId>javafaker</artifactId>
169169
<version>1.0.2</version>
170170
</dependency>
171+
<dependency>
172+
<groupId>org.reflections</groupId>
173+
<artifactId>reflections</artifactId>
174+
<version>0.9.10</version>
175+
</dependency>
171176

172177
</dependencies>
173178
</dependencyManagement>

wechaty-puppet/src/main/kotlin/Puppet.kt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -426,39 +426,39 @@ abstract class Puppet : EventEmitter {
426426
return@supplyAsync list
427427
}
428428

429-
val stream = list?.stream()?.map { contactPayload(it).get() }
429+
var stream = list?.stream()?.map { contactPayload(it).get() }
430430
if (StringUtils.isNotBlank(query.name)) {
431-
stream?.filter {
431+
stream = stream?.filter {
432432
StringUtils.equals(query.name, it.name)
433433
}
434434
}
435435

436436
if (StringUtils.isNotBlank(query.alias)) {
437-
stream?.filter {
437+
stream = stream?.filter {
438438
StringUtils.equals(query.alias, it.alias)
439439
}
440440
}
441441

442442
if (StringUtils.isNotBlank(query.id)) {
443-
stream?.filter {
443+
stream = stream?.filter {
444444
StringUtils.equals(query.alias, it.alias)
445445
}
446446
}
447447

448448
if (StringUtils.isNotBlank(query.weixin)) {
449-
stream?.filter {
449+
stream = stream?.filter {
450450
StringUtils.equals(query.alias, it.alias)
451451
}
452452
}
453453

454454
if (query.nameReg != null) {
455-
stream?.filter {
455+
stream = stream?.filter {
456456
query.nameReg!!.matches(it.name ?: "")
457457
}
458458
}
459459

460460
if (query.aliasReg != null) {
461-
stream?.filter {
461+
stream = stream?.filter {
462462
query.aliasReg!!.matches(it.alias ?: "")
463463
}
464464
}
@@ -650,46 +650,46 @@ abstract class Puppet : EventEmitter {
650650
messagePayload(it).get()
651651
}
652652

653-
val stream = messagePayloadList.stream()
653+
var stream = messagePayloadList.stream()
654654

655655
if (StringUtils.isNotEmpty(query.fromId)) {
656-
stream.filter {
656+
stream = stream.filter {
657657
StringUtils.equals(it.fromId, query.fromId)
658658
}
659659
}
660660

661661
if (StringUtils.isNotEmpty(query.id)) {
662-
stream.filter {
662+
stream = stream.filter {
663663
StringUtils.equals(it.id, query.id)
664664
}
665665
}
666666

667667
if (StringUtils.isNotEmpty(query.roomId)) {
668-
stream.filter {
668+
stream = stream.filter {
669669
StringUtils.equals(it.roomId, query.roomId)
670670
}
671671
}
672672

673673
if (StringUtils.isNotEmpty(query.toId)) {
674-
stream.filter {
674+
stream = stream.filter {
675675
StringUtils.equals(it.toId, query.toId)
676676
}
677677
}
678678

679679
if (StringUtils.isNotEmpty(query.text)) {
680-
stream.filter {
680+
stream = stream.filter {
681681
StringUtils.equals(it.text, query.text)
682682
}
683683
}
684684

685685
if (query.textReg != null) {
686-
stream.filter {
686+
stream = stream.filter {
687687
query.textReg!!.matches(it.text ?: "")
688688
}
689689
}
690690

691691
if (query.type != null) {
692-
stream.filter {
692+
stream = stream.filter {
693693
query.type == it.type
694694
}
695695
}

wechaty/pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@
110110
<dependency>
111111
<groupId>org.reflections</groupId>
112112
<artifactId>reflections</artifactId>
113-
<version>0.9.12</version>
114113
</dependency>
115-
116114
</dependencies>
117115

118116
<build>

wechaty/src/main/kotlin/io/github/wechaty/user/manager/PuppetManager.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import io.github.wechaty.schemas.PuppetOptions
66
import io.github.wechaty.utils.JsonUtils
77
import org.reflections.Reflections
88
import org.reflections.util.ClasspathHelper
9+
import org.reflections.util.ConfigurationBuilder
910
import org.slf4j.LoggerFactory
1011
import java.util.concurrent.CompletableFuture
1112
import java.util.concurrent.Future
@@ -21,8 +22,12 @@ class PuppetManager {
2122
fun resolveInstance(wechatyOptions: WechatyOptions): Future<Puppet> {
2223
log.info("PuppetManager resolveInstance(${JsonUtils.write(wechatyOptions)})")
2324

24-
val reflections = Reflections(ClasspathHelper.forPackage(REFLECTION_BASE_PACKAGE, Thread.currentThread().contextClassLoader))
25+
val reflections = Reflections(ConfigurationBuilder().setUrls(ClasspathHelper.forPackage(REFLECTION_BASE_PACKAGE, Thread.currentThread().contextClassLoader)))
26+
2527
val subTypes: Set<*> = reflections.getSubTypesOf(Puppet::class.java)
28+
if (subTypes.isEmpty()) {
29+
throw java.lang.RuntimeException("expect one puppet,but can not found any one.")
30+
}
2631

2732
if (subTypes.size > 1) {
2833
throw RuntimeException("expect one puppet,but found ${subTypes.size}")

0 commit comments

Comments
 (0)