@@ -13,6 +13,7 @@ import io.github.wechaty.filebox.FileBox
1313import io.github.wechaty.schemas.RoomMemberQueryFilter
1414import io.github.wechaty.schemas.RoomPayload
1515import io.github.wechaty.type.Sayable
16+ import io.github.wechaty.utils.QrcodeUtils
1617import org.apache.commons.collections4.CollectionUtils
1718import org.apache.commons.lang3.StringUtils
1819import org.slf4j.LoggerFactory
@@ -31,6 +32,10 @@ class Room(wechaty: Wechaty, val id: String) : Accessory(wechaty), Sayable {
3132 return ready(true )
3233 }
3334
35+ fun isReady (): Boolean {
36+ return this .payload != null
37+ }
38+
3439 override fun say (something : Any , contact : Contact ): Future <Any > {
3540
3641 var msgId: String? = null
@@ -75,8 +80,7 @@ class Room(wechaty: Wechaty, val id: String) : Accessory(wechaty), Sayable {
7580 }
7681 mentionList = varList.toList()
7782
78- val mentionAlias = mentionList.map {
79- contact ->
83+ val mentionAlias = mentionList.map { contact ->
8084 val alias = alias(contact as Contact )
8185 val concatText = if (StringUtils .isNotBlank(alias)) {
8286 alias!!
@@ -213,6 +217,66 @@ class Room(wechaty: Wechaty, val id: String) : Accessory(wechaty), Sayable {
213217 }
214218 }
215219
220+ fun topic (newTopic : String? ): Future <Any > {
221+ if (! isReady()) {
222+ log.warn(" Room topic() room not ready" )
223+ throw Exception (" not ready" )
224+ }
225+
226+ if (newTopic == null ) {
227+ if (payload != null && payload!! .topic != null ) {
228+ return CompletableFuture .supplyAsync {
229+ return @supplyAsync payload!! .topic
230+ }
231+ } else {
232+ val memberIdList = puppet.roomMemberList(id).get()
233+ val memberList = memberIdList.filter { it != puppet.selfId() }
234+ .map { wechaty.contactManager.load(it) }
235+
236+ var defaultTopic = " "
237+ if (memberList.isNotEmpty()) {
238+ defaultTopic = memberList[0 ].name()
239+ }
240+
241+ if (memberList.size >= 2 ) {
242+ for (index in 1 .. 2 ) {
243+ defaultTopic + = " ,${memberList[index].name()} "
244+ }
245+ }
246+ return CompletableFuture .supplyAsync {
247+ return @supplyAsync defaultTopic
248+ }
249+ }
250+ }
251+
252+ return CompletableFuture .supplyAsync {
253+ try {
254+ return @supplyAsync puppet.roomTopic(id, newTopic).get()
255+ } catch (e: Exception ) {
256+ log.warn(" Room topic(newTopic=$newTopic ) exception:$e " )
257+ throw Exception (e)
258+ }
259+ }
260+
261+ }
262+
263+ fun announce (text : String? ): Future <Any > {
264+ return CompletableFuture .supplyAsync {
265+ if (text == null ) {
266+ return @supplyAsync puppet.getRoomAnnounce(id).get()
267+ } else {
268+ return @supplyAsync puppet.setRoomAnnounce(id, text)
269+ }
270+ }
271+ }
272+
273+ fun qrCode (): Future <String > {
274+ return CompletableFuture .supplyAsync {
275+ val qrCodeValue = puppet.roomQRCode(id).get()
276+ return @supplyAsync QrcodeUtils .guardQrCodeValue(qrCodeValue)
277+ }
278+ }
279+
216280 fun memberAll (query : RoomMemberQueryFilter ? ): List <Contact > {
217281
218282 if (query == null ) {
0 commit comments