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
ac6f411e
Commit
ac6f411e
authored
Apr 17, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `equals` and `hashCode` to `Message`s
parent
db8cb84c
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
86 additions
and
33 deletions
+86
-33
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/At.kt
.../src/commonMain/kotlin/net.mamoe.mirai/message/data/At.kt
+20
-8
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/AtAll.kt
...c/commonMain/kotlin/net.mamoe.mirai/message/data/AtAll.kt
+7
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/CombinedMessage.kt
...in/kotlin/net.mamoe.mirai/message/data/CombinedMessage.kt
+13
-2
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Face.kt
...rc/commonMain/kotlin/net.mamoe.mirai/message/data/Face.kt
+6
-2
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/HummerMessage.kt
...Main/kotlin/net.mamoe.mirai/message/data/HummerMessage.kt
+15
-6
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt
...c/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt
+6
-3
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt
...commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt
+0
-2
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt
...nMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt
+1
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/PlainText.kt
...mmonMain/kotlin/net.mamoe.mirai/message/data/PlainText.kt
+1
-9
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt
...monMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt
+2
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/RichMessage.kt
...onMain/kotlin/net.mamoe.mirai/message/data/RichMessage.kt
+15
-1
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/At.kt
View file @
ac6f411e
...
...
@@ -29,7 +29,8 @@ import kotlin.jvm.JvmSynthetic
*
* @see AtAll 全体成员
*/
class
At
data class
At
@Suppress
(
"DataClassPrivateConstructor"
)
private
constructor
(
val
target
:
Long
,
val
display
:
String
)
:
MessageContent
,
CharSequence
by
display
,
...
...
@@ -40,6 +41,10 @@ private constructor(val target: Long, val display: String) :
*/
constructor
(
member
:
Member
)
:
this
(
member
.
id
,
"@${member.nameCardOrNick}"
)
override
fun
equals
(
other
:
Any
?):
Boolean
{
return
other
is
At
&&
other
.
target
==
this
.
target
&&
other
.
display
==
this
.
display
}
override
fun
toString
():
String
=
"[mirai:at:$target]"
override
fun
contentToString
():
String
=
this
.
display
...
...
@@ -57,6 +62,20 @@ private constructor(val target: Long, val display: String) :
}
// 自动为消息补充 " "
override
fun
followedBy
(
tail
:
Message
):
MessageChain
{
if
(
tail
is
PlainText
&&
tail
.
stringValue
.
startsWith
(
' '
))
{
return
super
.
followedBy
(
tail
)
}
return
super
.
followedBy
(
PlainText
(
" "
))
+
tail
}
override
fun
hashCode
():
Int
{
var
result
=
target
.
hashCode
()
result
=
31
*
result
+
display
.
hashCode
()
return
result
}
@OptIn
(
MiraiInternalAPI
::
class
)
@Suppress
(
"INAPPLICABLE_JVM_NAME"
,
"EXPOSED_FUNCTION_RETURN_TYPE"
)
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
...
...
@@ -65,13 +84,6 @@ private constructor(val target: Long, val display: String) :
override
fun
followedBy1
(
tail
:
Message
):
CombinedMessage
{
return
followedByInternalForBinaryCompatibility
(
tail
)
}
override
fun
followedBy
(
tail
:
Message
):
MessageChain
{
if
(
tail
is
PlainText
&&
tail
.
stringValue
.
startsWith
(
' '
))
{
return
super
.
followedBy
(
tail
)
}
return
super
.
followedBy
(
PlainText
(
" "
))
+
tail
}
}
/**
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/AtAll.kt
View file @
ac6f411e
...
...
@@ -41,6 +41,13 @@ object AtAll :
@Suppress
(
"SpellCheckingInspection"
)
override
fun
toString
():
String
=
"[mirai:atall]"
override
fun
contentToString
():
String
=
display
override
fun
equals
(
other
:
Any
?):
Boolean
{
return
other
===
this
}
override
fun
hashCode
():
Int
{
return
display
.
hashCode
()
}
// 自动为消息补充 " "
@OptIn
(
MiraiInternalAPI
::
class
)
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/CombinedMessage.kt
View file @
ac6f411e
...
...
@@ -14,6 +14,7 @@ package net.mamoe.mirai.message.data
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
import
net.mamoe.mirai.utils.MiraiInternalAPI
import
kotlin.jvm.JvmField
import
kotlin.jvm.JvmMultifileClass
import
kotlin.jvm.JvmName
import
kotlin.jvm.JvmSynthetic
...
...
@@ -30,8 +31,8 @@ import kotlin.jvm.JvmSynthetic
*/
internal
class
CombinedMessage
internal
constructor
(
internal
val
left
:
Message
,
// 必须已经完成 constrain single
internal
val
tail
:
Message
@JvmField
internal
val
left
:
Message
,
// 必须已经完成 constrain single
@JvmField
internal
val
tail
:
Message
)
:
Message
,
MessageChain
{
@OptIn
(
MiraiExperimentalAPI
::
class
)
fun
asSequence
():
Sequence
<
SingleMessage
>
=
sequence
{
...
...
@@ -49,6 +50,10 @@ internal constructor(
size
}
override
fun
equals
(
other
:
Any
?):
Boolean
{
return
other
is
CombinedMessage
&&
other
.
left
==
this
.
left
&&
other
.
tail
==
this
.
tail
}
@OptIn
(
MiraiExperimentalAPI
::
class
)
override
fun
toString
():
String
{
return
tail
.
toString
()
+
left
.
toString
()
...
...
@@ -57,6 +62,12 @@ internal constructor(
override
fun
contentToString
():
String
{
return
left
.
contentToString
()
+
tail
.
contentToString
()
}
override
fun
hashCode
():
Int
{
var
result
=
left
.
hashCode
()
result
=
31
*
result
+
tail
.
hashCode
()
return
result
}
}
@JvmSynthetic
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Face.kt
View file @
ac6f411e
...
...
@@ -18,15 +18,19 @@ import kotlin.jvm.JvmName
/**
* QQ 自带表情
*/
class
Face
private
constructor
(
val
id
:
Int
,
private
val
stringValue
:
String
)
:
data class
Face
@Suppress
(
"DataClassPrivateConstructor"
)
private
constructor
(
val
id
:
Int
,
private
val
stringValue
:
String
)
:
// used in delegation
MessageContent
,
CharSequence
by
stringValue
,
Comparable
<
String
>
by
stringValue
{
constructor
(
id
:
Int
)
:
this
(
id
,
"[mirai:face:$id]"
)
override
fun
toString
():
String
=
stringValue
override
fun
contentToString
():
String
=
"[表情]"
override
fun
equals
(
other
:
Any
?):
Boolean
=
other
is
Face
&&
other
.
id
==
this
.
id
override
fun
hashCode
():
Int
=
id
/**
* @author LamGC
*/
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/HummerMessage.kt
View file @
ac6f411e
...
...
@@ -43,7 +43,7 @@ sealed class HummerMessage : MessageContent {
*/
@SinceMirai
(
"0.31.0"
)
@OptIn
(
MiraiInternalAPI
::
class
)
class
PokeMessage
@MiraiInternalAPI
(
message
=
"使用伴生对象中的常量"
)
constructor
(
data
class
PokeMessage
@MiraiInternalAPI
(
message
=
"使用伴生对象中的常量"
)
constructor
(
@MiraiExperimentalAPI
val
type
:
Int
,
@MiraiExperimentalAPI
...
...
@@ -87,12 +87,21 @@ class PokeMessage @MiraiInternalAPI(message = "使用伴生对象中的常量")
override
fun
subSequence
(
startIndex
:
Int
,
endIndex
:
Int
):
CharSequence
=
stringValue
.
subSequence
(
startIndex
,
endIndex
)
override
fun
contentToString
():
String
{
return
"[戳一戳]"
}
override
fun
contentToString
():
String
=
"[戳一戳]"
@OptIn
(
MiraiExperimentalAPI
::
class
)
override
fun
equals
(
other
:
Any
?):
Boolean
=
other
is
PokeMessage
&&
other
.
type
==
this
.
type
&&
other
.
id
==
this
.
id
override
fun
compareTo
(
other
:
String
):
Int
=
stringValue
.
compareTo
(
other
)
@OptIn
(
MiraiExperimentalAPI
::
class
)
override
fun
hashCode
():
Int
{
var
result
=
type
result
=
31
*
result
+
id
result
=
31
*
result
+
stringValue
.
hashCode
()
return
result
}
//businessType=0x00000001(1)
//pbElem=08 01 18 00 20 FF FF FF FF 0F 2A 00 32 00 38 00 50 00
//serviceType=0x00000002(2)
...
...
@@ -178,7 +187,7 @@ inline fun FriendImage.flash(): FriendFlashImage = FlashImage(this) as FriendFla
* @see FlashImage.invoke
*/
@SinceMirai
(
"0.33.0"
)
class
GroupFlashImage
(
override
val
image
:
GroupImage
)
:
FlashImage
()
{
data
class
GroupFlashImage
(
override
val
image
:
GroupImage
)
:
FlashImage
()
{
companion
object
Key
:
Message
.
Key
<
GroupFlashImage
>
{
override
val
typeName
:
String
get
()
=
"GroupFlashImage"
...
...
@@ -189,7 +198,7 @@ class GroupFlashImage(override val image: GroupImage) : FlashImage() {
* @see FlashImage.invoke
*/
@SinceMirai
(
"0.33.0"
)
class
FriendFlashImage
(
override
val
image
:
FriendImage
)
:
FlashImage
()
{
data
class
FriendFlashImage
(
override
val
image
:
FriendImage
)
:
FlashImage
()
{
companion
object
Key
:
Message
.
Key
<
FriendFlashImage
>
{
override
val
typeName
:
String
get
()
=
"FriendFlashImage"
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt
View file @
ac6f411e
...
...
@@ -212,7 +212,7 @@ data class OfflineGroupImage(
}
override
fun
equals
(
other
:
Any
?):
Boolean
{
return
other
is
OfflineGroupImage
&&
other
.
md5
.
contentEquals
(
this
.
md5
)
&&
other
.
filepath
==
this
.
filepath
return
other
is
OfflineGroupImage
&&
other
::
class
== this::class && other
.md5.content
Equals
(
this
.
md5
)
&&
other
.
filepath
==
this
.
filepath
}
}
...
...
@@ -276,8 +276,8 @@ data class OfflineFriendImage(
}
override
fun
equals
(
other
:
Any
?):
Boolean
{
return
other
is
OfflineFriendImage
&&
other
.
md5
.
contentEquals
(
this
.
md5
)
&&
other
.
resourceId
==
this
.
resourceId
return
other
is
OfflineFriendImage
&&
other
::
class
== this::class &&
other.md5
.content
Equals
(
this
.
md5
)
&&
other
.
resourceId
==
this
.
resourceId
}
}
...
...
@@ -290,7 +290,10 @@ abstract class OnlineFriendImage : FriendImage(), OnlineImage
// endregion
//////////////////////
// region internal
//////////////////////
private
val
EMPTY_BYTE_ARRAY
=
ByteArray
(
0
)
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt
View file @
ac6f411e
...
...
@@ -100,8 +100,6 @@ interface Message {
* ```
*/
@SinceMirai
(
"0.34.0"
)
@Suppress
(
"DEPRECATION_ERROR"
)
@OptIn
(
MiraiInternalAPI
::
class
)
@JvmSynthetic
// in java they should use `plus` instead
fun
followedBy
(
tail
:
Message
):
MessageChain
=
followedByImpl
(
tail
)
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt
View file @
ac6f411e
...
...
@@ -373,6 +373,7 @@ object EmptyMessageChain : MessageChain, Iterator<SingleMessage> {
override
val
size
:
Int
get
()
=
0
override
fun
toString
():
String
=
""
override
fun
contentToString
():
String
=
""
override
fun
equals
(
other
:
Any
?):
Boolean
=
other
===
this
override
fun
iterator
():
Iterator
<
SingleMessage
>
=
this
override
fun
hasNext
():
Boolean
=
false
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/PlainText.kt
View file @
ac6f411e
...
...
@@ -22,7 +22,7 @@ import kotlin.jvm.JvmSynthetic
*
* 一般不需要主动构造 [PlainText], [Message] 可直接与 [String] 相加. Java 用户请使用 [MessageChain.plus]
*/
class
PlainText
(
val
stringValue
:
String
)
:
data
class
PlainText
(
val
stringValue
:
String
)
:
MessageContent
,
Comparable
<
String
>
by
stringValue
,
CharSequence
by
stringValue
{
...
...
@@ -33,14 +33,6 @@ class PlainText(val stringValue: String) :
override
fun
toString
():
String
=
stringValue
override
fun
contentToString
():
String
=
stringValue
override
fun
equals
(
other
:
Any
?):
Boolean
{
return
other
is
PlainText
&&
other
.
stringValue
==
this
.
stringValue
}
override
fun
hashCode
():
Int
{
return
stringValue
.
hashCode
()
}
companion
object
Key
:
Message
.
Key
<
PlainText
>
{
override
val
typeName
:
String
get
()
=
"PlainText"
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt
View file @
ac6f411e
...
...
@@ -46,6 +46,8 @@ class QuoteReply(val source: MessageSource) : Message, MessageMetadata, Constrai
override
fun
toString
():
String
=
"[mirai:quote:${source.id}]"
override
fun
contentToString
():
String
=
""
override
fun
equals
(
other
:
Any
?):
Boolean
=
other
is
QuoteReply
&&
other
.
source
==
this
.
source
override
fun
hashCode
():
Int
=
source
.
hashCode
()
}
@
get
:
JvmSynthetic
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/RichMessage.kt
View file @
ac6f411e
...
...
@@ -33,6 +33,7 @@ interface RichMessage : MessageContent {
override
fun
contentToString
():
String
=
this
.
content
@MiraiExperimentalAPI
@SinceMirai
(
"0.30.0"
)
companion
object
Templates
:
Message
.
Key
<
RichMessage
>
{
...
...
@@ -77,7 +78,7 @@ interface RichMessage : MessageContent {
* @param content 一般是 json
*/
@SinceMirai
(
"0.27.0"
)
class
LightApp
constructor
(
override
val
content
:
String
)
:
RichMessage
{
data class
LightApp
(
override
val
content
:
String
)
:
RichMessage
{
companion
object
Key
:
Message
.
Key
<
LightApp
>
{
override
val
typeName
:
String
get
()
=
"LightApp"
}
...
...
@@ -97,6 +98,19 @@ open class ServiceMessage(@MiraiExperimentalAPI val serviceId: Int, final overri
}
final
override
fun
toString
():
String
=
"[mirai:service:$serviceId,$content]"
final
override
fun
equals
(
other
:
Any
?):
Boolean
{
if
(
other
==
null
)
return
false
if
(
other
::
class
!= this::class) return false
other as
ServiceMessage
return
other
.
serviceId
==
this
.
serviceId
&&
other
.
content
==
this
.
content
}
final
override
fun
hashCode
():
Int
{
var
result
=
serviceId
result
=
31
*
result
+
content
.
hashCode
()
return
result
}
}
...
...
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