Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
405696d9
Commit
405696d9
authored
Apr 18, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use sequenceId as `MessageSource.id`, await sequenceId on `Group.sendMessage`
parent
c695f2cd
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
63 additions
and
37 deletions
+63
-37
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt
...n/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt
+7
-7
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt
...ain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt
+9
-0
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/incomingSourceImpl.kt
...n/net/mamoe/mirai/qqandroid/message/incomingSourceImpl.kt
+17
-6
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/offlineSourceImpl.kt
...in/net/mamoe/mirai/qqandroid/message/offlineSourceImpl.kt
+7
-4
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/outgoingSourceImpl.kt
...n/net/mamoe/mirai/qqandroid/message/outgoingSourceImpl.kt
+15
-5
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt
...ndroid/network/protocol/packet/chat/receive/MessageSvc.kt
+6
-6
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt
...Main/kotlin/net.mamoe.mirai/message/data/MessageSource.kt
+2
-9
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt
View file @
405696d9
...
...
@@ -7,7 +7,7 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
@
file
:
Suppress
(
"EXPERIMENTAL_API_USAGE"
,
"
DEPRECATION_ERROR"
,
"
INVISIBLE_REFERENCE"
,
"INVISIBLE_MEMBER"
)
@
file
:
Suppress
(
"EXPERIMENTAL_API_USAGE"
,
"INVISIBLE_REFERENCE"
,
"INVISIBLE_MEMBER"
)
package
net.mamoe.mirai.qqandroid
...
...
@@ -322,7 +322,7 @@ internal abstract class QQAndroidBotBase constructor(
bot
.
asQQAndroidBot
().
client
,
group
.
id
,
source
.
sequenceId
,
source
.
id
source
.
random
).
sendAndExpect
<
PbMessageSvc
.
PbMsgWithDraw
.
Response
>()
}
}
...
...
@@ -336,7 +336,7 @@ internal abstract class QQAndroidBotBase constructor(
bot
.
client
,
source
.
targetId
,
source
.
sequenceId
,
source
.
id
,
source
.
random
,
source
.
time
).
sendAndExpect
<
PbMessageSvc
.
PbMsgWithDraw
.
Response
>()
}
...
...
@@ -352,7 +352,7 @@ internal abstract class QQAndroidBotBase constructor(
source
.
target
.
group
.
id
,
source
.
targetId
,
source
.
sequenceId
,
source
.
id
,
source
.
random
,
source
.
time
).
sendAndExpect
<
PbMessageSvc
.
PbMsgWithDraw
.
Response
>()
}
...
...
@@ -366,7 +366,7 @@ internal abstract class QQAndroidBotBase constructor(
bot
.
client
,
source
.
targetId
,
source
.
sequenceId
,
source
.
id
,
source
.
random
,
source
.
time
).
sendAndExpect
<
PbMessageSvc
.
PbMsgWithDraw
.
Response
>()
}
...
...
@@ -379,7 +379,7 @@ internal abstract class QQAndroidBotBase constructor(
source
.
targetId
,
// groupUin
source
.
targetId
,
// memberUin
source
.
sequenceId
,
source
.
id
,
source
.
random
,
source
.
time
).
sendAndExpect
<
PbMessageSvc
.
PbMsgWithDraw
.
Response
>()
}
...
...
@@ -388,7 +388,7 @@ internal abstract class QQAndroidBotBase constructor(
bot
.
client
,
source
.
targetId
,
source
.
sequenceId
,
source
.
id
source
.
random
).
sendAndExpect
<
PbMessageSvc
.
PbMsgWithDraw
.
Response
>()
}
}
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt
View file @
405696d9
...
...
@@ -345,6 +345,15 @@ internal class GroupImpl(
}
}
try
{
source
.
ensureSequenceIdAvailable
()
}
catch
(
e
:
Exception
)
{
bot
.
network
.
logger
.
warning
{
"Timeout awaiting sequenceId for group message(${message.contentToString()
.
take
(
10
)}).
Some
features
may
not
work
properly
"
}
}
return
MessageReceipt
(
source
,
this
,
botAsMember
)
}
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/incomingSourceImpl.kt
View file @
405696d9
...
...
@@ -27,16 +27,24 @@ import net.mamoe.mirai.qqandroid.utils.io.serialization.toByteArray
internal
interface
MessageSourceInternal
{
val
sequenceId
:
Int
val
random
:
Int
@Deprecated
(
"don't use this internally. Use sequenceId or random instead."
,
level
=
DeprecationLevel
.
ERROR
)
val
id
:
Int
val
isRecalledOrPlanned
:
MiraiAtomicBoolean
fun
toJceData
():
ImMsgBody
.
SourceMsg
}
@Suppress
(
"RedundantSuspendModifier"
,
"unused"
)
internal
suspend
inline
fun
MessageSource
.
ensureSequenceIdAvailable
()
{
// obsolete but keep for future
return
/*
if (this is MessageSourceToGroupImpl) {
this.ensureSequenceIdAvailable()
}
}
*/
}
internal
class
MessageSourceFromFriendImpl
(
...
...
@@ -45,12 +53,13 @@ internal class MessageSourceFromFriendImpl(
)
:
OnlineMessageSource
.
Incoming
.
FromFriend
(),
MessageSourceInternal
{
override
val
sequenceId
:
Int
get
()
=
msg
.
msgHead
.
msgSeq
override
var
isRecalledOrPlanned
:
MiraiAtomicBoolean
=
MiraiAtomicBoolean
(
false
)
override
val
id
:
Int
get
()
=
msg
.
msgBody
.
richText
.
attr
!!
.
random
override
val
id
:
Int
get
()
=
sequenceId
// msg.msgBody.richText.attr!!.random
override
val
random
:
Int
get
()
=
msg
.
msgBody
.
richText
.
attr
!!
.
random
override
val
time
:
Int
get
()
=
msg
.
msgHead
.
msgTime
override
val
originalMessage
:
MessageChain
by
lazy
{
msg
.
toMessageChain
(
bot
,
0
,
false
)
}
override
val
sender
:
QQ
get
()
=
bot
.
getFriend
(
msg
.
msgHead
.
fromUin
)
private
val
jceData
by
lazy
{
msg
.
toJceDataFriendOrTemp
(
id
)
}
private
val
jceData
by
lazy
{
msg
.
toJceDataFriendOrTemp
(
random
)
}
override
fun
toJceData
():
ImMsgBody
.
SourceMsg
=
jceData
}
...
...
@@ -96,13 +105,14 @@ internal class MessageSourceFromTempImpl(
private
val
msg
:
MsgComm
.
Msg
)
:
OnlineMessageSource
.
Incoming
.
FromTemp
(),
MessageSourceInternal
{
override
val
sequenceId
:
Int
get
()
=
msg
.
msgHead
.
msgSeq
override
val
random
:
Int
get
()
=
msg
.
msgBody
.
richText
.
attr
!!
.
random
override
var
isRecalledOrPlanned
:
MiraiAtomicBoolean
=
MiraiAtomicBoolean
(
false
)
override
val
id
:
Int
get
()
=
msg
.
msgBody
.
richText
.
attr
!!
.
random
override
val
id
:
Int
get
()
=
sequenceId
//
override
val
time
:
Int
get
()
=
msg
.
msgHead
.
msgTime
override
val
originalMessage
:
MessageChain
by
lazy
{
msg
.
toMessageChain
(
bot
,
0
,
false
)
}
override
val
sender
:
Member
get
()
=
with
(
msg
.
msgHead
)
{
bot
.
getGroup
(
c2cTmpMsgHead
!!
.
groupUin
)[
fromUin
]
}
private
val
jceData
by
lazy
{
msg
.
toJceDataFriendOrTemp
(
id
)
}
private
val
jceData
by
lazy
{
msg
.
toJceDataFriendOrTemp
(
random
)
}
override
fun
toJceData
():
ImMsgBody
.
SourceMsg
=
jceData
}
...
...
@@ -112,7 +122,8 @@ internal data class MessageSourceFromGroupImpl(
)
:
OnlineMessageSource
.
Incoming
.
FromGroup
(),
MessageSourceInternal
{
override
var
isRecalledOrPlanned
:
MiraiAtomicBoolean
=
MiraiAtomicBoolean
(
false
)
override
val
sequenceId
:
Int
get
()
=
msg
.
msgHead
.
msgSeq
override
val
id
:
Int
get
()
=
msg
.
msgBody
.
richText
.
attr
!!
.
random
override
val
random
:
Int
get
()
=
msg
.
msgBody
.
richText
.
attr
!!
.
random
override
val
id
:
Int
get
()
=
sequenceId
override
val
time
:
Int
get
()
=
msg
.
msgHead
.
msgTime
override
val
originalMessage
:
MessageChain
by
lazy
{
msg
.
toMessageChain
(
bot
,
groupIdOrZero
=
group
.
id
,
onlineSource
=
false
)
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/offlineSourceImpl.kt
View file @
405696d9
...
...
@@ -27,7 +27,8 @@ internal class OfflineMessageSourceImplByMsg(
override
val
bot
:
Bot
)
:
OfflineMessageSource
(),
MessageSourceInternal
{
override
val
kind
:
Kind
=
if
(
delegate
.
msgHead
.
groupInfo
!=
null
)
Kind
.
GROUP
else
Kind
.
FRIEND
override
val
id
:
Int
override
val
id
:
Int
get
()
=
sequenceId
override
val
random
:
Int
get
()
=
delegate
.
msgHead
.
msgUid
.
toInt
()
override
val
time
:
Int
get
()
=
delegate
.
msgHead
.
msgTime
...
...
@@ -73,6 +74,8 @@ internal class OfflineMessageSourceImplBySourceMsg(
override
var
isRecalledOrPlanned
:
MiraiAtomicBoolean
=
MiraiAtomicBoolean
(
false
)
override
val
sequenceId
:
Int
get
()
=
delegate
.
origSeqs
?.
first
()
?:
error
(
"cannot find sequenceId"
)
override
val
random
:
Int
get
()
=
delegate
.
pbReserve
.
loadAs
(
SourceMsg
.
ResvAttr
.
serializer
()).
origUids
?.
toInt
()
?:
0
override
val
time
:
Int
get
()
=
delegate
.
time
override
val
originalMessage
:
MessageChain
by
lazy
{
delegate
.
toMessageChain
(
bot
,
groupIdOrZero
)
}
/*
...
...
@@ -82,9 +85,9 @@ internal class OfflineMessageSourceImplBySourceMsg(
delegate.pbReserve.loadAs(SourceMsg.ResvAttr.serializer()).origUids!!.and(0xFFFFFFFF)
*/
override
val
id
:
Int
get
()
=
delegate
.
pbReserve
.
loadAs
(
SourceMsg
.
ResvAttr
.
serializer
()).
origUids
?.
toInt
()
?:
0
override
val
id
:
Int
get
()
=
sequenceId
//
delegate.pbReserve.loadAs(SourceMsg.ResvAttr.serializer()).origUids?.toInt()
//
?: 0
// override val sourceMessage: MessageChain get() = delegate.toMessageChain()
override
val
fromId
:
Long
get
()
=
delegate
.
senderUin
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/outgoingSourceImpl.kt
View file @
405696d9
...
...
@@ -34,7 +34,7 @@ private fun <T> T.toJceDataImpl(): ImMsgBody.SourceMsg
where
T
:
MessageSourceInternal
,
T
:
MessageSource
{
val
elements
=
originalMessage
.
toRichTextElems
(
forGroup
=
false
,
withGeneralFlags
=
true
)
val
messageUid
:
Long
=
sequenceId
.
toLong
().
shl
(
32
)
or
id
.
toLong
().
and
(
0
xffFFffFF
)
val
messageUid
:
Long
=
sequenceId
.
toLong
().
shl
(
32
)
or
random
.
toLong
().
and
(
0
xffFFffFF
)
return
ImMsgBody
.
SourceMsg
(
origSeqs
=
listOf
(
sequenceId
),
senderUin
=
fromId
,
...
...
@@ -71,7 +71,7 @@ private fun <T> T.toJceDataImpl(): ImMsgBody.SourceMsg
internal
class
MessageSourceToFriendImpl
(
override
val
sequenceId
:
Int
,
override
val
id
:
Int
,
override
val
random
:
Int
,
override
val
time
:
Int
,
override
val
originalMessage
:
MessageChain
,
override
val
sender
:
Bot
,
...
...
@@ -79,6 +79,8 @@ internal class MessageSourceToFriendImpl(
)
:
OnlineMessageSource
.
Outgoing
.
ToFriend
(),
MessageSourceInternal
{
override
val
bot
:
Bot
get
()
=
sender
override
val
id
:
Int
get
()
=
sequenceId
override
var
isRecalledOrPlanned
:
MiraiAtomicBoolean
=
MiraiAtomicBoolean
(
false
)
private
val
jceData
by
lazy
{
toJceDataImpl
()
}
override
fun
toJceData
():
ImMsgBody
.
SourceMsg
=
jceData
...
...
@@ -86,7 +88,7 @@ internal class MessageSourceToFriendImpl(
internal
class
MessageSourceToTempImpl
(
override
val
sequenceId
:
Int
,
override
val
id
:
Int
,
override
val
random
:
Int
,
override
val
time
:
Int
,
override
val
originalMessage
:
MessageChain
,
override
val
sender
:
Bot
,
...
...
@@ -94,18 +96,22 @@ internal class MessageSourceToTempImpl(
)
:
OnlineMessageSource
.
Outgoing
.
ToTemp
(),
MessageSourceInternal
{
override
val
bot
:
Bot
get
()
=
sender
override
val
id
:
Int
get
()
=
sequenceId
override
var
isRecalledOrPlanned
:
MiraiAtomicBoolean
=
MiraiAtomicBoolean
(
false
)
private
val
jceData
by
lazy
{
toJceDataImpl
()
}
override
fun
toJceData
():
ImMsgBody
.
SourceMsg
=
jceData
}
internal
class
MessageSourceToGroupImpl
(
override
val
id
:
Int
,
override
val
random
:
Int
,
override
val
time
:
Int
,
override
val
originalMessage
:
MessageChain
,
override
val
sender
:
Bot
,
override
val
target
:
Group
)
:
OnlineMessageSource
.
Outgoing
.
ToGroup
(),
MessageSourceInternal
{
override
val
id
:
Int
get
()
=
sequenceId
override
val
bot
:
Bot
get
()
=
sender
override
var
isRecalledOrPlanned
:
MiraiAtomicBoolean
=
MiraiAtomicBoolean
(
false
)
...
...
@@ -113,7 +119,11 @@ internal class MessageSourceToGroupImpl(
@OptIn
(
ExperimentalCoroutinesApi
::
class
)
override
val
sequenceId
:
Int
get
()
=
sequenceIdDeferred
.
getCompleted
()
get
()
=
when
{
sequenceIdDeferred
.
isCompleted
->
sequenceIdDeferred
.
getCompleted
()
!
sequenceIdDeferred
.
isActive
->
0
else
->
error
(
"sequenceId not yet available"
)
}
@OptIn
(
MiraiExperimentalAPI
::
class
)
internal
fun
startWaitingSequenceId
(
coroutineScope
:
CoroutineScope
)
{
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt
View file @
405696d9
...
...
@@ -371,7 +371,7 @@ internal class MessageSvc {
):
OutgoingPacket
{
val
rand
=
Random
.
nextInt
().
absoluteValue
val
source
=
MessageSourceToFriendImpl
(
id
=
rand
,
random
=
rand
,
sender
=
client
.
bot
,
target
=
qq
,
time
=
currentTimeSeconds
.
toInt
(),
...
...
@@ -405,7 +405,7 @@ internal class MessageSvc {
)
),
msgSeq
=
source
.
sequenceId
,
msgRand
=
source
.
id
,
msgRand
=
source
.
random
,
syncCookie
=
SyncCookie
(
time
=
source
.
time
.
toLong
()).
toByteArray
(
SyncCookie
.
serializer
())
// msgVia = 1
)
...
...
@@ -420,7 +420,7 @@ internal class MessageSvc {
sourceCallback
:
(
MessageSourceToTempImpl
)
->
Unit
):
OutgoingPacket
{
val
source
=
MessageSourceToTempImpl
(
id
=
Random
.
nextInt
().
absoluteValue
,
random
=
Random
.
nextInt
().
absoluteValue
,
sender
=
client
.
bot
,
target
=
member
,
time
=
currentTimeSeconds
.
toInt
(),
...
...
@@ -453,7 +453,7 @@ internal class MessageSvc {
)
),
msgSeq
=
source
.
sequenceId
,
msgRand
=
source
.
id
,
msgRand
=
source
.
random
,
syncCookie
=
SyncCookie
(
time
=
source
.
time
.
toLong
()).
toByteArray
(
SyncCookie
.
serializer
())
)
)
...
...
@@ -468,7 +468,7 @@ internal class MessageSvc {
):
OutgoingPacket
{
val
source
=
MessageSourceToGroupImpl
(
id
=
Random
.
nextInt
().
absoluteValue
,
random
=
Random
.
nextInt
().
absoluteValue
,
sender
=
client
.
bot
,
target
=
group
,
time
=
currentTimeSeconds
.
toInt
(),
...
...
@@ -504,7 +504,7 @@ internal class MessageSvc {
)
),
msgSeq
=
client
.
atomicNextMessageSequenceId
(),
msgRand
=
source
.
id
,
msgRand
=
source
.
random
,
syncCookie
=
EMPTY_BYTE_ARRAY
,
msgVia
=
1
)
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt
View file @
405696d9
...
...
@@ -53,10 +53,9 @@ sealed class MessageSource : Message, MessageMetadata, ConstrainSingle<MessageSo
/**
* 消息 id.
* 当 [OnlineMessageSource] 时为随机数.
* 当 [OfflineMessageSource] 时可能为 0, 取决于服务器是否提供这个值.
* 此值在同一会话中唯一且有顺序.
*/
abstract
val
id
:
Int
// random
abstract
val
id
:
Int
/**
* 发送时间时间戳, 单位为秒.
...
...
@@ -335,12 +334,6 @@ abstract class OfflineMessageSource : MessageSource() {
*/
abstract
val
kind
:
Kind
/**
* 消息 id.
* 服务器不一定提供 id. 因此此值可能为 0
*/
abstract
override
val
id
:
Int
// final override fun toString(): String = "OfflineMessageSource(sender=$senderId, target=$targetId)"
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment