Commit 7a217f6f authored by Him188's avatar Him188

Add `MessageChain.messageUid`, `MessageChain.sequenceId`

parent 32dc95a6
......@@ -48,7 +48,7 @@ interface Contact : CoroutineScope {
val id: Long
/**
* 向这个对象发送消息. 发送成功后 [message] 中会添加 [MessageSource], 此后可以 [引用回复][MessageReceipt.quote](仅群聊)或 [撤回][MessageReceipt.recall] 这条消息.
* 向这个对象发送消息.
*
* @see FriendMessageSendEvent 发送好友信息事件, cancellable
* @see GroupMessageSendEvent 发送群消息事件. cancellable
......
......@@ -209,7 +209,7 @@ fun <M : Message> MessageChain.firstOrNull(key: Message.Key<M>): M? = when (key)
* @throws [NoSuchElementException] 如果找不到该类型的实例
*/
@Suppress("UNCHECKED_CAST")
fun <M : Message> MessageChain.first(key: Message.Key<M>): M = firstOrNull(key) ?: error("unknown key: $key")
fun <M : Message> MessageChain.first(key: Message.Key<M>): M = firstOrNull(key) ?: throw NoSuchElementException("no such element: $key")
/**
* 获取第一个 [M] 类型的 [Message] 实例
......
......@@ -62,4 +62,14 @@ interface MessageSource : Message {
* 固定返回空字符串 ("")
*/
override fun toString(): String
}
\ No newline at end of file
}
/**
* 消息唯一标识符. 实际上是个随机数, 但服务器确实是用它当做 uid
*/
val MessageChain.messageUid get() = this[MessageSource].messageUid
/**
* 消息序列号, 可能来自服务器也可以发送时赋值, 不唯一.
*/
val MessageChain.sequenceId get() = this[MessageSource].sequenceId
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment