Bladeren bron

[core] Code style & comments update

Karlatemp 3 jaren geleden
bovenliggende
commit
b8321870aa

+ 1 - 1
mirai-core/src/commonMain/kotlin/contact/roaming/RoamingMessagesImplGroup.kt

@@ -62,7 +62,7 @@ internal class RoamingMessagesImplGroup(
                     resp.msgElem.asSequence()
                         .filter { lastOfferedSeq == -1 || it.msgHead.msgSeq < lastOfferedSeq }
                         .filter { it.time in timeStart..timeEnd }
-                        .sortedByDescending { it.msgHead.msgSeq } // Ensure caller receiver newer messages first
+                        .sortedByDescending { it.msgHead.msgSeq } // Ensure caller receives newer messages first
                         .filter { filter.apply(it) } // Call filter after sort
                         .asFlow()
                         .map { listOf(it).toMessageChainOnline(bot, contact.id, MessageSourceKind.GROUP) }

+ 4 - 5
mirai-core/src/commonMain/kotlin/message/protocol/impl/GeneralMessageSenderProtocol.kt

@@ -71,6 +71,7 @@ internal class GeneralMessageSenderProtocol : MessageProtocol(PRIORITY_GENERAL_S
                 fragmented = step == SendMessageStep.FRAGMENTED || currentMessageChain.contains(ForceAsFragmentedMessage)
             ) { source = it }
 
+            // Patch time to be actual server time
             var finalTime = bot.clock.server.currentTimeSeconds().toInt()
             val sendPacketOk = sendAllPackets(bot, step, contact, packets) { idx, rsp ->
                 if (rsp is MessageSvcPbSendMsg.Response.SUCCESS) {
@@ -102,8 +103,7 @@ internal class GeneralMessageSenderProtocol : MessageProtocol(PRIORITY_GENERAL_S
             packets.forEachIndexed { index, packet ->
                 if (!sendSinglePacket(
                         bot, packet, step, contact,
-                        index, packetResponseConsumer
-                    )
+                    ) { packetResponseConsumer(index, it) }
                 ) return@sendAllPackets false
             }
 
@@ -115,15 +115,14 @@ internal class GeneralMessageSenderProtocol : MessageProtocol(PRIORITY_GENERAL_S
             packet: OutgoingPacket,
             step: SendMessageStep,
             contact: Contact,
-            index: Int,
-            packetResponseConsumer: (Int, MessageSvcPbSendMsg.Response) -> Unit,
+            packetResponseConsumer: (MessageSvcPbSendMsg.Response) -> Unit,
         ): Boolean {
             val originalMessage = attributes[ORIGINAL_MESSAGE]
             val protocolStrategy = components[MessageProtocolStrategy]
             val finalMessage = currentMessageChain
 
             val resp = protocolStrategy.sendPacket(bot, packet) as MessageSvcPbSendMsg.Response
-            packetResponseConsumer(index, resp)
+            packetResponseConsumer(resp)
             if (resp is MessageSvcPbSendMsg.Response.MessageTooLarge) {
                 logger.info { "STEP $step: message too large." }
                 val next = step.nextStepOrNull()

+ 4 - 6
mirai-core/src/commonMain/kotlin/message/protocol/impl/QuoteReplyProtocol.kt

@@ -157,22 +157,20 @@ internal class QuoteReplyProtocol : MessageProtocol(PRIORITY_METADATA) {
             markAsConsumed()
             collect(ImMsgBody.Elem(srcMsg = source.toJceData()))
             if (sourceCommon.kind == MessageSourceKind.GROUP) {
-
-                @Suppress("RemoveExplicitTypeArguments")
-                val needPlusAt = sequence<Boolean> {
+                fun isPlusNeed(): Boolean {
                     if (source is OnlineMessageSource.Incoming.FromGroup) {
                         try {
                             val sender0 = source.sender
-                            yield(sender0 !is AnonymousMember)
+                            return sender0 !is AnonymousMember
                         } catch (_: IllegalStateException) {
                             // Member not available now
                         }
                     }
 
-                    yield(sourceCommon.fromId != 80000000L)
+                    return sourceCommon.fromId != 80000000L // #2501
                 }
 
-                if (needPlusAt.first()) {
+                if (isPlusNeed()) {
                     processAlso(At(sourceCommon.fromId))
 
                     // transformOneMessage(PlainText(" "))