mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-09 18:00:33 +08:00
Make MessageSource.messageUid
int
This commit is contained in:
parent
0e30d3d69b
commit
0015b7bcc1
@ -98,7 +98,7 @@ fun MessageChainDTO.toMessageChain(contact: Contact) =
|
|||||||
|
|
||||||
@UseExperimental(ExperimentalUnsignedTypes::class)
|
@UseExperimental(ExperimentalUnsignedTypes::class)
|
||||||
fun Message.toDTO() = when (this) {
|
fun Message.toDTO() = when (this) {
|
||||||
is MessageSource -> MessageSourceDTO(messageUid)
|
is MessageSource -> MessageSourceDTO(messageUid.toLong() and 0xFFffFFff)
|
||||||
is At -> AtDTO(target, display)
|
is At -> AtDTO(target, display)
|
||||||
is AtAll -> AtAllDTO(0L)
|
is AtAll -> AtAllDTO(0L)
|
||||||
is Face -> FaceDTO(id)
|
is Face -> FaceDTO(id)
|
||||||
|
@ -44,6 +44,6 @@ class MessageQueue : ConcurrentLinkedDeque<BotEvent>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun addCache(msg: GroupMessage) {
|
private fun addCache(msg: GroupMessage) {
|
||||||
quoteCache[msg.message[MessageSource].messageUid] = msg
|
quoteCache[msg.message[MessageSource].messageUid.toLong() and 0xFFffFFff] = msg
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -70,16 +70,17 @@ internal class QQImpl(
|
|||||||
if (event.isCancelled) {
|
if (event.isCancelled) {
|
||||||
throw EventCancelledException("cancelled by FriendMessageSendEvent")
|
throw EventCancelledException("cancelled by FriendMessageSendEvent")
|
||||||
}
|
}
|
||||||
|
lateinit var source: MessageSource
|
||||||
bot.network.run {
|
bot.network.run {
|
||||||
check(
|
check(
|
||||||
MessageSvc.PbSendMsg.ToFriend(
|
MessageSvc.PbSendMsg.ToFriend(
|
||||||
bot.client,
|
bot.client,
|
||||||
id,
|
id,
|
||||||
event.message
|
event.message
|
||||||
).sendAndExpect<MessageSvc.PbSendMsg.Response>() is MessageSvc.PbSendMsg.Response.SUCCESS
|
) { source = it }.sendAndExpect<MessageSvc.PbSendMsg.Response>() is MessageSvc.PbSendMsg.Response.SUCCESS
|
||||||
) { "send message failed" }
|
) { "send message failed" }
|
||||||
}
|
}
|
||||||
return MessageReceipt(message, this)
|
return MessageReceipt(message, source, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun uploadImage(image: ExternalImage): Image = try {
|
override suspend fun uploadImage(image: ExternalImage): Image = try {
|
||||||
@ -552,12 +553,13 @@ internal class GroupImpl(
|
|||||||
if (event.isCancelled) {
|
if (event.isCancelled) {
|
||||||
throw EventCancelledException("cancelled by FriendMessageSendEvent")
|
throw EventCancelledException("cancelled by FriendMessageSendEvent")
|
||||||
}
|
}
|
||||||
|
lateinit var source: MessageSource
|
||||||
bot.network.run {
|
bot.network.run {
|
||||||
val response = MessageSvc.PbSendMsg.ToGroup(
|
val response: MessageSvc.PbSendMsg.Response = MessageSvc.PbSendMsg.ToGroup(
|
||||||
bot.client,
|
bot.client,
|
||||||
id,
|
id,
|
||||||
event.message
|
event.message
|
||||||
).sendAndExpect<MessageSvc.PbSendMsg.Response>()
|
) { source = it }.sendAndExpect()
|
||||||
check(
|
check(
|
||||||
response is MessageSvc.PbSendMsg.Response.SUCCESS
|
response is MessageSvc.PbSendMsg.Response.SUCCESS
|
||||||
) { "send message failed: $response" }
|
) { "send message failed: $response" }
|
||||||
@ -566,7 +568,7 @@ internal class GroupImpl(
|
|||||||
((message.last() as MessageSource) as MessageSvc.PbSendMsg.MessageSourceFromSend)
|
((message.last() as MessageSource) as MessageSvc.PbSendMsg.MessageSourceFromSend)
|
||||||
.startWaitingSequenceId(this)
|
.startWaitingSequenceId(this)
|
||||||
|
|
||||||
return MessageReceipt(message, this)
|
return MessageReceipt(message, source, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun uploadImage(image: ExternalImage): Image = try {
|
override suspend fun uploadImage(image: ExternalImage): Image = try {
|
||||||
|
@ -27,7 +27,7 @@ internal inline class MessageSourceFromServer(
|
|||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
override val messageUid: Long get() = delegate.pbReserve.loadAs(SourceMsg.ResvAttr.serializer()).origUids!!
|
override val messageUid: Int get() = delegate.pbReserve.loadAs(SourceMsg.ResvAttr.serializer()).origUids!!.toInt()
|
||||||
// override val sourceMessage: MessageChain get() = delegate.toMessageChain()
|
// override val sourceMessage: MessageChain get() = delegate.toMessageChain()
|
||||||
override val senderId: Long get() = delegate.senderUin
|
override val senderId: Long get() = delegate.senderUin
|
||||||
override val groupId: Long get() = Group.calculateGroupCodeByGroupUin(delegate.toUin)
|
override val groupId: Long get() = Group.calculateGroupCodeByGroupUin(delegate.toUin)
|
||||||
@ -44,7 +44,7 @@ internal inline class MessageSourceFromMsg(
|
|||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
override val messageUid: Long get() = delegate.msgBody.richText.attr!!.random.toLong()
|
override val messageUid: Int get() = delegate.msgBody.richText.attr!!.random
|
||||||
// override val sourceMessage: MessageChain get() = delegate.toMessageChain()
|
// override val sourceMessage: MessageChain get() = delegate.toMessageChain()
|
||||||
override val senderId: Long get() = delegate.msgHead.fromUin
|
override val senderId: Long get() = delegate.msgHead.fromUin
|
||||||
override val groupId: Long get() = delegate.msgHead.groupInfo!!.groupCode
|
override val groupId: Long get() = delegate.msgHead.groupInfo!!.groupCode
|
||||||
@ -62,7 +62,7 @@ internal inline class MessageSourceFromMsg(
|
|||||||
type = 0,
|
type = 0,
|
||||||
time = delegate.msgHead.msgTime,
|
time = delegate.msgHead.msgTime,
|
||||||
pbReserve = SourceMsg.ResvAttr(
|
pbReserve = SourceMsg.ResvAttr(
|
||||||
origUids = messageUid
|
origUids = messageUid.toLong() and 0xffFFffFF
|
||||||
).toByteArray(SourceMsg.ResvAttr.serializer()),
|
).toByteArray(SourceMsg.ResvAttr.serializer()),
|
||||||
srcMsg = MsgComm.Msg(
|
srcMsg = MsgComm.Msg(
|
||||||
msgHead = MsgComm.MsgHead(
|
msgHead = MsgComm.MsgHead(
|
||||||
@ -72,7 +72,8 @@ internal inline class MessageSourceFromMsg(
|
|||||||
c2cCmd = delegate.msgHead.c2cCmd,
|
c2cCmd = delegate.msgHead.c2cCmd,
|
||||||
msgSeq = delegate.msgHead.msgSeq,
|
msgSeq = delegate.msgHead.msgSeq,
|
||||||
msgTime = delegate.msgHead.msgTime,
|
msgTime = delegate.msgHead.msgTime,
|
||||||
msgUid = messageUid, // ok
|
msgUid = messageUid.toLong() and 0xffFFffFF
|
||||||
|
, // ok
|
||||||
groupInfo = MsgComm.GroupInfo(groupCode = delegate.msgHead.groupInfo.groupCode),
|
groupInfo = MsgComm.GroupInfo(groupCode = delegate.msgHead.groupInfo.groupCode),
|
||||||
isSrcMsg = true
|
isSrcMsg = true
|
||||||
),
|
),
|
||||||
|
@ -26,7 +26,7 @@ internal class MsgSvc : ProtoBuf {
|
|||||||
internal class PbGetMsgResp(
|
internal class PbGetMsgResp(
|
||||||
@SerialId(1) val result: Int = 0,
|
@SerialId(1) val result: Int = 0,
|
||||||
@SerialId(2) val errmsg: String = "",
|
@SerialId(2) val errmsg: String = "",
|
||||||
@SerialId(3) val syncCookie: ByteArray = EMPTY_BYTE_ARRAY,
|
@SerialId(3) val syncCookie: ByteArray? = EMPTY_BYTE_ARRAY,
|
||||||
@SerialId(4) val syncFlag: SyncFlag,
|
@SerialId(4) val syncFlag: SyncFlag,
|
||||||
@SerialId(5) val uinPairMsgs: List<MsgComm.UinPairMsg>? = null,
|
@SerialId(5) val uinPairMsgs: List<MsgComm.UinPairMsg>? = null,
|
||||||
@SerialId(6) val bindUin: Long = 0L,
|
@SerialId(6) val bindUin: Long = 0L,
|
||||||
|
@ -272,7 +272,7 @@ internal class MessageSvc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal class MessageSourceFromSend(
|
internal class MessageSourceFromSend(
|
||||||
override val messageUid: Long,
|
override val messageUid: Int,
|
||||||
override val time: Long,
|
override val time: Long,
|
||||||
override val senderId: Long,
|
override val senderId: Long,
|
||||||
override val groupId: Long// ,
|
override val groupId: Long// ,
|
||||||
@ -283,7 +283,7 @@ internal class MessageSvc {
|
|||||||
@UseExperimental(MiraiExperimentalAPI::class)
|
@UseExperimental(MiraiExperimentalAPI::class)
|
||||||
fun startWaitingSequenceId(contact: Contact) {
|
fun startWaitingSequenceId(contact: Contact) {
|
||||||
sequenceIdDeferred = contact.subscribingGetAsync<OnlinePush.PbPushGroupMsg.SendGroupMessageReceipt, Int> {
|
sequenceIdDeferred = contact.subscribingGetAsync<OnlinePush.PbPushGroupMsg.SendGroupMessageReceipt, Int> {
|
||||||
if (it.messageRandom == messageUid.toInt()) {
|
if (it.messageRandom == messageUid) {
|
||||||
it.sequenceId
|
it.sequenceId
|
||||||
} else null
|
} else null
|
||||||
}
|
}
|
||||||
@ -302,25 +302,34 @@ internal class MessageSvc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
inline fun ToFriend(
|
||||||
* 发送好友消息
|
|
||||||
*/
|
|
||||||
@Suppress("FunctionName")
|
|
||||||
fun ToFriend(
|
|
||||||
client: QQAndroidClient,
|
client: QQAndroidClient,
|
||||||
toUin: Long,
|
toUin: Long,
|
||||||
message: MessageChain
|
message: MessageChain,
|
||||||
): OutgoingPacket = buildOutgoingUniPacket(client) {
|
crossinline sourceCallback: (MessageSource) -> Unit
|
||||||
///writeFully("0A 08 0A 06 08 89 FC A6 8C 0B 12 06 08 01 10 00 18 00 1A 1F 0A 1D 12 08 0A 06 0A 04 F0 9F 92 A9 12 11 AA 02 0E 88 01 00 9A 01 08 78 00 F8 01 00 C8 02 00 20 9B 7A 28 F4 CA 9B B8 03 32 34 08 92 C2 C4 F1 05 10 92 C2 C4 F1 05 18 E6 ED B9 C3 02 20 89 FE BE A4 06 28 89 84 F9 A2 06 48 DE 8C EA E5 0E 58 D9 BD BB A0 09 60 1D 68 92 C2 C4 F1 05 70 00 40 01".hexToBytes())
|
): OutgoingPacket {
|
||||||
|
|
||||||
val source = MessageSourceFromSend(
|
val source = MessageSourceFromSend(
|
||||||
messageUid = Random.nextInt().absoluteValue.toLong() and 0xffffffff,
|
messageUid = Random.nextInt().absoluteValue,
|
||||||
senderId = client.uin,
|
senderId = client.uin,
|
||||||
time = currentTimeSeconds + client.timeDifference,
|
time = currentTimeSeconds + client.timeDifference,
|
||||||
groupId = 0//
|
groupId = 0//
|
||||||
// sourceMessage = message
|
// sourceMessage = message
|
||||||
)
|
)
|
||||||
message.addOrRemove(source)
|
sourceCallback(source)
|
||||||
|
return ToFriend(client, toUin, message, source)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送好友消息
|
||||||
|
*/
|
||||||
|
@Suppress("FunctionName")
|
||||||
|
private fun ToFriend(
|
||||||
|
client: QQAndroidClient,
|
||||||
|
toUin: Long,
|
||||||
|
message: MessageChain,
|
||||||
|
source: MessageSource
|
||||||
|
): OutgoingPacket = buildOutgoingUniPacket(client) {
|
||||||
|
///writeFully("0A 08 0A 06 08 89 FC A6 8C 0B 12 06 08 01 10 00 18 00 1A 1F 0A 1D 12 08 0A 06 0A 04 F0 9F 92 A9 12 11 AA 02 0E 88 01 00 9A 01 08 78 00 F8 01 00 C8 02 00 20 9B 7A 28 F4 CA 9B B8 03 32 34 08 92 C2 C4 F1 05 10 92 C2 C4 F1 05 18 E6 ED B9 C3 02 20 89 FE BE A4 06 28 89 84 F9 A2 06 48 DE 8C EA E5 0E 58 D9 BD BB A0 09 60 1D 68 92 C2 C4 F1 05 70 00 40 01".hexToBytes())
|
||||||
|
|
||||||
///return@buildOutgoingUniPacket
|
///return@buildOutgoingUniPacket
|
||||||
writeProtoBuf(
|
writeProtoBuf(
|
||||||
@ -333,13 +342,32 @@ internal class MessageSvc {
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
msgSeq = client.atomicNextMessageSequenceId(),
|
msgSeq = client.atomicNextMessageSequenceId(),
|
||||||
msgRand = source.messageUid.toInt(),
|
msgRand = source.messageUid,
|
||||||
syncCookie = SyncCookie(time = source.time).toByteArray(SyncCookie.serializer())
|
syncCookie = SyncCookie(time = source.time).toByteArray(SyncCookie.serializer())
|
||||||
// msgVia = 1
|
// msgVia = 1
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline fun ToGroup(
|
||||||
|
client: QQAndroidClient,
|
||||||
|
groupCode: Long,
|
||||||
|
message: MessageChain,
|
||||||
|
sourceCallback: (MessageSource) -> Unit
|
||||||
|
): OutgoingPacket {
|
||||||
|
|
||||||
|
val source = MessageSourceFromSend(
|
||||||
|
messageUid = Random.nextInt().absoluteValue,
|
||||||
|
senderId = client.uin,
|
||||||
|
time = currentTimeSeconds + client.timeDifference,
|
||||||
|
groupId = groupCode//,
|
||||||
|
// sourceMessage = message
|
||||||
|
)
|
||||||
|
sourceCallback(source)
|
||||||
|
return ToGroup(client, groupCode, message, source)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送群消息
|
* 发送群消息
|
||||||
*/
|
*/
|
||||||
@ -347,17 +375,9 @@ internal class MessageSvc {
|
|||||||
fun ToGroup(
|
fun ToGroup(
|
||||||
client: QQAndroidClient,
|
client: QQAndroidClient,
|
||||||
groupCode: Long,
|
groupCode: Long,
|
||||||
message: MessageChain
|
message: MessageChain,
|
||||||
|
source: MessageSource
|
||||||
): OutgoingPacket = buildOutgoingUniPacket(client) {
|
): OutgoingPacket = buildOutgoingUniPacket(client) {
|
||||||
|
|
||||||
val source = MessageSourceFromSend(
|
|
||||||
messageUid = Random.nextInt().absoluteValue.toLong(),
|
|
||||||
senderId = client.uin,
|
|
||||||
time = currentTimeSeconds + client.timeDifference,
|
|
||||||
groupId = groupCode//,
|
|
||||||
// sourceMessage = message
|
|
||||||
)
|
|
||||||
|
|
||||||
///writeFully("0A 08 0A 06 08 89 FC A6 8C 0B 12 06 08 01 10 00 18 00 1A 1F 0A 1D 12 08 0A 06 0A 04 F0 9F 92 A9 12 11 AA 02 0E 88 01 00 9A 01 08 78 00 F8 01 00 C8 02 00 20 9B 7A 28 F4 CA 9B B8 03 32 34 08 92 C2 C4 F1 05 10 92 C2 C4 F1 05 18 E6 ED B9 C3 02 20 89 FE BE A4 06 28 89 84 F9 A2 06 48 DE 8C EA E5 0E 58 D9 BD BB A0 09 60 1D 68 92 C2 C4 F1 05 70 00 40 01".hexToBytes())
|
///writeFully("0A 08 0A 06 08 89 FC A6 8C 0B 12 06 08 01 10 00 18 00 1A 1F 0A 1D 12 08 0A 06 0A 04 F0 9F 92 A9 12 11 AA 02 0E 88 01 00 9A 01 08 78 00 F8 01 00 C8 02 00 20 9B 7A 28 F4 CA 9B B8 03 32 34 08 92 C2 C4 F1 05 10 92 C2 C4 F1 05 18 E6 ED B9 C3 02 20 89 FE BE A4 06 28 89 84 F9 A2 06 48 DE 8C EA E5 0E 58 D9 BD BB A0 09 60 1D 68 92 C2 C4 F1 05 70 00 40 01".hexToBytes())
|
||||||
|
|
||||||
// DebugLogger.debug("sending group message: " + message.toRichTextElems().contentToString())
|
// DebugLogger.debug("sending group message: " + message.toRichTextElems().contentToString())
|
||||||
@ -373,7 +393,7 @@ internal class MessageSvc {
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
msgSeq = client.atomicNextMessageSequenceId(),
|
msgSeq = client.atomicNextMessageSequenceId(),
|
||||||
msgRand = source.messageUid.toInt(),
|
msgRand = source.messageUid,
|
||||||
syncCookie = EMPTY_BYTE_ARRAY,
|
syncCookie = EMPTY_BYTE_ARRAY,
|
||||||
msgVia = 1
|
msgVia = 1
|
||||||
)
|
)
|
||||||
|
@ -28,6 +28,7 @@ import net.mamoe.mirai.utils.unsafeWeakRef
|
|||||||
*/
|
*/
|
||||||
open class MessageReceipt<C : Contact>(
|
open class MessageReceipt<C : Contact>(
|
||||||
val originalMessage: MessageChain,
|
val originalMessage: MessageChain,
|
||||||
|
private val source: MessageSource,
|
||||||
target: C
|
target: C
|
||||||
) {
|
) {
|
||||||
init {
|
init {
|
||||||
@ -53,7 +54,7 @@ open class MessageReceipt<C : Contact>(
|
|||||||
if (_isRecalled.compareAndSet(false, true)) {
|
if (_isRecalled.compareAndSet(false, true)) {
|
||||||
when (val contact = target) {
|
when (val contact = target) {
|
||||||
is Group -> {
|
is Group -> {
|
||||||
contact.recall(originalMessage)
|
contact.recall(source)
|
||||||
}
|
}
|
||||||
is QQ -> {
|
is QQ -> {
|
||||||
TODO()
|
TODO()
|
||||||
@ -76,7 +77,7 @@ open class MessageReceipt<C : Contact>(
|
|||||||
if (_isRecalled.compareAndSet(false, true)) {
|
if (_isRecalled.compareAndSet(false, true)) {
|
||||||
when (val contact = target) {
|
when (val contact = target) {
|
||||||
is Group -> {
|
is Group -> {
|
||||||
return contact.recallIn(originalMessage, millis)
|
return contact.recallIn(source, millis)
|
||||||
}
|
}
|
||||||
is QQ -> {
|
is QQ -> {
|
||||||
TODO()
|
TODO()
|
||||||
@ -97,7 +98,7 @@ open class MessageReceipt<C : Contact>(
|
|||||||
open fun quote(): MessageChain {
|
open fun quote(): MessageChain {
|
||||||
val target = target
|
val target = target
|
||||||
check(target is Group) { "quote is only available for GroupMessage" }
|
check(target is Group) { "quote is only available for GroupMessage" }
|
||||||
return this.originalMessage.quote(target.botAsMember)
|
return this.source.quote(target.botAsMember)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,7 +41,7 @@ interface MessageSource : Message {
|
|||||||
/**
|
/**
|
||||||
* 实际上是个随机数, 但服务器确实是用它当做 uid
|
* 实际上是个随机数, 但服务器确实是用它当做 uid
|
||||||
*/
|
*/
|
||||||
val messageUid: Long
|
val messageUid: Int
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送时间, 单位为秒
|
* 发送时间, 单位为秒
|
||||||
|
Loading…
Reference in New Issue
Block a user