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
d97aa7bd
Commit
d97aa7bd
authored
Apr 12, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unified MessageSource.toJceData
parent
e279e79b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
19 deletions
+36
-19
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/MessageSourceImpl.kt
...in/net/mamoe/mirai/qqandroid/message/MessageSourceImpl.kt
+34
-11
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/convension.kt
...in/kotlin/net/mamoe/mirai/qqandroid/message/convension.kt
+2
-8
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/MessageSourceImpl.kt
View file @
d97aa7bd
...
@@ -39,6 +39,8 @@ internal interface MessageSourceImpl {
...
@@ -39,6 +39,8 @@ internal interface MessageSourceImpl {
val
sequenceId
:
Int
val
sequenceId
:
Int
var
isRecalledOrPlanned
:
Boolean
// // TODO: 2020/4/7 实现 isRecalledOrPlanned
var
isRecalledOrPlanned
:
Boolean
// // TODO: 2020/4/7 实现 isRecalledOrPlanned
fun
toJceData
():
ImMsgBody
.
SourceMsg
}
}
internal
suspend
inline
fun
MessageSource
.
ensureSequenceIdAvailable
()
{
internal
suspend
inline
fun
MessageSource
.
ensureSequenceIdAvailable
()
{
...
@@ -76,7 +78,7 @@ internal class MessageSourceFromFriendImpl(
...
@@ -76,7 +78,7 @@ internal class MessageSourceFromFriendImpl(
}
}
}
}
internal
fun
toJceDataImplForFriend
():
ImMsgBody
.
SourceMsg
{
override
fun
toJceData
():
ImMsgBody
.
SourceMsg
{
return
ImMsgBody
.
SourceMsg
(
return
ImMsgBody
.
SourceMsg
(
origSeqs
=
listOf
(
msg
.
msgHead
.
msgSeq
),
origSeqs
=
listOf
(
msg
.
msgHead
.
msgSeq
),
senderUin
=
msg
.
msgHead
.
fromUin
,
senderUin
=
msg
.
msgHead
.
fromUin
,
...
@@ -131,9 +133,10 @@ internal class MessageSourceFromTempImpl(
...
@@ -131,9 +133,10 @@ internal class MessageSourceFromTempImpl(
)
)
}
}
override
val
target
:
Bot
get
()
=
bot
override
val
target
:
Bot
get
()
=
bot
override
val
sender
:
Member
get
()
=
with
(
msg
.
msgHead
)
{
override
val
sender
:
Member
bot
.
getGroup
(
c2cTmpMsgHead
!!
.
groupUin
)[
fromUin
]
get
()
=
with
(
msg
.
msgHead
)
{
}
bot
.
getGroup
(
c2cTmpMsgHead
!!
.
groupUin
)[
fromUin
]
}
private
val
elems
by
lazy
{
private
val
elems
by
lazy
{
msg
.
msgBody
.
richText
.
elems
.
toMutableList
().
also
{
msg
.
msgBody
.
richText
.
elems
.
toMutableList
().
also
{
...
@@ -141,7 +144,7 @@ internal class MessageSourceFromTempImpl(
...
@@ -141,7 +144,7 @@ internal class MessageSourceFromTempImpl(
}
}
}
}
internal
fun
toJceDataImplForTemp
():
ImMsgBody
.
SourceMsg
{
override
fun
toJceData
():
ImMsgBody
.
SourceMsg
{
return
ImMsgBody
.
SourceMsg
(
return
ImMsgBody
.
SourceMsg
(
origSeqs
=
listOf
(
msg
.
msgHead
.
msgSeq
),
origSeqs
=
listOf
(
msg
.
msgHead
.
msgSeq
),
senderUin
=
msg
.
msgHead
.
fromUin
,
senderUin
=
msg
.
msgHead
.
fromUin
,
...
@@ -204,7 +207,7 @@ internal class MessageSourceFromGroupImpl(
...
@@ -204,7 +207,7 @@ internal class MessageSourceFromGroupImpl(
?:
error
(
"cannot find member for MessageSourceFromGroupImpl. msg=${msg._miraiContentToString()}"
)
?:
error
(
"cannot find member for MessageSourceFromGroupImpl. msg=${msg._miraiContentToString()}"
)
fun
toJceDataImplForGroup
():
ImMsgBody
.
SourceMsg
{
override
fun
toJceData
():
ImMsgBody
.
SourceMsg
{
return
ImMsgBody
.
SourceMsg
(
return
ImMsgBody
.
SourceMsg
(
origSeqs
=
listOf
(
msg
.
msgHead
.
msgSeq
),
origSeqs
=
listOf
(
msg
.
msgHead
.
msgSeq
),
senderUin
=
msg
.
msgHead
.
fromUin
,
senderUin
=
msg
.
msgHead
.
fromUin
,
...
@@ -219,7 +222,8 @@ internal class MessageSourceFromGroupImpl(
...
@@ -219,7 +222,8 @@ internal class MessageSourceFromGroupImpl(
}
}
}
}
internal
class
OfflineMessageSourceImplByMsg
(
// from other sources' originalMessage
internal
class
OfflineMessageSourceImplByMsg
(
// from other sources' originalMessage
val
delegate
:
MsgComm
.
Msg
,
val
delegate
:
MsgComm
.
Msg
,
override
val
bot
:
Bot
override
val
bot
:
Bot
)
:
OfflineMessageSource
(),
MessageSourceImpl
{
)
:
OfflineMessageSource
(),
MessageSourceImpl
{
...
@@ -248,9 +252,24 @@ internal class OfflineMessageSourceImplByMsg( // from other sources' originalMes
...
@@ -248,9 +252,24 @@ internal class OfflineMessageSourceImplByMsg( // from other sources' originalMes
set
(
value
)
{
set
(
value
)
{
isRecalled
.
value
=
value
isRecalled
.
value
=
value
}
}
override
fun
toJceData
():
ImMsgBody
.
SourceMsg
{
return
ImMsgBody
.
SourceMsg
(
origSeqs
=
listOf
(
delegate
.
msgHead
.
msgSeq
),
senderUin
=
delegate
.
msgHead
.
fromUin
,
toUin
=
0
,
flag
=
1
,
elems
=
delegate
.
msgBody
.
richText
.
elems
,
type
=
0
,
time
=
delegate
.
msgHead
.
msgTime
,
pbReserve
=
EMPTY_BYTE_ARRAY
,
srcMsg
=
EMPTY_BYTE_ARRAY
)
}
}
}
internal
class
OfflineMessageSourceImplBySourceMsg
(
// from others' quotation
internal
class
OfflineMessageSourceImplBySourceMsg
(
// from others' quotation
val
delegate
:
ImMsgBody
.
SourceMsg
,
val
delegate
:
ImMsgBody
.
SourceMsg
,
override
val
bot
:
Bot
,
override
val
bot
:
Bot
,
groupIdOrZero
:
Long
groupIdOrZero
:
Long
...
@@ -295,6 +314,10 @@ internal class OfflineMessageSourceImplBySourceMsg( // from others' quotation
...
@@ -295,6 +314,10 @@ internal class OfflineMessageSourceImplBySourceMsg( // from others' quotation
)*/
)*/
}
}
}
}
override
fun
toJceData
():
ImMsgBody
.
SourceMsg
{
return
delegate
}
}
}
internal
class
MessageSourceToFriendImpl
(
internal
class
MessageSourceToFriendImpl
(
...
@@ -317,7 +340,7 @@ internal class MessageSourceToFriendImpl(
...
@@ -317,7 +340,7 @@ internal class MessageSourceToFriendImpl(
originalMessage
.
toRichTextElems
(
forGroup
=
false
,
withGeneralFlags
=
true
)
originalMessage
.
toRichTextElems
(
forGroup
=
false
,
withGeneralFlags
=
true
)
}
}
fun
toJceDataImplForFriend
():
ImMsgBody
.
SourceMsg
{
override
fun
toJceData
():
ImMsgBody
.
SourceMsg
{
val
messageUid
:
Long
=
sequenceId
.
toLong
().
shl
(
32
)
or
id
.
toLong
().
and
(
0
xffFFffFF
)
val
messageUid
:
Long
=
sequenceId
.
toLong
().
shl
(
32
)
or
id
.
toLong
().
and
(
0
xffFFffFF
)
return
ImMsgBody
.
SourceMsg
(
return
ImMsgBody
.
SourceMsg
(
origSeqs
=
listOf
(
sequenceId
),
origSeqs
=
listOf
(
sequenceId
),
...
@@ -374,7 +397,7 @@ internal class MessageSourceToTempImpl(
...
@@ -374,7 +397,7 @@ internal class MessageSourceToTempImpl(
originalMessage
.
toRichTextElems
(
forGroup
=
false
,
withGeneralFlags
=
true
)
originalMessage
.
toRichTextElems
(
forGroup
=
false
,
withGeneralFlags
=
true
)
}
}
fun
toJceDataImplForTemp
():
ImMsgBody
.
SourceMsg
{
override
fun
toJceData
():
ImMsgBody
.
SourceMsg
{
val
messageUid
:
Long
=
sequenceId
.
toLong
().
shl
(
32
)
or
id
.
toLong
().
and
(
0
xffFFffFF
)
val
messageUid
:
Long
=
sequenceId
.
toLong
().
shl
(
32
)
or
id
.
toLong
().
and
(
0
xffFFffFF
)
return
ImMsgBody
.
SourceMsg
(
return
ImMsgBody
.
SourceMsg
(
origSeqs
=
listOf
(
sequenceId
),
origSeqs
=
listOf
(
sequenceId
),
...
@@ -449,7 +472,7 @@ internal class MessageSourceToGroupImpl(
...
@@ -449,7 +472,7 @@ internal class MessageSourceToGroupImpl(
}
}
fun
toJceDataImplForGroup
():
ImMsgBody
.
SourceMsg
{
override
fun
toJceData
():
ImMsgBody
.
SourceMsg
{
return
ImMsgBody
.
SourceMsg
(
return
ImMsgBody
.
SourceMsg
(
origSeqs
=
listOf
(
sequenceId
),
origSeqs
=
listOf
(
sequenceId
),
senderUin
=
fromId
,
senderUin
=
fromId
,
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/convension.kt
View file @
d97aa7bd
...
@@ -40,14 +40,8 @@ internal fun MessageChain.toRichTextElems(forGroup: Boolean, withGeneralFlags: B
...
@@ -40,14 +40,8 @@ internal fun MessageChain.toRichTextElems(forGroup: Boolean, withGeneralFlags: B
if
(
this
.
anyIsInstance
<
QuoteReply
>())
{
if
(
this
.
anyIsInstance
<
QuoteReply
>())
{
when
(
val
source
=
this
[
QuoteReply
].
source
)
{
when
(
val
source
=
this
[
QuoteReply
].
source
)
{
is
OfflineMessageSourceImplBySourceMsg
->
elements
.
add
(
ImMsgBody
.
Elem
(
srcMsg
=
source
.
delegate
))
is
MessageSourceImpl
->
elements
.
add
(
ImMsgBody
.
Elem
(
srcMsg
=
source
.
toJceData
()))
is
MessageSourceToFriendImpl
->
elements
.
add
(
ImMsgBody
.
Elem
(
srcMsg
=
source
.
toJceDataImplForFriend
()))
else
->
error
(
"unsupported MessageSource implementation: ${source::class.simpleName}. Don't implement your own MessageSource."
)
is
MessageSourceToGroupImpl
->
elements
.
add
(
ImMsgBody
.
Elem
(
srcMsg
=
source
.
toJceDataImplForGroup
()))
is
MessageSourceToTempImpl
->
elements
.
add
(
ImMsgBody
.
Elem
(
srcMsg
=
source
.
toJceDataImplForTemp
()))
is
MessageSourceFromFriendImpl
->
elements
.
add
(
ImMsgBody
.
Elem
(
srcMsg
=
source
.
toJceDataImplForFriend
()))
is
MessageSourceFromGroupImpl
->
elements
.
add
(
ImMsgBody
.
Elem
(
srcMsg
=
source
.
toJceDataImplForGroup
()))
is
MessageSourceFromTempImpl
->
elements
.
add
(
ImMsgBody
.
Elem
(
srcMsg
=
source
.
toJceDataImplForTemp
()))
else
->
error
(
"unsupported MessageSource implementation: ${source::class.simpleName}"
)
}
}
}
}
...
...
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