Commit d9692c3b authored by ryoii's avatar ryoii

ignore IgnoreEventDTO from fetch list

parent 47601918
......@@ -9,6 +9,9 @@
package net.mamoe.mirai.api.http.queue
import net.mamoe.mirai.api.http.data.common.EventDTO
import net.mamoe.mirai.api.http.data.common.IgnoreEventDTO
import net.mamoe.mirai.api.http.data.common.toDTO
import net.mamoe.mirai.event.events.BotEvent
import net.mamoe.mirai.message.GroupMessage
import net.mamoe.mirai.message.data.MessageSource
......@@ -19,16 +22,22 @@ class MessageQueue : ConcurrentLinkedDeque<BotEvent>() {
val quoteCache = ConcurrentHashMap<Long, GroupMessage>()
fun fetch(size: Int): List<BotEvent> {
fun fetch(size: Int): List<EventDTO> {
var count = size
quoteCache.clear()
val ret = ArrayList<BotEvent>(count)
while (!this.isEmpty() && count-- > 0) {
val packet = pop()
ret.add(packet)
val ret = ArrayList<EventDTO>(count)
while (!this.isEmpty() && count > 0) {
val event = pop()
if (packet is GroupMessage) {
addCache(packet)
event.toDTO().also {
if (it != IgnoreEventDTO) {
ret.add(it)
count--
}
}
if (event is GroupMessage) {
addCache(event)
}
}
return ret
......
......@@ -37,9 +37,8 @@ fun Application.messageModule() {
miraiGet("/fetchMessage") {
val count: Int = paramOrNull("count")
val fetch = it.messageQueue.fetch(count)
val ls = Array(fetch.size) { index -> fetch[index].toDTO() }
call.respondJson(ls.toList().toJson())
call.respondJson(fetch.toJson())
}
miraiVerify<SendDTO>("/sendFriendMessage") {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment