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
0015b7bc
Commit
0015b7bc
authored
Feb 22, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make `MessageSource.messageUid` int
parent
0e30d3d6
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
63 additions
and
39 deletions
+63
-39
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/common/MessageDTO.kt
...kotlin/net/mamoe/mirai/api/http/data/common/MessageDTO.kt
+1
-1
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/queue/MessageQueue.kt
...ain/kotlin/net/mamoe/mirai/api/http/queue/MessageQueue.kt
+1
-1
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt
...ommonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt
+7
-5
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/MessageSourceFromMsg.kt
...net/mamoe/mirai/qqandroid/message/MessageSourceFromMsg.kt
+5
-4
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/data/proto/MsgSvc.kt
...moe/mirai/qqandroid/network/protocol/data/proto/MsgSvc.kt
+1
-1
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
+43
-23
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageReceipt.kt
...mmonMain/kotlin/net.mamoe.mirai/message/MessageReceipt.kt
+4
-3
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt
...Main/kotlin/net.mamoe.mirai/message/data/MessageSource.kt
+1
-1
No files found.
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/common/MessageDTO.kt
View file @
0015b7bc
...
...
@@ -98,7 +98,7 @@ fun MessageChainDTO.toMessageChain(contact: Contact) =
@UseExperimental
(
ExperimentalUnsignedTypes
::
class
)
fun
Message
.
toDTO
()
=
when
(
this
)
{
is
MessageSource
->
MessageSourceDTO
(
messageUid
)
is
MessageSource
->
MessageSourceDTO
(
messageUid
.
toLong
()
and
0
xFFffFFff
)
is
At
->
AtDTO
(
target
,
display
)
is
AtAll
->
AtAllDTO
(
0L
)
is
Face
->
FaceDTO
(
id
)
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/queue/MessageQueue.kt
View file @
0015b7bc
...
...
@@ -44,6 +44,6 @@ class MessageQueue : ConcurrentLinkedDeque<BotEvent>() {
}
private
fun
addCache
(
msg
:
GroupMessage
)
{
quoteCache
[
msg
.
message
[
MessageSource
].
messageUid
]
=
msg
quoteCache
[
msg
.
message
[
MessageSource
].
messageUid
.
toLong
()
and
0
xFFffFFff
]
=
msg
}
}
\ No newline at end of file
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt
View file @
0015b7bc
...
...
@@ -70,16 +70,17 @@ internal class QQImpl(
if
(
event
.
isCancelled
)
{
throw
EventCancelledException
(
"cancelled by FriendMessageSendEvent"
)
}
lateinit
var
source
:
MessageSource
bot
.
network
.
run
{
check
(
MessageSvc
.
PbSendMsg
.
ToFriend
(
bot
.
client
,
id
,
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"
}
}
return
MessageReceipt
(
message
,
this
)
return
MessageReceipt
(
message
,
source
,
this
)
}
override
suspend
fun
uploadImage
(
image
:
ExternalImage
):
Image
=
try
{
...
...
@@ -552,12 +553,13 @@ internal class GroupImpl(
if
(
event
.
isCancelled
)
{
throw
EventCancelledException
(
"cancelled by FriendMessageSendEvent"
)
}
lateinit
var
source
:
MessageSource
bot
.
network
.
run
{
val
response
=
MessageSvc
.
PbSendMsg
.
ToGroup
(
val
response
:
MessageSvc
.
PbSendMsg
.
Response
=
MessageSvc
.
PbSendMsg
.
ToGroup
(
bot
.
client
,
id
,
event
.
message
)
.
sendAndExpect
<
MessageSvc
.
PbSendMsg
.
Response
>
()
)
{
source
=
it
}.
sendAndExpect
()
check
(
response
is
MessageSvc
.
PbSendMsg
.
Response
.
SUCCESS
)
{
"send message failed: $response"
}
...
...
@@ -566,7 +568,7 @@ internal class GroupImpl(
((
message
.
last
()
as
MessageSource
)
as
MessageSvc
.
PbSendMsg
.
MessageSourceFromSend
)
.
startWaitingSequenceId
(
this
)
return
MessageReceipt
(
message
,
this
)
return
MessageReceipt
(
message
,
source
,
this
)
}
override
suspend
fun
uploadImage
(
image
:
ExternalImage
):
Image
=
try
{
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/MessageSourceFromMsg.kt
View file @
0015b7bc
...
...
@@ -27,7 +27,7 @@ internal inline class MessageSourceFromServer(
// 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
senderId
:
Long
get
()
=
delegate
.
senderUin
override
val
groupId
:
Long
get
()
=
Group
.
calculateGroupCodeByGroupUin
(
delegate
.
toUin
)
...
...
@@ -44,7 +44,7 @@ internal inline class MessageSourceFromMsg(
// 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
senderId
:
Long
get
()
=
delegate
.
msgHead
.
fromUin
override
val
groupId
:
Long
get
()
=
delegate
.
msgHead
.
groupInfo
!!
.
groupCode
...
...
@@ -62,7 +62,7 @@ internal inline class MessageSourceFromMsg(
type
=
0
,
time
=
delegate
.
msgHead
.
msgTime
,
pbReserve
=
SourceMsg
.
ResvAttr
(
origUids
=
messageUid
origUids
=
messageUid
.
toLong
()
and
0
xffFFffFF
).
toByteArray
(
SourceMsg
.
ResvAttr
.
serializer
()),
srcMsg
=
MsgComm
.
Msg
(
msgHead
=
MsgComm
.
MsgHead
(
...
...
@@ -72,7 +72,8 @@ internal inline class MessageSourceFromMsg(
c2cCmd
=
delegate
.
msgHead
.
c2cCmd
,
msgSeq
=
delegate
.
msgHead
.
msgSeq
,
msgTime
=
delegate
.
msgHead
.
msgTime
,
msgUid
=
messageUid
,
// ok
msgUid
=
messageUid
.
toLong
()
and
0
xffFFffFF
,
// ok
groupInfo
=
MsgComm
.
GroupInfo
(
groupCode
=
delegate
.
msgHead
.
groupInfo
.
groupCode
),
isSrcMsg
=
true
),
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/data/proto/MsgSvc.kt
View file @
0015b7bc
...
...
@@ -26,7 +26,7 @@ internal class MsgSvc : ProtoBuf {
internal
class
PbGetMsgResp
(
@SerialId
(
1
)
val
result
:
Int
=
0
,
@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
(
5
)
val
uinPairMsgs
:
List
<
MsgComm
.
UinPairMsg
>?
=
null
,
@SerialId
(
6
)
val
bindUin
:
Long
=
0L
,
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt
View file @
0015b7bc
...
...
@@ -272,7 +272,7 @@ internal class MessageSvc {
}
internal
class
MessageSourceFromSend
(
override
val
messageUid
:
Long
,
override
val
messageUid
:
Int
,
override
val
time
:
Long
,
override
val
senderId
:
Long
,
override
val
groupId
:
Long
// ,
...
...
@@ -283,7 +283,7 @@ internal class MessageSvc {
@UseExperimental
(
MiraiExperimentalAPI
::
class
)
fun
startWaitingSequenceId
(
contact
:
Contact
)
{
sequenceIdDeferred
=
contact
.
subscribingGetAsync
<
OnlinePush
.
PbPushGroupMsg
.
SendGroupMessageReceipt
,
Int
>
{
if
(
it
.
messageRandom
==
messageUid
.
toInt
()
)
{
if
(
it
.
messageRandom
==
messageUid
)
{
it
.
sequenceId
}
else
null
}
...
...
@@ -302,25 +302,34 @@ internal class MessageSvc {
}
}
/**
* 发送好友消息
*/
@Suppress
(
"FunctionName"
)
fun
ToFriend
(
inline
fun
ToFriend
(
client
:
QQAndroidClient
,
toUin
:
Long
,
message
:
MessageChain
):
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())
message
:
MessageChain
,
crossinline
sourceCallback
:
(
MessageSource
)
->
Unit
):
OutgoingPacket
{
val
source
=
MessageSourceFromSend
(
messageUid
=
Random
.
nextInt
().
absoluteValue
.
toLong
()
and
0
xffffffff
,
messageUid
=
Random
.
nextInt
().
absoluteValue
,
senderId
=
client
.
uin
,
time
=
currentTimeSeconds
+
client
.
timeDifference
,
groupId
=
0
//
// 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
writeProtoBuf
(
...
...
@@ -333,31 +342,42 @@ internal class MessageSvc {
)
),
msgSeq
=
client
.
atomicNextMessageSequenceId
(),
msgRand
=
source
.
messageUid
.
toInt
()
,
msgRand
=
source
.
messageUid
,
syncCookie
=
SyncCookie
(
time
=
source
.
time
).
toByteArray
(
SyncCookie
.
serializer
())
// msgVia = 1
)
)
}
/**
* 发送群消息
*/
@Suppress
(
"FunctionName"
)
fun
ToGroup
(
inline
fun
ToGroup
(
client
:
QQAndroidClient
,
groupCode
:
Long
,
message
:
MessageChain
):
OutgoingPacket
=
buildOutgoingUniPacket
(
client
)
{
message
:
MessageChain
,
sourceCallback
:
(
MessageSource
)
->
Unit
):
OutgoingPacket
{
val
source
=
MessageSourceFromSend
(
messageUid
=
Random
.
nextInt
().
absoluteValue
.
toLong
()
,
messageUid
=
Random
.
nextInt
().
absoluteValue
,
senderId
=
client
.
uin
,
time
=
currentTimeSeconds
+
client
.
timeDifference
,
groupId
=
groupCode
//,
// sourceMessage = message
)
sourceCallback
(
source
)
return
ToGroup
(
client
,
groupCode
,
message
,
source
)
}
/**
* 发送群消息
*/
@Suppress
(
"FunctionName"
)
fun
ToGroup
(
client
:
QQAndroidClient
,
groupCode
:
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())
// DebugLogger.debug("sending group message: " + message.toRichTextElems().contentToString())
...
...
@@ -373,7 +393,7 @@ internal class MessageSvc {
)
),
msgSeq
=
client
.
atomicNextMessageSequenceId
(),
msgRand
=
source
.
messageUid
.
toInt
()
,
msgRand
=
source
.
messageUid
,
syncCookie
=
EMPTY_BYTE_ARRAY
,
msgVia
=
1
)
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageReceipt.kt
View file @
0015b7bc
...
...
@@ -28,6 +28,7 @@ import net.mamoe.mirai.utils.unsafeWeakRef
*/
open
class
MessageReceipt
<
C
:
Contact
>(
val
originalMessage
:
MessageChain
,
private
val
source
:
MessageSource
,
target
:
C
)
{
init
{
...
...
@@ -53,7 +54,7 @@ open class MessageReceipt<C : Contact>(
if
(
_isRecalled
.
compareAndSet
(
false
,
true
))
{
when
(
val
contact
=
target
)
{
is
Group
->
{
contact
.
recall
(
originalMessag
e
)
contact
.
recall
(
sourc
e
)
}
is
QQ
->
{
TODO
()
...
...
@@ -76,7 +77,7 @@ open class MessageReceipt<C : Contact>(
if
(
_isRecalled
.
compareAndSet
(
false
,
true
))
{
when
(
val
contact
=
target
)
{
is
Group
->
{
return
contact
.
recallIn
(
originalMessag
e
,
millis
)
return
contact
.
recallIn
(
sourc
e
,
millis
)
}
is
QQ
->
{
TODO
()
...
...
@@ -97,7 +98,7 @@ open class MessageReceipt<C : Contact>(
open
fun
quote
():
MessageChain
{
val
target
=
target
check
(
target
is
Group
)
{
"quote is only available for GroupMessage"
}
return
this
.
originalMessag
e
.
quote
(
target
.
botAsMember
)
return
this
.
sourc
e
.
quote
(
target
.
botAsMember
)
}
/**
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt
View file @
0015b7bc
...
...
@@ -41,7 +41,7 @@ interface MessageSource : Message {
/**
* 实际上是个随机数, 但服务器确实是用它当做 uid
*/
val
messageUid
:
Long
val
messageUid
:
Int
/**
* 发送时间, 单位为秒
...
...
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