Commit d9692c3b authored by ryoii's avatar ryoii

ignore IgnoreEventDTO from fetch list

parent 47601918
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
package net.mamoe.mirai.api.http.queue 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.event.events.BotEvent
import net.mamoe.mirai.message.GroupMessage import net.mamoe.mirai.message.GroupMessage
import net.mamoe.mirai.message.data.MessageSource import net.mamoe.mirai.message.data.MessageSource
...@@ -19,16 +22,22 @@ class MessageQueue : ConcurrentLinkedDeque<BotEvent>() { ...@@ -19,16 +22,22 @@ class MessageQueue : ConcurrentLinkedDeque<BotEvent>() {
val quoteCache = ConcurrentHashMap<Long, GroupMessage>() val quoteCache = ConcurrentHashMap<Long, GroupMessage>()
fun fetch(size: Int): List<BotEvent> { fun fetch(size: Int): List<EventDTO> {
var count = size var count = size
quoteCache.clear() quoteCache.clear()
val ret = ArrayList<BotEvent>(count) val ret = ArrayList<EventDTO>(count)
while (!this.isEmpty() && count-- > 0) { while (!this.isEmpty() && count > 0) {
val packet = pop() val event = pop()
ret.add(packet)
if (packet is GroupMessage) { event.toDTO().also {
addCache(packet) if (it != IgnoreEventDTO) {
ret.add(it)
count--
}
}
if (event is GroupMessage) {
addCache(event)
} }
} }
return ret return ret
......
...@@ -37,9 +37,8 @@ fun Application.messageModule() { ...@@ -37,9 +37,8 @@ fun Application.messageModule() {
miraiGet("/fetchMessage") { miraiGet("/fetchMessage") {
val count: Int = paramOrNull("count") val count: Int = paramOrNull("count")
val fetch = it.messageQueue.fetch(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") { 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