mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-05 23:50:08 +08:00
[core] Get group incoming message source raw data directly
This commit is contained in:
parent
fe14600018
commit
ec5870e0b3
@ -4809,9 +4809,9 @@ public abstract class net/mamoe/mirai/message/data/OnlineMessageSource : net/mam
|
||||
|
||||
public abstract class net/mamoe/mirai/message/data/OnlineMessageSource$Incoming : net/mamoe/mirai/message/data/OnlineMessageSource {
|
||||
public static final field Key Lnet/mamoe/mirai/message/data/OnlineMessageSource$Incoming$Key;
|
||||
public final fun getFromId ()J
|
||||
public fun getFromId ()J
|
||||
public abstract fun getSender ()Lnet/mamoe/mirai/contact/User;
|
||||
public final fun getTargetId ()J
|
||||
public fun getTargetId ()J
|
||||
}
|
||||
|
||||
public abstract class net/mamoe/mirai/message/data/OnlineMessageSource$Incoming$FromFriend : net/mamoe/mirai/message/data/OnlineMessageSource$Incoming {
|
||||
|
@ -4809,9 +4809,9 @@ public abstract class net/mamoe/mirai/message/data/OnlineMessageSource : net/mam
|
||||
|
||||
public abstract class net/mamoe/mirai/message/data/OnlineMessageSource$Incoming : net/mamoe/mirai/message/data/OnlineMessageSource {
|
||||
public static final field Key Lnet/mamoe/mirai/message/data/OnlineMessageSource$Incoming$Key;
|
||||
public final fun getFromId ()J
|
||||
public fun getFromId ()J
|
||||
public abstract fun getSender ()Lnet/mamoe/mirai/contact/User;
|
||||
public final fun getTargetId ()J
|
||||
public fun getTargetId ()J
|
||||
}
|
||||
|
||||
public abstract class net/mamoe/mirai/message/data/OnlineMessageSource$Incoming$FromFriend : net/mamoe/mirai/message/data/OnlineMessageSource$Incoming {
|
||||
|
@ -151,8 +151,9 @@ public sealed class OnlineMessageSource : MessageSource() {
|
||||
public sealed class Incoming : OnlineMessageSource() {
|
||||
public abstract override val sender: User
|
||||
|
||||
public final override val fromId: Long get() = sender.id
|
||||
public final override val targetId: Long get() = target.id
|
||||
/// NOTE: DONT use final to avoid contact not available
|
||||
public override val fromId: Long get() = sender.id
|
||||
public override val targetId: Long get() = target.id
|
||||
|
||||
@NotStableForInheritance
|
||||
public abstract class FromFriend @MiraiInternalApi constructor() : Incoming() {
|
||||
|
@ -206,7 +206,7 @@ internal class OnlineMessageSourceFromTempImpl(
|
||||
@Serializable(OnlineMessageSourceFromGroupImpl.Serializer::class)
|
||||
internal class OnlineMessageSourceFromGroupImpl(
|
||||
override val bot: Bot,
|
||||
msg: List<MsgComm.Msg>,
|
||||
private val msg: List<MsgComm.Msg>,
|
||||
) : OnlineMessageSource.Incoming.FromGroup(), IncomingMessageSourceInternal {
|
||||
object Serializer : KSerializer<MessageSource> by MessageSourceSerializerImpl("OnlineMessageSourceFromGroupImpl")
|
||||
|
||||
@ -229,11 +229,8 @@ internal class OnlineMessageSourceFromGroupImpl(
|
||||
|
||||
|
||||
override val subject: GroupImpl by lazy {
|
||||
val groupCode = msg.first().msgHead.groupInfo?.groupCode
|
||||
?: error("cannot find groupCode for OnlineMessageSourceFromGroupImpl. msg=${msg.structureToString()}")
|
||||
|
||||
val group = bot.getGroup(groupCode)?.checkIsGroupImpl()
|
||||
?: error("cannot find group for OnlineMessageSourceFromGroupImpl. msg=${msg.structureToString()}")
|
||||
val group = bot.getGroup(targetId)?.checkIsGroupImpl()
|
||||
?: error("cannot find group for OnlineMessageSourceFromGroupImpl. Use `source.targetId` to get group id. msg=${msg.structureToString()}")
|
||||
|
||||
group
|
||||
}
|
||||
@ -245,13 +242,20 @@ internal class OnlineMessageSourceFromGroupImpl(
|
||||
if (member != null) return@lazy member
|
||||
|
||||
val anonymousInfo = msg.first().msgBody.richText.elems.firstOrNull { it.anonGroupMsg != null }
|
||||
?: error("cannot find member for OnlineMessageSourceFromGroupImpl. msg=${msg.structureToString()}")
|
||||
?: error("cannot find member for OnlineMessageSourceFromGroupImpl. Use `source.fromId` to get sender id. msg=${msg.structureToString()}")
|
||||
|
||||
anonymousInfo.run {
|
||||
group.newAnonymous(anonGroupMsg!!.anonNick.decodeToString(), anonGroupMsg.anonId.encodeBase64())
|
||||
}
|
||||
}
|
||||
|
||||
override val fromId: Long get() = msg.first().msgHead.fromUin
|
||||
override val targetId: Long
|
||||
get() {
|
||||
return msg.first().msgHead.groupInfo?.groupCode
|
||||
?: error("cannot find groupCode for OnlineMessageSourceFromGroupImpl. msg=${msg.structureToString()}")
|
||||
}
|
||||
|
||||
private val jceData: ImMsgBody.SourceMsg by lazy {
|
||||
ImMsgBody.SourceMsg(
|
||||
origSeqs = intArrayOf(msg.first().msgHead.msgSeq),
|
||||
|
Loading…
Reference in New Issue
Block a user